Merge "Fix NPE" into sc-v2-dev am: 70cc3c99d3 am: 1cdad7c9ae
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19886854 Change-Id: I6f175a177d4dca48cd383782617cfbf975e58790 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -95,8 +95,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 {
|
||||
@@ -122,7 +125,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);
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user