Fix NPE
Test: NotificationChannelGroupTest
Test: view notification settings for an app that doesn't use groups
Fixes: 244574602
Bug: 241764350
Bug: 241764340
Bug: 241764135
Bug: 242702935
Bug: 242703118
Bug: 242703202
Bug: 242702851
Bug: 242703217
Bug: 242703556
Change-Id: I9c681106f6d645e62b0e44903d40aa523fee0e95
(cherry picked from commit 6f02c07176)
Merged-In: I9c681106f6d645e62b0e44903d40aa523fee0e95
This commit is contained in:
@@ -95,8 +95,11 @@ public final class NotificationChannelGroup implements Parcelable {
|
|||||||
} else {
|
} else {
|
||||||
mId = null;
|
mId = null;
|
||||||
}
|
}
|
||||||
mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
|
if (in.readByte() != 0) {
|
||||||
mName = getTrimmedString(mName.toString());
|
mName = getTrimmedString(in.readString());
|
||||||
|
} else {
|
||||||
|
mName = "";
|
||||||
|
}
|
||||||
if (in.readByte() != 0) {
|
if (in.readByte() != 0) {
|
||||||
mDescription = getTrimmedString(in.readString());
|
mDescription = getTrimmedString(in.readString());
|
||||||
} else {
|
} else {
|
||||||
@@ -122,7 +125,12 @@ public final class NotificationChannelGroup implements Parcelable {
|
|||||||
} else {
|
} else {
|
||||||
dest.writeByte((byte) 0);
|
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) {
|
if (mDescription != null) {
|
||||||
dest.writeByte((byte) 1);
|
dest.writeByte((byte) 1);
|
||||||
dest.writeString(mDescription);
|
dest.writeString(mDescription);
|
||||||
|
|||||||
@@ -17,9 +17,11 @@
|
|||||||
package android.app;
|
package android.app;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
@@ -70,4 +72,18 @@ public class NotificationChannelGroupTest {
|
|||||||
assertEquals(NotificationChannelGroup.MAX_TEXT_LENGTH,
|
assertEquals(NotificationChannelGroup.MAX_TEXT_LENGTH,
|
||||||
fromParcel.getDescription().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