diff options
author | Julia Reynolds <juliacr@google.com> | 2022-09-22 19:31:57 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-09-22 19:31:57 +0000 |
commit | 23ffc379fe8794c466b5a38a4e6f04856897f801 (patch) | |
tree | 32d1c8b942271ec987bf60d90bbb55878bd0a594 | |
parent | 32dfdfc4b7eab129aa64693dc3b33030fc52c384 (diff) | |
parent | 261b601d25a8779ce40edbb76e85089bfdc027cb (diff) | |
download | base-23ffc379fe8794c466b5a38a4e6f04856897f801.tar.gz |
Merge "Fix NPE" into qt-dev am: 261b601d25
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19886859
Change-Id: I1d34705e2995a26c7f396fef7027031d62010990
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | core/java/android/app/NotificationChannelGroup.java | 14 | ||||
-rw-r--r-- | core/tests/coretests/src/android/app/NotificationChannelGroupTest.java | 16 |
2 files changed, 27 insertions, 3 deletions
diff --git a/core/java/android/app/NotificationChannelGroup.java b/core/java/android/app/NotificationChannelGroup.java index 85de55e6dd2e..cb20b7f84256 100644 --- a/core/java/android/app/NotificationChannelGroup.java +++ b/core/java/android/app/NotificationChannelGroup.java @@ -94,8 +94,11 @@ public final class NotificationChannelGroup implements Parcelable { } else { mId = null; } - mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - mName = getTrimmedString(mName.toString()); + if (in.readByte() != 0) { + mName = getTrimmedString(in.readString()); + } else { + mName = ""; + } if (in.readByte() != 0) { mDescription = getTrimmedString(in.readString()); } else { @@ -121,7 +124,12 @@ public final class NotificationChannelGroup implements Parcelable { } else { dest.writeByte((byte) 0); } - TextUtils.writeToParcel(mName.toString(), dest, flags); + if (mName != null) { + dest.writeByte((byte) 1); + dest.writeString(mName.toString()); + } else { + dest.writeByte((byte) 0); + } if (mDescription != null) { dest.writeByte((byte) 1); dest.writeString(mDescription); diff --git a/core/tests/coretests/src/android/app/NotificationChannelGroupTest.java b/core/tests/coretests/src/android/app/NotificationChannelGroupTest.java index 2a3da05eabb3..625c66a4c60e 100644 --- a/core/tests/coretests/src/android/app/NotificationChannelGroupTest.java +++ b/core/tests/coretests/src/android/app/NotificationChannelGroupTest.java @@ -17,9 +17,11 @@ package android.app; import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; import android.os.Parcel; import android.test.AndroidTestCase; +import android.text.TextUtils; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -70,4 +72,18 @@ public class NotificationChannelGroupTest { assertEquals(NotificationChannelGroup.MAX_TEXT_LENGTH, fromParcel.getDescription().length()); } + + @Test + public void testNullableFields() { + NotificationChannelGroup group = new NotificationChannelGroup("my_group_01", null); + + Parcel parcel = Parcel.obtain(); + group.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + + NotificationChannelGroup fromParcel = + NotificationChannelGroup.CREATOR.createFromParcel(parcel); + assertEquals(group.getId(), fromParcel.getId()); + assertTrue(TextUtils.isEmpty(fromParcel.getName())); + } } |