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

Commit ba71046c authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Default 'showWhen' to true

Although Notification was changed to default it to false in Android N,
NotificationCompat was not updated to match. This is guarded by the flag
that controls sorting changes, since showing times matters more when
thee shade is sorting by time.

setWhen is also now ignoring inputs of "0" when 'showWhen' is true, to
avoid showing timestamps that are decades old. This value is already
ignored by the sorting logic.

Test: manual
Bug: 330193582
Flag: android.app.update_ranking_time DEV
Change-Id: Ibcf9dacc618871d37ddbdd3c16d23fde12650bce
parent 63f75075
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -2583,6 +2583,7 @@ public class Notification implements Parcelable
        this.when = System.currentTimeMillis();
        if (updateRankingTime()) {
            creationTime = when;
            extras.putBoolean(EXTRA_SHOW_WHEN, true);
        } else {
            this.creationTime = System.currentTimeMillis();
        }
@@ -2598,6 +2599,7 @@ public class Notification implements Parcelable
    {
        if (updateRankingTime()) {
            creationTime = when;
            extras.putBoolean(EXTRA_SHOW_WHEN, true);
        }
        new Builder(context)
                .setWhen(when)
@@ -2630,6 +2632,7 @@ public class Notification implements Parcelable
        this.when = when;
        if (updateRankingTime()) {
            creationTime = when;
            extras.putBoolean(EXTRA_SHOW_WHEN, true);
        } else {
            this.creationTime = System.currentTimeMillis();
        }
@@ -4382,14 +4385,16 @@ public class Notification implements Parcelable
        /**
         * Add a timestamp pertaining to the notification (usually the time the event occurred).
         *
         * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this time is not
         * shown anymore by default and must be opted into by using
         * {@link android.app.Notification.Builder#setShowWhen(boolean)}
         *
         * @see Notification#when
         */
        @NonNull
        public Builder setWhen(long when) {
            if (updateRankingTime()) {
                // don't show a timestamp that's decades old
                if (mN.extras.getBoolean(EXTRA_SHOW_WHEN, true) && when == 0) {
                    return this;
                }
            }
            mN.when = when;
            return this;
        }
@@ -4397,8 +4402,6 @@ public class Notification implements Parcelable
        /**
         * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown
         * in the content view.
         * For apps targeting {@link android.os.Build.VERSION_CODES#N} and above, this defaults to
         * {@code false}. For earlier apps, the default is {@code true}.
         */
        @NonNull
        public Builder setShowWhen(boolean show) {