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

Commit b551eb6a authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Polite notifications

 Add polite notifications implementation to NotificationAttentionHelper:
  - 2 cooldown strategies: to be reduced to a single strategy after dogfood.

Test: atest BuzzBeepBlinkTest
Test: atest NotificationAttentionHelperTest

Bug: 270456865
Change-Id: I185a0a4b13d6602061c664d1babe6beff7630cd1
parent f178449b
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -272,6 +272,10 @@ public final class NotificationChannel implements Parcelable {
    private boolean mDemoted = false;
    private boolean mImportantConvo = false;
    private long mDeletedTime = DEFAULT_DELETION_TIME_MS;
    /** Do not (de)serialize this value: it only affects logic in system_server and that logic
     * is reset on each boot {@link NotificationAttentionHelper#buzzBeepBlinkLocked}.
     */
    private long mLastNotificationUpdateTimeMs = 0;

    /**
     * Creates a notification channel.
@@ -931,6 +935,23 @@ public final class NotificationChannel implements Parcelable {
        return (mUserLockedFields & USER_LOCKED_SOUND) != 0;
    }

    /**
     * Returns the time of the notification post or last update for this channel.
     * @return time of post / last update
     * @hide
     */
    public long getLastNotificationUpdateTimeMs() {
        return mLastNotificationUpdateTimeMs;
    }

    /**
     * Sets the time of the notification post or last update for this channel.
     * @hide
     */
    public void setLastNotificationUpdateTimeMs(long updateTimeMs) {
        mLastNotificationUpdateTimeMs = updateTimeMs;
    }

    /**
     * @hide
     */
@@ -1408,7 +1429,8 @@ public final class NotificationChannel implements Parcelable {
                + ", mParent=" + mParentId
                + ", mConversationId=" + mConversationId
                + ", mDemoted=" + mDemoted
                + ", mImportantConvo=" + mImportantConvo;
                + ", mImportantConvo=" + mImportantConvo
                + ", mLastNotificationUpdateTimeMs=" + mLastNotificationUpdateTimeMs;
    }

    /** @hide */
+31 −0
Original line number Diff line number Diff line
@@ -5353,6 +5353,37 @@ public final class Settings {
        /** {@hide} */
        public static final Uri NOTIFICATION_SOUND_CACHE_URI = getUriFor(NOTIFICATION_SOUND_CACHE);
        /**
         * When enabled, notifications attention effects: sound, vibration, flashing
         * will have a cooldown timer.
         *
         * The value 1 - enable, 0 - disable
         * @hide
         */
        public static final String NOTIFICATION_COOLDOWN_ENABLED =
            "notification_cooldown_enabled";
        /**
         * When enabled, notification cooldown will apply to all notifications.
         * Otherwise cooldown will only apply to conversations.
         *
         * The value 1 - enable, 0 - disable
         * Only valid if {@code NOTIFICATION_COOLDOWN_ENABLED} is enabled.
         * @hide
         */
        public static final String NOTIFICATION_COOLDOWN_ALL =
            "notification_cooldown_all";
        /**
         * When enabled, notification attention effects will be restricted to vibration only
         * as long as the screen is unlocked.
         *
         * The value 1 - enable, 0 - disable
         * @hide
         */
        public static final String NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED =
            "notification_cooldown_vibrate_unlocked";
        /**
         * Persistent store for the system-wide default alarm alert.
         *
+3 −0
Original line number Diff line number Diff line
@@ -103,5 +103,8 @@ public class SystemSettings {
        Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
        Settings.System.PEAK_REFRESH_RATE,
        Settings.System.MIN_REFRESH_RATE,
        Settings.System.NOTIFICATION_COOLDOWN_ENABLED,
        Settings.System.NOTIFICATION_COOLDOWN_ALL,
        Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED,
    };
}
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.hardware.display.ColorDisplayManager;
import android.os.BatteryManager;
import android.provider.Settings.Global;
import android.provider.Settings.System;
import android.util.ArrayMap;

@@ -239,5 +240,8 @@ public class SystemSettingsValidators {
        VALIDATORS.put(System.SCREEN_FLASH_NOTIFICATION_COLOR, ANY_INTEGER_VALIDATOR);
        VALIDATORS.put(System.PEAK_REFRESH_RATE, NON_NEGATIVE_FLOAT_VALIDATOR);
        VALIDATORS.put(System.MIN_REFRESH_RATE, NON_NEGATIVE_FLOAT_VALIDATOR);
        VALIDATORS.put(System.NOTIFICATION_COOLDOWN_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.NOTIFICATION_COOLDOWN_ALL, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, BOOLEAN_VALIDATOR);
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -90,8 +90,14 @@ message MetricsEvent {
    // Make sound through the speaker.
    ALERT_BEEP = 2;

    // Flash a notificaiton light.
    // Flash a notification light.
    ALERT_BLINK = 4;

    // Alert was attenuated by polite notif. feature.
    ALERT_POLITE = 8;

    // Alert was muted by polite notif. feature.
    ALERT_MUTED = 16;
  }

  // Reasons that a notification might be dismissed.
Loading