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

Commit b0431885 authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

Fix bug: ProgressStyle.setProgressSegments doesn't set the segments.

Flag: android.app.api_rich_ongoing
Bug: 359918677
Test: patch ag/29675286 and run ProgressStyleNotificationScreenshotTest
Test: atest NotificationTest
Change-Id: Id10171b30409b36a21bbc346d0163771dc77ddd3
parent 735aa554
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -11296,7 +11296,11 @@ public class Notification implements Parcelable
         * @see Segment
         */
        public @NonNull ProgressStyle setProgressSegments(@NonNull List<Segment> progressSegments) {
            mProgressSegments = new ArrayList<>(progressSegments.size());
            if (mProgressSegments == null) {
                mProgressSegments = new ArrayList<>();
            }
            mProgressSegments.clear();
            mProgressSegments.addAll(progressSegments);
            return this;
        }
+16 −1
Original line number Diff line number Diff line
@@ -2397,10 +2397,25 @@ public class NotificationTest {
    public void progressStyle_getProgressMax_returnsSumOfSegmentLength() {
        final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
        progressStyle
                .setProgressSegments(List.of(new Notification.ProgressStyle.Segment(15),
                        new Notification.ProgressStyle.Segment(25)))
                .addProgressSegment(new Notification.ProgressStyle.Segment(10))
                .addProgressSegment(new Notification.ProgressStyle.Segment(20));

        assertThat(progressStyle.getProgressMax()).isEqualTo(30);
        assertThat(progressStyle.getProgressMax()).isEqualTo(70);
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void progressStyle_getProgressMax_onSetProgressSegments_resets() {
        final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
        progressStyle
                .addProgressSegment(new Notification.ProgressStyle.Segment(10))
                .addProgressSegment(new Notification.ProgressStyle.Segment(20))
                .setProgressSegments(List.of(new Notification.ProgressStyle.Segment(15),
                        new Notification.ProgressStyle.Segment(25)));

        assertThat(progressStyle.getProgressMax()).isEqualTo(40);
    }

    @Test