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

Commit 7c35ede8 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Ignore 'when's of 0" into main

parents 6ce9c634 b5072f38
Loading
Loading
Loading
Loading
+31 −9
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.app;
import static android.annotation.Dimension.DP;
import static android.app.Flags.evenlyDividedCallStyleActionLayout;
import static android.app.Flags.updateRankingTime;
import static android.app.admin.DevicePolicyResources.Drawables.Source.NOTIFICATION;
import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED;
import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON;
@@ -2600,7 +2599,7 @@ public class Notification implements Parcelable
    public Notification()
    {
        this.when = System.currentTimeMillis();
        if (updateRankingTime()) {
        if (Flags.sortSectionByTime()) {
            creationTime = when;
            extras.putBoolean(EXTRA_SHOW_WHEN, true);
        } else {
@@ -2616,7 +2615,7 @@ public class Notification implements Parcelable
    public Notification(Context context, int icon, CharSequence tickerText, long when,
            CharSequence contentTitle, CharSequence contentText, Intent contentIntent)
    {
        if (updateRankingTime()) {
        if (Flags.sortSectionByTime()) {
            creationTime = when;
            extras.putBoolean(EXTRA_SHOW_WHEN, true);
        }
@@ -2649,7 +2648,7 @@ public class Notification implements Parcelable
        this.icon = icon;
        this.tickerText = tickerText;
        this.when = when;
        if (updateRankingTime()) {
        if (Flags.sortSectionByTime()) {
            creationTime = when;
            extras.putBoolean(EXTRA_SHOW_WHEN, true);
        } else {
@@ -5985,21 +5984,22 @@ public class Notification implements Parcelable
                }
                if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) {
                    contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
                    contentView.setLong(R.id.chronometer, "setBase",
                            mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
                    contentView.setLong(R.id.chronometer, "setBase", mN.getWhen()
                            + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
                    contentView.setBoolean(R.id.chronometer, "setStarted", true);
                    boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN);
                    contentView.setChronometerCountDown(R.id.chronometer, countsDown);
                    setTextViewColorSecondary(contentView, R.id.chronometer, p);
                } else {
                    contentView.setViewVisibility(R.id.time, View.VISIBLE);
                    contentView.setLong(R.id.time, "setTime", mN.when);
                    contentView.setLong(R.id.time, "setTime", mN.getWhen());
                    setTextViewColorSecondary(contentView, R.id.time, p);
                }
            } else {
                // We still want a time to be set but gone, such that we can show and hide it
                // on demand in case it's a child notification without anything in the header
                contentView.setLong(R.id.time, "setTime", mN.when != 0 ? mN.when : mN.creationTime);
                contentView.setLong(R.id.time, "setTime", mN.getWhen() != 0 ? mN.getWhen() :
                        mN.creationTime);
                setTextViewColorSecondary(contentView, R.id.time, p);
            }
        }
@@ -7166,7 +7166,7 @@ public class Notification implements Parcelable
                }
            }
            if (!updateRankingTime()) {
            if (!Flags.sortSectionByTime()) {
                mN.creationTime = System.currentTimeMillis();
            }
@@ -7618,11 +7618,30 @@ public class Notification implements Parcelable
        return mLargeIcon != null || largeIcon != null;
    }
    /**
     * Returns #when, unless it's set to 0, which should be shown as/treated as a 'current'
     * notification. 0 is treated as a special value because it was special in an old version of
     * android, and some apps are still (incorrectly) using it.
     *
     * @hide
     */
    public long getWhen() {
        if (Flags.sortSectionByTime()) {
            if (when == 0) {
                return creationTime;
            }
        }
        return when;
    }
    /**
     * @return true if the notification will show the time; false otherwise
     * @hide
     */
    public boolean showsTime() {
        if (Flags.sortSectionByTime()) {
            return extras.getBoolean(EXTRA_SHOW_WHEN);
        }
        return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN);
    }
@@ -7631,6 +7650,9 @@ public class Notification implements Parcelable
     * @hide
     */
    public boolean showsChronometer() {
        if (Flags.sortSectionByTime()) {
            return extras.getBoolean(EXTRA_SHOW_CHRONOMETER);
        }
        return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER);
    }
+32 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemProperties;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
@@ -126,6 +127,7 @@ public class NotificationTest {

    @Rule
    public TestRule compatChangeRule = new PlatformCompatChangeRule();
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Before
    public void setUp() {
@@ -1835,6 +1837,36 @@ public class NotificationTest {
        Assert.assertEquals(bitmap, resultBitmap);
    }

    @Test
    public void testGetWhen_zero() {
        Notification n = new Notification.Builder(mContext, "test")
                .setWhen(0)
                .build();

        mSetFlagsRule.disableFlags(Flags.FLAG_SORT_SECTION_BY_TIME);

        assertThat(n.getWhen()).isEqualTo(0);

        mSetFlagsRule.enableFlags(Flags.FLAG_SORT_SECTION_BY_TIME);

        assertThat(n.getWhen()).isEqualTo(n.creationTime);
    }

    @Test
    public void testGetWhen_devProvidedNonZero() {
        Notification n = new Notification.Builder(mContext, "test")
                .setWhen(9)
                .build();

        mSetFlagsRule.disableFlags(Flags.FLAG_SORT_SECTION_BY_TIME);

        assertThat(n.getWhen()).isEqualTo(9);

        mSetFlagsRule.enableFlags(Flags.FLAG_SORT_SECTION_BY_TIME);

        assertThat(n.getWhen()).isEqualTo(9);
    }

    private void assertValid(Notification.Colors c) {
        // Assert that all colors are populated
        assertThat(c.getBackgroundColor()).isNotEqualTo(Notification.COLOR_INVALID);
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public class NotificationHelper {
                    if (messages2 == null) {
                        return -1;
                    }
                    return (int) (n2.when - n1.when);
                    return (int) (n2.getWhen() - n1.getWhen());
                }
            };

+5 −4
Original line number Diff line number Diff line
@@ -1243,8 +1243,9 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
        if (cmp != 0) return cmp;

        cmp = -1 * Long.compare(
                o1.getRepresentativeEntry().getSbn().getNotification().when,
                o2.getRepresentativeEntry().getSbn().getNotification().when);
                o1.getRepresentativeEntry().getSbn().getNotification().getWhen(),
                o2.getRepresentativeEntry().getSbn().getNotification().getWhen());

        return cmp;
    };

@@ -1256,8 +1257,8 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
        if (cmp != 0) return cmp;

        cmp = -1 * Long.compare(
                o1.getRepresentativeEntry().getSbn().getNotification().when,
                o2.getRepresentativeEntry().getSbn().getNotification().when);
                o1.getRepresentativeEntry().getSbn().getNotification().getWhen(),
                o2.getRepresentativeEntry().getSbn().getNotification().getWhen());
        return cmp;
    };

+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ constructor(
        var futureTime = Long.MAX_VALUE
        groupEntry.children
            .asSequence()
            .mapNotNull { child -> child.sbn.notification.`when`.takeIf { it > 0 } }
            .mapNotNull { child -> child.sbn.notification.getWhen().takeIf { it > 0 } }
            .forEach { time ->
                val isInThePast = currentTimeMillis - time > 0
                if (isInThePast) {
Loading