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

Commit 423e958c authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

In Notification.java, ignore ProgressStyle points at start and end.

These are ignored in NotificationProgressBar after ag/31654366. Match
the logic in Notification.java allows more valid points to be drawn.

Flag: android.app.api_rich_ongoing
Fix: 391678201
Test: Post ProgressStyle notifications via test app
Test: patch ag/30006048 and run ProgressStyleNotificationScreenshotTest on device
Test: NotificationProgressBarTest
Change-Id: I04f8d60e10f1c389a8579eb84378636e7a3f5f5b
parent ff8a95c4
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -11370,7 +11370,7 @@ public class Notification implements Parcelable
            if (mProgressPoints == null) {
                mProgressPoints = new ArrayList<>();
            }
            if (point.getPosition() >= 0) {
            if (point.getPosition() > 0) {
                mProgressPoints.add(point);
                if (mProgressPoints.size() > MAX_PROGRESS_POINT_LIMIT) {
@@ -11379,7 +11379,7 @@ public class Notification implements Parcelable
                }
            } else {
                Log.w(TAG, "Dropped the point. The position is a negative integer.");
                Log.w(TAG, "Dropped the point. The position is a negative or zero integer.");
            }
            return this;
@@ -11893,7 +11893,9 @@ public class Notification implements Parcelable
                final List<Point> points = new ArrayList<>();
                for (Point point : mProgressPoints) {
                    final int position = point.getPosition();
                    if (position < 0 || position > totalLength) continue;
                    // The points at start/end aren't supposed to show in the progress bar.
                    // Therefore those are also dropped here.
                    if (position <= 0 || position >= totalLength) continue;
                    points.add(sanitizePoint(point, backgroundColor, defaultProgressColor));
                    if (points.size() == MAX_PROGRESS_POINT_LIMIT) {
                        break;
+44 −4
Original line number Diff line number Diff line
@@ -2530,6 +2530,46 @@ public class NotificationTest {
        assertThat(progressStyle.getProgressPoints()).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void progressStyle_addProgressPoint_dropsZeroPoints() {
        // GIVEN
        final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
        // Points should not be a negative integer.
        progressStyle
                .addProgressPoint(new Notification.ProgressStyle.Point(0));

        // THEN
        assertThat(progressStyle.getProgressPoints()).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void progressStyle_setProgressPoint_dropsZeroPoints() {
        // GIVEN
        final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
        // Points should not be a negative integer.
        progressStyle
                .setProgressPoints(List.of(new Notification.ProgressStyle.Point(0)));

        // THEN
        assertThat(progressStyle.getProgressPoints()).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void progressStyle_createProgressModel_ignoresPointsAtMax() {
        // GIVEN
        final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
        progressStyle.addProgressSegment(new Notification.ProgressStyle.Segment(100));
        // Points should not larger than progress maximum.
        progressStyle
                .addProgressPoint(new Notification.ProgressStyle.Point(100));

        // THEN
        assertThat(progressStyle.createProgressModel(Color.BLUE, Color.RED).getPoints()).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void progressStyle_createProgressModel_ignoresPointsExceedingMax() {
@@ -2573,13 +2613,13 @@ public class NotificationTest {
        // THEN
        assertThat(progressStyle.createProgressModel(defaultProgressColor, backgroundColor)
                .getPoints()).isEqualTo(
                        List.of(new Notification.ProgressStyle.Point(0)
                                .setColor(expectedProgressColor),
                                new Notification.ProgressStyle.Point(20)
                        List.of(new Notification.ProgressStyle.Point(20)
                                .setColor(expectedProgressColor),
                                new Notification.ProgressStyle.Point(50)
                                .setColor(expectedProgressColor),
                                new Notification.ProgressStyle.Point(70)
                                .setColor(expectedProgressColor),
                                new Notification.ProgressStyle.Point(80)
                                        .setColor(expectedProgressColor)
                        )
        );
+2 −2
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public class NotificationProgressModelTest {
                new Notification.ProgressStyle.Segment(50).setColor(Color.YELLOW),
                new Notification.ProgressStyle.Segment(50).setColor(Color.LTGRAY));
        final List<Notification.ProgressStyle.Point> points = List.of(
                new Notification.ProgressStyle.Point(0).setColor(Color.RED),
                new Notification.ProgressStyle.Point(1).setColor(Color.RED),
                new Notification.ProgressStyle.Point(20).setColor(Color.BLUE));
        final NotificationProgressModel savedModel = new NotificationProgressModel(segments,
                points,
@@ -121,7 +121,7 @@ public class NotificationProgressModelTest {
                new Notification.ProgressStyle.Segment(50).setColor(Color.YELLOW),
                new Notification.ProgressStyle.Segment(50).setColor(Color.YELLOW));
        final List<Notification.ProgressStyle.Point> points = List.of(
                new Notification.ProgressStyle.Point(0).setColor(Color.RED),
                new Notification.ProgressStyle.Point(1).setColor(Color.RED),
                new Notification.ProgressStyle.Point(20).setColor(Color.BLUE));
        final NotificationProgressModel savedModel = new NotificationProgressModel(segments,
                points,