Loading core/java/android/app/Notification.java +5 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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; Loading Loading @@ -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; Loading core/tests/coretests/src/android/app/NotificationTest.java +44 −4 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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) ) ); Loading core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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, Loading Loading
core/java/android/app/Notification.java +5 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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; Loading Loading @@ -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; Loading
core/tests/coretests/src/android/app/NotificationTest.java +44 −4 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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) ) ); Loading
core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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, Loading