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

Commit 008911c3 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Change how ranking time is calculated

The calculation about 'did the dev supply a "when" value is many years
out of date, and we shouldn't ignore all updates in the name of
stability - updates that a user would consider something new (e.g. sound
or new text) should have a chance to be ranked higher. This shares the
same logic as the notification counts we show in settings

Test: atest FrameworksUiServicesTests
Bug: 326016985

Change-Id: Ib79c1aa903442eaf02ba459d4c399b289d32f91b
parent 40c66cff
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.app.admin.DevicePolicyResources.UNDEFINED;
import static android.graphics.drawable.Icon.TYPE_URI;
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;
import static android.app.Flags.evenlyDividedCallStyleActionLayout;
import static android.app.Flags.updateRankingTime;
import static java.util.Objects.requireNonNull;
@@ -339,8 +340,9 @@ public class Notification implements Parcelable
    /**
     * The creation time of the notification
     * @hide
     */
    private long creationTime;
    public long creationTime;
    /**
     * The resource id of a drawable to use as the icon in the status bar.
@@ -2578,7 +2580,11 @@ public class Notification implements Parcelable
    public Notification()
    {
        this.when = System.currentTimeMillis();
        if (updateRankingTime()) {
            creationTime = when;
        } else {
            this.creationTime = System.currentTimeMillis();
        }
        this.priority = PRIORITY_DEFAULT;
    }
@@ -2589,6 +2595,9 @@ public class Notification implements Parcelable
    public Notification(Context context, int icon, CharSequence tickerText, long when,
            CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
    {
        if (updateRankingTime()) {
            creationTime = when;
        }
        new Builder(context)
                .setWhen(when)
                .setSmallIcon(icon)
@@ -2618,8 +2627,12 @@ public class Notification implements Parcelable
        this.icon = icon;
        this.tickerText = tickerText;
        this.when = when;
        if (updateRankingTime()) {
            creationTime = when;
        } else {
            this.creationTime = System.currentTimeMillis();
        }
    }
    /**
     * Unflatten the notification from a parcel.
@@ -6843,7 +6856,9 @@ public class Notification implements Parcelable
                }
            }
            if (!updateRankingTime()) {
                mN.creationTime = System.currentTimeMillis();
            }
            // lazy stuff from mContext; see comment in Builder(Context, Notification)
            Notification.addFieldsFromContext(mContext, mN);
+10 −0
Original line number Diff line number Diff line
@@ -67,3 +67,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "update_ranking_time"
  namespace: "systemui"
  description: "Updates notification sorting criteria to highlight new content while maintaining stability"
  bug: "326016985"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.notification;

import static android.app.Flags.updateRankingTime;
import static android.app.Notification.FLAG_INSISTENT;
import static android.app.Notification.FLAG_ONLY_ALERT_ONCE;
import static android.app.NotificationManager.IMPORTANCE_MIN;
@@ -496,6 +497,11 @@ public final class NotificationAttentionHelper {
                    Slog.v(TAG, "INTERRUPTIVENESS: "
                            + record.getKey() + " is interruptive: alerted");
                }
                if (updateRankingTime()) {
                    if (buzz || beep) {
                        record.resetRankingTime();
                    }
                }
            }
        }
        final int buzzBeepBlinkLoggingCode =
+6 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ import static android.service.notification.NotificationListenerService.TRIM_LIGH
import static android.view.contentprotection.flags.Flags.rapidClearNotificationsByListenerAppOpEnabled;
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
import static android.app.Flags.updateRankingTime;
import static com.android.internal.util.FrameworkStatsLog.DND_MODE_RULE;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES;
@@ -8489,6 +8490,11 @@ public class NotificationManagerService extends SystemService {
                        r.isUpdate = true;
                        final boolean isInterruptive = isVisuallyInterruptive(old, r);
                        r.setTextChanged(isInterruptive);
                        if (updateRankingTime()) {
                            if (isInterruptive) {
                                r.resetRankingTime();
                            }
                        }
                    }
                    mNotificationsByKey.put(n.getKey(), r);
+15 −4
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.server.notification;

import static android.app.Flags.updateRankingTime;
import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
@@ -65,14 +66,12 @@ import android.util.Log;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;
import android.widget.RemoteViews;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.server.EventLogTags;
import com.android.server.LocalServices;
import com.android.server.uri.UriGrantsManagerInternal;

import dalvik.annotation.optimization.NeverCompile;

import java.io.PrintWriter;
@@ -1090,9 +1089,15 @@ public final class NotificationRecord {
    private long calculateRankingTimeMs(long previousRankingTimeMs) {
        Notification n = getNotification();
        // Take developer provided 'when', unless it's in the future.
        if (updateRankingTime()) {
            if (n.when != n.creationTime && n.when <= getSbn().getPostTime()){
                return n.when;
            }
        } else {
            if (n.when != 0 && n.when <= getSbn().getPostTime()) {
                return n.when;
            }
        }
        // If we've ranked a previous instance with a timestamp, inherit it. This case is
        // important in order to have ranking stability for updating notifications.
        if (previousRankingTimeMs > 0) {
@@ -1193,6 +1198,12 @@ public final class NotificationRecord {
        return mPeopleOverride;
    }

    public void resetRankingTime() {
        if (updateRankingTime()) {
            mRankingTimeMs = calculateRankingTimeMs(getSbn().getPostTime());
        }
    }

    public void setInterruptive(boolean interruptive) {
        mIsInterruptive = interruptive;
        final long now = System.currentTimeMillis();
Loading