summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/Notification.java8
-rw-r--r--core/tests/coretests/src/android/app/NotificationTest.java48
-rw-r--r--core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java4
3 files changed, 51 insertions, 9 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index dce15b833bbb..3633b4eb333a 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -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;
diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java
index ca6ad6fae46e..f89e4416ce78 100644
--- a/core/tests/coretests/src/android/app/NotificationTest.java
+++ b/core/tests/coretests/src/android/app/NotificationTest.java
@@ -2532,6 +2532,46 @@ public class NotificationTest {
@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() {
// GIVEN
final Notification.ProgressStyle progressStyle = new Notification.ProgressStyle();
@@ -2573,14 +2613,14 @@ 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)
+ .setColor(expectedProgressColor),
+ new Notification.ProgressStyle.Point(80)
+ .setColor(expectedProgressColor)
)
);
}
diff --git a/core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java b/core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java
index e1f5b1c2e4a4..140d268e855b 100644
--- a/core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java
+++ b/core/tests/coretests/src/com/android/internal/widget/NotificationProgressModelTest.java
@@ -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,