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

Commit 43e2ca5d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "AOSP/DeskClock - Updated to sdkVersion 29. + Fixed all the comments...

Merge "AOSP/DeskClock - Updated to sdkVersion 29. + Fixed all the comments from jplemieux@ in CL: https://android-review.googlesource.com/c/platform/packages/apps/DeskClock/+/1161143 + Incorporated changes from Luca Stefani (https://android-review.googlesource.com/c/platform/packages/apps/DeskClock/+/1162919)"
parents 75477d54 6b38605e
Loading
Loading
Loading
Loading
+152 −64
Original line number Diff line number Diff line
@@ -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;
@@ -46,6 +47,35 @@ 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 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.
     */
@@ -86,11 +116,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)
@@ -126,6 +158,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);
@@ -135,10 +174,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)
@@ -167,6 +209,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);
@@ -232,6 +281,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_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);
@@ -243,7 +299,7 @@ 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_NOTIFICATION_CHANNEL_ID)
                    .setShowWhen(false)
                    .setContentIntent(firstUpcoming.contentIntent)
                    .setColor(ContextCompat.getColor(context, R.color.default_background))
@@ -266,6 +322,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_NOTIFICATION_CHANNEL_ID,
                    context.getString(R.string.default_label),
                    NotificationManagerCompat.IMPORTANCE_DEFAULT);
            nm.createNotificationChannel(channel);
        }

        final Notification firstMissed = getFirstActiveNotification(context, MISSED_GROUP_KEY,
                canceledNotificationId, postedNotification);
@@ -277,7 +340,14 @@ final class AlarmNotifications {
        Notification summary = getActiveGroupSummaryNotification(context, MISSED_GROUP_KEY);
        if (summary == null
                || !Objects.equals(summary.contentIntent, firstMissed.contentIntent)) {
            summary = new NotificationCompat.Builder(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);
            }
            summary = new NotificationCompat.Builder(context, ALARM_NOTIFICATION_CHANNEL_ID)
                    .setShowWhen(false)
                    .setContentIntent(firstMissed.contentIntent)
                    .setColor(ContextCompat.getColor(context, R.color.default_background))
@@ -297,7 +367,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,
@@ -330,6 +401,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);
@@ -341,7 +419,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 :
@@ -375,6 +454,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);
@@ -384,9 +470,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)
+5 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -232,6 +235,7 @@ final class StopwatchModel {
        // Otherwise build and post a notification reflecting the latest stopwatch state.
        final Notification notification =
                mNotificationBuilder.build(mContext, mNotificationModel, stopwatch);
        mNotificationBuilder.buildChannel(mContext, mNotificationManager);
        mNotificationManager.notify(mNotificationModel.getStopwatchNotificationId(), notification);
    }

+28 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.deskclock.data;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -27,6 +28,7 @@ import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationCompat.Action;
import androidx.core.app.NotificationCompat.Builder;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import android.widget.RemoteViews;

@@ -46,6 +48,21 @@ import static android.view.View.VISIBLE;
 */
class StopwatchNotificationBuilder {

    /**
     * Notification channel containing all stopwatch notifications.
     */
    private static final String STOPWATCH_NOTIFICATION_CHANNEL_ID = "StopwatchNotification";

    public void buildChannel(Context context, NotificationManagerCompat notificationManager) {
        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);
            notificationManager.createNotificationChannel(channel);
        }
    }

    public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) {
        @StringRes final int eventLabel = R.string.label_notification;

@@ -127,7 +144,8 @@ class StopwatchNotificationBuilder {
            content.setViewVisibility(R.id.state, VISIBLE);
        }

        final Builder notification = new NotificationCompat.Builder(context)
        final Builder notification = new NotificationCompat.Builder(
                context, STOPWATCH_NOTIFICATION_CHANNEL_ID)
                        .setLocalOnly(true)
                        .setOngoing(running)
                        .setCustomContentView(content)
+2 −1
Original line number Diff line number Diff line
@@ -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;
@@ -752,8 +753,8 @@ final class TimerModel {
        final Notification notification =
                mNotificationBuilder.build(mContext, mNotificationModel, unexpired);
        final int notificationId = mNotificationModel.getUnexpiredTimerNotificationId();
        mNotificationBuilder.buildChannel(mContext, mNotificationManager);
        mNotificationManager.notify(notificationId, notification);

    }

    /**
+58 −38
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.deskclock.data;
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -27,6 +28,7 @@ import android.os.Build;
import android.os.SystemClock;
import androidx.annotation.DrawableRes;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import android.text.TextUtils;
import android.widget.RemoteViews;
@@ -51,9 +53,24 @@ import static android.text.format.DateUtils.SECOND_IN_MILLIS;
 */
class TimerNotificationBuilder {

    /**
     * Notification channel containing all TimerModel notifications.
     */
    private static final String TIMER_MODEL_NOTIFICATION_CHANNEL_ID = "TimerModelNotification";

    private static final int REQUEST_CODE_UPCOMING = 0;
    private static final int REQUEST_CODE_MISSING = 1;

    public void buildChannel(Context context, NotificationManagerCompat notificationManager) {
        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);
            notificationManager.createNotificationChannel(channel);
        }
    }

    public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
        final Timer timer = unexpired.get(0);
        final int count = unexpired.size();
@@ -148,7 +165,8 @@ class TimerNotificationBuilder {
                PendingIntent.getService(context, REQUEST_CODE_UPCOMING, showApp,
                        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

        final Builder notification = new NotificationCompat.Builder(context)
        final Builder notification = new NotificationCompat.Builder(
                context, TIMER_MODEL_NOTIFICATION_CHANNEL_ID)
                        .setOngoing(true)
                        .setLocalOnly(true)
                        .setShowWhen(false)
@@ -261,7 +279,8 @@ class TimerNotificationBuilder {
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
        final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen);

        final Builder notification = new NotificationCompat.Builder(context)
        final Builder notification = new NotificationCompat.Builder(
                context, TIMER_MODEL_NOTIFICATION_CHANNEL_ID)
                        .setOngoing(true)
                        .setLocalOnly(true)
                        .setShowWhen(false)
@@ -344,7 +363,8 @@ class TimerNotificationBuilder {
                PendingIntent.getService(context, REQUEST_CODE_MISSING, showApp,
                        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

        final Builder notification = new NotificationCompat.Builder(context)
        final Builder notification = new NotificationCompat.Builder(
                context, TIMER_MODEL_NOTIFICATION_CHANNEL_ID)
                        .setLocalOnly(true)
                        .setShowWhen(false)
                        .setAutoCancel(false)