summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alisa Hung <alisahung@google.com> 2025-06-13 05:52:18 -0700
committer Kampalus <kampalus@protonmail.ch> 2025-09-18 09:09:22 +0200
commitd603ff6d17067f9653ccd4c8825019f591ae7dd7 (patch)
treea01568c5de2f5ba2e828c6a3f13246068c82a18a
parent70daf2478f8835d778f06a0e2e4c3f497bacac11 (diff)
[SP 2025-09-01] Trim oversized strings in setId and setConversationId
Flag: EXEMPT bugfix Test: android.app.NotificationChannelTest Test: cts NotificationChannelTest Bug: 419014146 Change-Id: Id721d3123ee8d38753f550fe57ba0f5d15d743ac (cherry picked from commit a9a1b4365b8d6def5b36fed7dd9caf2389fe0a51)
-rw-r--r--core/java/android/app/NotificationChannel.java6
-rw-r--r--core/tests/coretests/src/android/app/NotificationChannelTest.java30
2 files changed, 33 insertions, 3 deletions
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java
index c1d80c93cfd6..acdcb7cadd58 100644
--- a/core/java/android/app/NotificationChannel.java
+++ b/core/java/android/app/NotificationChannel.java
@@ -650,7 +650,7 @@ public final class NotificationChannel implements Parcelable {
* @hide
*/
public void setId(String id) {
- mId = id;
+ mId = getTrimmedString(id);
}
// Modifiable by apps on channel creation.
@@ -894,8 +894,8 @@ public final class NotificationChannel implements Parcelable {
*/
public void setConversationId(@NonNull String parentChannelId,
@NonNull String conversationId) {
- mParentId = parentChannelId;
- mConversationId = conversationId;
+ mParentId = getTrimmedString(parentChannelId);
+ mConversationId = getTrimmedString(conversationId);
}
/**
diff --git a/core/tests/coretests/src/android/app/NotificationChannelTest.java b/core/tests/coretests/src/android/app/NotificationChannelTest.java
index b1d995a2eb9d..aea65c88c15d 100644
--- a/core/tests/coretests/src/android/app/NotificationChannelTest.java
+++ b/core/tests/coretests/src/android/app/NotificationChannelTest.java
@@ -256,6 +256,36 @@ public class NotificationChannelTest {
}
@Test
+ public void testSetId_longStringIsTrimmed() {
+ NotificationChannel channel =
+ new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
+ String longId = Strings.repeat("A", NotificationChannel.MAX_TEXT_LENGTH + 10);
+
+ channel.setId(longId);
+
+ assertThat(channel.getId()).hasLength(NotificationChannel.MAX_TEXT_LENGTH);
+ assertThat(channel.getId())
+ .isEqualTo(longId.substring(0, NotificationChannel.MAX_TEXT_LENGTH));
+ }
+
+ @Test
+ public void testSetConversationId_longStringsAreTrimmed() {
+ NotificationChannel channel =
+ new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
+ String longParentId = Strings.repeat("P", NotificationChannel.MAX_TEXT_LENGTH + 10);
+ String longConversationId = Strings.repeat("C", NotificationChannel.MAX_TEXT_LENGTH + 10);
+
+ channel.setConversationId(longParentId, longConversationId);
+
+ assertThat(channel.getParentChannelId()).hasLength(NotificationChannel.MAX_TEXT_LENGTH);
+ assertThat(channel.getParentChannelId())
+ .isEqualTo(longParentId.substring(0, NotificationChannel.MAX_TEXT_LENGTH));
+ assertThat(channel.getConversationId()).hasLength(NotificationChannel.MAX_TEXT_LENGTH);
+ assertThat(channel.getConversationId())
+ .isEqualTo(longConversationId.substring(0, NotificationChannel.MAX_TEXT_LENGTH));
+ }
+
+ @Test
@EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API,
Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS})
public void testLongVibrationFields_canWriteToXml() throws Exception {