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

Commit 2042e4ea authored by Raman Tenneti's avatar Raman Tenneti
Browse files

AOSP/DeskClock - Updated to sdkVersion 29.

BUG: 133177396
BUG: 143990962

Test: manual - Tested the DeskClock UI manually and tested the alarm, stopwatch and timer.

$ make -j 40

$ ls -l out/target/product/generic/system/product/app/DeskClock/DeskClock.apk
-rw-r--r-- 1 rtenneti primarygroup 6432279 Nov  6 19:07 out/target/product/generic/system/product/app/DeskClock/DeskClock.apk

$ adb install -r out/target/product/generic/system/product/app/DeskClock/DeskClock.apk

+ Verified by setting up the alaram and waiting for the alarm to go off. "Clock has stopped" wasn't displayed. Noted there were no exceptions in the logs. (b/135587258)

Change-Id: Ic946cb58ddc8430c034b73854080c586a1939d4a
parent 8d674ee7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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" />
+180 −86
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,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.
     */
@@ -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)
@@ -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);
@@ -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)
@@ -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);
@@ -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);
@@ -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))
@@ -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);
@@ -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))
@@ -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,
@@ -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);
@@ -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 :
@@ -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);
@@ -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)
+16 −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;
@@ -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;
@@ -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);
+11 −10
Original line number Diff line number Diff line
@@ -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)
+13 −0
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;
@@ -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.
@@ -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