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

Commit 3d39a54f authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/34081795']...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/34081795'] into security-aosp-24Q3-release.

Change-Id: Ic6c805d5530d074f111887cc072823e8bf9ee699
parents 3174d1e3 fc5d9b6e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -581,7 +581,7 @@ public final class NotificationChannel implements Parcelable {
     * @hide
     */
    public void setId(String id) {
        mId = id;
        mId = getTrimmedString(id);
    }

    // Modifiable by apps on channel creation.
@@ -818,8 +818,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);
    }

    /**
+30 −0
Original line number Diff line number Diff line
@@ -234,6 +234,36 @@ public class NotificationChannelTest {
                fromParcel.getSound().toString().length());
    }

    @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)
    public void testLongVibrationFields_canWriteToXml() throws Exception {