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

Commit 88b0b0b6 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

[RONs] Eliminate invalid points from ProgressStyle

Bug: 359128724
Test: presubmit && post ProgressStyle with point whose position is bigger than progressMax
Flag: android.app.api_rich_ongoing
Change-Id: I9b0901b0d672d694613f6bb2b15219d9c05739c5
parent 387c9494
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -11823,28 +11823,42 @@ public class Notification implements Parcelable
                        sanitizeProgressColor(indeterminateColor,
                                backgroundColor, defaultProgressColor));
            } else {
                // Ensure segment color contrasts.
                final List<Segment> segments = new ArrayList<>();
                int totalLength = 0;
                for (Segment segment : mProgressSegments) {
                    final int length = segment.getLength();
                    if (length <= 0) continue;
                    try {
                        totalLength += Math.addExact(totalLength, length);
                        segments.add(sanitizeSegment(segment, backgroundColor,
                                defaultProgressColor));
                    } catch (ArithmeticException e) {
                        totalLength = DEFAULT_PROGRESS_MAX;
                        segments.clear();
                        break;
                    }
                }
                // Create default segment when no segments are provided.
                if (segments.isEmpty()) {
                    segments.add(sanitizeSegment(new Segment(100), backgroundColor,
                    totalLength = DEFAULT_PROGRESS_MAX;
                    segments.add(sanitizeSegment(new Segment(totalLength), backgroundColor,
                            defaultProgressColor));
                }
                // Ensure point color contrasts.
                final List<Point> points = new ArrayList<>();
                for (Point point : mProgressPoints) {
                    final int position = point.getPosition();
                    if (position < 0 || position > totalLength) continue;
                    points.add(sanitizePoint(point, backgroundColor, defaultProgressColor));
                }
                model = new NotificationProgressModel(segments, points,
                        mProgress, mIsStyledByProgress);
                        Math.clamp(mProgress, 0, totalLength), mIsStyledByProgress);
            }
            return model;
        }
+1 −1
Original line number Diff line number Diff line
@@ -453,7 +453,7 @@ public final class NotificationProgressBar extends ProgressBar {
        }
        for (ProgressStyle.Point point : points) {
            final int pos = point.getPosition();
            if (pos <= 0 || pos >= progressMax) {
            if (pos < 0 || pos > progressMax) {
                throw new IllegalArgumentException("Invalid Point position : " + pos);
            }
        }
+0 −30
Original line number Diff line number Diff line
@@ -171,36 +171,6 @@ public class NotificationProgressBarTest {
                isStyledByProgress);
    }

    @Test(expected = IllegalArgumentException.class)
    public void processAndConvertToDrawableParts_pointPositionIsZero() {
        List<ProgressStyle.Segment> segments = new ArrayList<>();
        segments.add(new ProgressStyle.Segment(100));
        List<ProgressStyle.Point> points = new ArrayList<>();
        points.add(new ProgressStyle.Point(0).setColor(Color.RED));
        int progress = 50;
        int progressMax = 100;
        boolean isStyledByProgress = true;

        NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
                progressMax,
                isStyledByProgress);
    }

    @Test(expected = IllegalArgumentException.class)
    public void processAndConvertToDrawableParts_pointPositionAtMax() {
        List<ProgressStyle.Segment> segments = new ArrayList<>();
        segments.add(new ProgressStyle.Segment(100));
        List<ProgressStyle.Point> points = new ArrayList<>();
        points.add(new ProgressStyle.Point(100).setColor(Color.RED));
        int progress = 50;
        int progressMax = 100;
        boolean isStyledByProgress = true;

        NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
                progressMax,
                isStyledByProgress);
    }

    @Test(expected = IllegalArgumentException.class)
    public void processAndConvertToDrawableParts_pointPositionAboveMax() {
        List<ProgressStyle.Segment> segments = new ArrayList<>();