Loading AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ <original-package android:name="com.android.alarmclock" /> <original-package android:name="com.android.deskclock" /> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="25" /> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="29" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> Loading src/com/android/deskclock/alarms/AlarmNotifications.java +180 −86 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.deskclock.alarms; import android.annotation.TargetApi; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; Loading Loading @@ -46,6 +47,47 @@ import java.util.Objects; final class AlarmNotifications { static final String EXTRA_NOTIFICATION_ID = "extra_notification_id"; /** * Notification channel containing all low priority notifications. */ private static final String ALARM_LOW_PRIORITY_NOTIFICATION_CHANNEL_ID = "alarmLowPriorityNotification"; /** * Notification channel containing all high priority notifications. */ private static final String ALARM_HIGH_PRIORITY_NOTIFICATION_CHANNEL_ID = "alarmHighPriorityNotification"; /** * Notification channel containing all upcoming update notifications. */ private static final String ALARM_UPDATE_UPCOMING_NOTIFICATION_CHANNEL_ID = "alarmUpdateUpcomingNotification"; /** * Notification channel containing all missed update notifications. */ private static final String ALARM_UPDATE_MISSED_NOTIFICATION_CHANNEL_ID = "alarmUpdateMissedNotification"; /** * Notification channel containing all snooze notifications. */ private static final String ALARM_SNOOZE_NOTIFICATION_CHANNEL_ID = "alarmSnoozeNotification"; /** * Notification channel containing all missed notifications. */ private static final String ALARM_MISSED_NOTIFICATION_CHANNEL_ID = "alarmMissedNotification"; /** * Notification channel containing all alarm notifications. */ private static final String ALARM_NOTIFICATION_CHANNEL_ID = "alarmNotification"; /** * Formats times such that chronological order and lexicographical order agree. */ Loading Loading @@ -86,11 +128,13 @@ final class AlarmNotifications { AlarmInstance instance) { LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_LOW_PRIORITY_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(context.getString( R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setContentText(AlarmUtils.getAlarmText( context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm) .setAutoCancel(false) Loading Loading @@ -126,6 +170,13 @@ final class AlarmNotifications { viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_LOW_PRIORITY_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); Loading @@ -135,10 +186,13 @@ final class AlarmNotifications { AlarmInstance instance) { LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_HIGH_PRIORITY_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setContentTitle(context.getString( R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText( context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm) .setAutoCancel(false) Loading Loading @@ -167,6 +221,13 @@ final class AlarmNotifications { viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_HIGH_PRIORITY_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); Loading Loading @@ -232,6 +293,13 @@ final class AlarmNotifications { } final NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_UPDATE_UPCOMING_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification firstUpcoming = getFirstActiveNotification(context, UPCOMING_GROUP_KEY, canceledNotificationId, postedNotification); Loading @@ -243,7 +311,8 @@ final class AlarmNotifications { Notification summary = getActiveGroupSummaryNotification(context, UPCOMING_GROUP_KEY); if (summary == null || !Objects.equals(summary.contentIntent, firstUpcoming.contentIntent)) { summary = new NotificationCompat.Builder(context) summary = new NotificationCompat.Builder( context, ALARM_UPDATE_UPCOMING_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentIntent(firstUpcoming.contentIntent) .setColor(ContextCompat.getColor(context, R.color.default_background)) Loading @@ -266,6 +335,12 @@ final class AlarmNotifications { } final NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_UPDATE_MISSED_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); } final Notification firstMissed = getFirstActiveNotification(context, MISSED_GROUP_KEY, canceledNotificationId, postedNotification); Loading @@ -277,7 +352,8 @@ final class AlarmNotifications { Notification summary = getActiveGroupSummaryNotification(context, MISSED_GROUP_KEY); if (summary == null || !Objects.equals(summary.contentIntent, firstMissed.contentIntent)) { summary = new NotificationCompat.Builder(context) summary = new NotificationCompat.Builder( context, ALARM_UPDATE_MISSED_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentIntent(firstMissed.contentIntent) .setColor(ContextCompat.getColor(context, R.color.default_background)) Loading @@ -297,7 +373,8 @@ final class AlarmNotifications { AlarmInstance instance) { LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_SNOOZE_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(context.getString(R.string.alarm_alert_snooze_until, Loading Loading @@ -330,6 +407,13 @@ final class AlarmNotifications { viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_SNOOZE_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); Loading @@ -341,7 +425,8 @@ final class AlarmNotifications { String label = instance.mLabel; String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime()); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_MISSED_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(context.getString(R.string.alarm_missed_title)) .setContentText(instance.mLabel.isEmpty() ? alarmTime : Loading Loading @@ -375,6 +460,13 @@ final class AlarmNotifications { showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_MISSED_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateMissedAlarmGroupNotification(context, -1, notification); Loading @@ -384,9 +476,11 @@ final class AlarmNotifications { LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId); Resources resources = service.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(service) NotificationCompat.Builder notification = new NotificationCompat.Builder( service, ALARM_NOTIFICATION_CHANNEL_ID) .setContentTitle(instance.getLabelOrDefault(service)) .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime())) .setContentText(AlarmUtils.getFormattedTime( service, instance.getAlarmTime())) .setColor(ContextCompat.getColor(service, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm) .setOngoing(true) Loading src/com/android/deskclock/data/StopwatchModel.java +16 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.deskclock.data; import android.app.Notification; import android.app.NotificationChannel; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading @@ -25,6 +26,8 @@ import android.content.SharedPreferences; import androidx.annotation.VisibleForTesting; import androidx.core.app.NotificationManagerCompat; import com.android.deskclock.R; import java.util.ArrayList; import java.util.Collections; import java.util.List; Loading @@ -34,6 +37,11 @@ import java.util.List; */ final class StopwatchModel { /** * Notification channel containing all stopwatch notifications. */ static final String STOPWATCH_NOTIFICATION_CHANNEL_ID = "StopwatchNotification"; private final Context mContext; private final SharedPreferences mPrefs; Loading Loading @@ -66,6 +74,13 @@ final class StopwatchModel { mPrefs = prefs; mNotificationModel = notificationModel; mNotificationManager = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( STOPWATCH_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(channel); } // Update stopwatch notification when locale changes. final IntentFilter localeBroadcastFilter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); Loading src/com/android/deskclock/data/StopwatchNotificationBuilder.java +11 −10 Original line number Diff line number Diff line Loading @@ -127,7 +127,8 @@ class StopwatchNotificationBuilder { content.setViewVisibility(R.id.state, VISIBLE); } final Builder notification = new NotificationCompat.Builder(context) final Builder notification = new NotificationCompat.Builder( context, StopwatchModel.STOPWATCH_NOTIFICATION_CHANNEL_ID) .setLocalOnly(true) .setOngoing(running) .setCustomContentView(content) Loading src/com/android/deskclock/data/TimerModel.java +13 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.deskclock.data; import android.annotation.SuppressLint; import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.PendingIntent; import android.app.Service; import android.content.BroadcastReceiver; Loading Loading @@ -56,6 +57,11 @@ import static com.android.deskclock.data.Timer.State.RESET; */ final class TimerModel { /** * Notification channel containing all TimerModel notifications. */ static final String TIMER_MODEL_NOTIFICATION_CHANNEL_ID = "TimerModelNotification"; /** * Running timers less than this threshold are left running/expired; greater than this * threshold are considered missed. Loading Loading @@ -136,6 +142,13 @@ final class TimerModel { mRingtoneModel = ringtoneModel; mNotificationModel = notificationModel; mNotificationManager = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( TIMER_MODEL_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(channel); } mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); Loading Loading
AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ <original-package android:name="com.android.alarmclock" /> <original-package android:name="com.android.deskclock" /> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="25" /> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="29" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> Loading
src/com/android/deskclock/alarms/AlarmNotifications.java +180 −86 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.deskclock.alarms; import android.annotation.TargetApi; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; Loading Loading @@ -46,6 +47,47 @@ import java.util.Objects; final class AlarmNotifications { static final String EXTRA_NOTIFICATION_ID = "extra_notification_id"; /** * Notification channel containing all low priority notifications. */ private static final String ALARM_LOW_PRIORITY_NOTIFICATION_CHANNEL_ID = "alarmLowPriorityNotification"; /** * Notification channel containing all high priority notifications. */ private static final String ALARM_HIGH_PRIORITY_NOTIFICATION_CHANNEL_ID = "alarmHighPriorityNotification"; /** * Notification channel containing all upcoming update notifications. */ private static final String ALARM_UPDATE_UPCOMING_NOTIFICATION_CHANNEL_ID = "alarmUpdateUpcomingNotification"; /** * Notification channel containing all missed update notifications. */ private static final String ALARM_UPDATE_MISSED_NOTIFICATION_CHANNEL_ID = "alarmUpdateMissedNotification"; /** * Notification channel containing all snooze notifications. */ private static final String ALARM_SNOOZE_NOTIFICATION_CHANNEL_ID = "alarmSnoozeNotification"; /** * Notification channel containing all missed notifications. */ private static final String ALARM_MISSED_NOTIFICATION_CHANNEL_ID = "alarmMissedNotification"; /** * Notification channel containing all alarm notifications. */ private static final String ALARM_NOTIFICATION_CHANNEL_ID = "alarmNotification"; /** * Formats times such that chronological order and lexicographical order agree. */ Loading Loading @@ -86,11 +128,13 @@ final class AlarmNotifications { AlarmInstance instance) { LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_LOW_PRIORITY_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(context.getString( R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setContentText(AlarmUtils.getAlarmText( context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm) .setAutoCancel(false) Loading Loading @@ -126,6 +170,13 @@ final class AlarmNotifications { viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_LOW_PRIORITY_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); Loading @@ -135,10 +186,13 @@ final class AlarmNotifications { AlarmInstance instance) { LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_HIGH_PRIORITY_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setContentTitle(context.getString( R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText( context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm) .setAutoCancel(false) Loading Loading @@ -167,6 +221,13 @@ final class AlarmNotifications { viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_HIGH_PRIORITY_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); Loading Loading @@ -232,6 +293,13 @@ final class AlarmNotifications { } final NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_UPDATE_UPCOMING_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification firstUpcoming = getFirstActiveNotification(context, UPCOMING_GROUP_KEY, canceledNotificationId, postedNotification); Loading @@ -243,7 +311,8 @@ final class AlarmNotifications { Notification summary = getActiveGroupSummaryNotification(context, UPCOMING_GROUP_KEY); if (summary == null || !Objects.equals(summary.contentIntent, firstUpcoming.contentIntent)) { summary = new NotificationCompat.Builder(context) summary = new NotificationCompat.Builder( context, ALARM_UPDATE_UPCOMING_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentIntent(firstUpcoming.contentIntent) .setColor(ContextCompat.getColor(context, R.color.default_background)) Loading @@ -266,6 +335,12 @@ final class AlarmNotifications { } final NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_UPDATE_MISSED_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); } final Notification firstMissed = getFirstActiveNotification(context, MISSED_GROUP_KEY, canceledNotificationId, postedNotification); Loading @@ -277,7 +352,8 @@ final class AlarmNotifications { Notification summary = getActiveGroupSummaryNotification(context, MISSED_GROUP_KEY); if (summary == null || !Objects.equals(summary.contentIntent, firstMissed.contentIntent)) { summary = new NotificationCompat.Builder(context) summary = new NotificationCompat.Builder( context, ALARM_UPDATE_MISSED_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentIntent(firstMissed.contentIntent) .setColor(ContextCompat.getColor(context, R.color.default_background)) Loading @@ -297,7 +373,8 @@ final class AlarmNotifications { AlarmInstance instance) { LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_SNOOZE_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(context.getString(R.string.alarm_alert_snooze_until, Loading Loading @@ -330,6 +407,13 @@ final class AlarmNotifications { viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_SNOOZE_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); Loading @@ -341,7 +425,8 @@ final class AlarmNotifications { String label = instance.mLabel; String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime()); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) NotificationCompat.Builder builder = new NotificationCompat.Builder( context, ALARM_MISSED_NOTIFICATION_CHANNEL_ID) .setShowWhen(false) .setContentTitle(context.getString(R.string.alarm_missed_title)) .setContentText(instance.mLabel.isEmpty() ? alarmTime : Loading Loading @@ -375,6 +460,13 @@ final class AlarmNotifications { showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( ALARM_MISSED_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); nm.createNotificationChannel(channel); } final Notification notification = builder.build(); nm.notify(id, notification); updateMissedAlarmGroupNotification(context, -1, notification); Loading @@ -384,9 +476,11 @@ final class AlarmNotifications { LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId); Resources resources = service.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(service) NotificationCompat.Builder notification = new NotificationCompat.Builder( service, ALARM_NOTIFICATION_CHANNEL_ID) .setContentTitle(instance.getLabelOrDefault(service)) .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime())) .setContentText(AlarmUtils.getFormattedTime( service, instance.getAlarmTime())) .setColor(ContextCompat.getColor(service, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm) .setOngoing(true) Loading
src/com/android/deskclock/data/StopwatchModel.java +16 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.deskclock.data; import android.app.Notification; import android.app.NotificationChannel; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading @@ -25,6 +26,8 @@ import android.content.SharedPreferences; import androidx.annotation.VisibleForTesting; import androidx.core.app.NotificationManagerCompat; import com.android.deskclock.R; import java.util.ArrayList; import java.util.Collections; import java.util.List; Loading @@ -34,6 +37,11 @@ import java.util.List; */ final class StopwatchModel { /** * Notification channel containing all stopwatch notifications. */ static final String STOPWATCH_NOTIFICATION_CHANNEL_ID = "StopwatchNotification"; private final Context mContext; private final SharedPreferences mPrefs; Loading Loading @@ -66,6 +74,13 @@ final class StopwatchModel { mPrefs = prefs; mNotificationModel = notificationModel; mNotificationManager = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( STOPWATCH_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(channel); } // Update stopwatch notification when locale changes. final IntentFilter localeBroadcastFilter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); Loading
src/com/android/deskclock/data/StopwatchNotificationBuilder.java +11 −10 Original line number Diff line number Diff line Loading @@ -127,7 +127,8 @@ class StopwatchNotificationBuilder { content.setViewVisibility(R.id.state, VISIBLE); } final Builder notification = new NotificationCompat.Builder(context) final Builder notification = new NotificationCompat.Builder( context, StopwatchModel.STOPWATCH_NOTIFICATION_CHANNEL_ID) .setLocalOnly(true) .setOngoing(running) .setCustomContentView(content) Loading
src/com/android/deskclock/data/TimerModel.java +13 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.deskclock.data; import android.annotation.SuppressLint; import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.PendingIntent; import android.app.Service; import android.content.BroadcastReceiver; Loading Loading @@ -56,6 +57,11 @@ import static com.android.deskclock.data.Timer.State.RESET; */ final class TimerModel { /** * Notification channel containing all TimerModel notifications. */ static final String TIMER_MODEL_NOTIFICATION_CHANNEL_ID = "TimerModelNotification"; /** * Running timers less than this threshold are left running/expired; greater than this * threshold are considered missed. Loading Loading @@ -136,6 +142,13 @@ final class TimerModel { mRingtoneModel = ringtoneModel; mNotificationModel = notificationModel; mNotificationManager = NotificationManagerCompat.from(context); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( TIMER_MODEL_NOTIFICATION_CHANNEL_ID, context.getString(R.string.default_label), NotificationManagerCompat.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(channel); } mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); Loading