Deal more gracefully with null smallIcons.

First, when parceling a notification with no small icon:
Well, you shouldn't attempt to do this anyway, since NoMan
will reject a notification without a valid smallIcon.  But
setServiceForeground parcels up the Notification on its own
before handing it off to NoMan, so it will crash on an
invalid small icon. (In general, parceling code should never
ever crash, even if the object is in an undesirable state.)

And when build()ing a notification: Same thing---don't build
a notification with no icon; you're going to have a bad
time. But maybe you're going to fix it before you hand it
off to NoMan. Or maybe it's just one page of a wearable
notification, so it doesn't really need its own icon. Either
way, Notification shouldn't crash.

Bug: 21286186
Bug: 21298403
Change-Id: Ie482cde0a3afe3aaabf07be0536551b8e4bceba0
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 3309443..96c6878 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -1366,7 +1366,9 @@
         int version = parcel.readInt();
 
         when = parcel.readLong();
-        mSmallIcon = Icon.CREATOR.createFromParcel(parcel);
+        if (parcel.readInt() != 0) {
+            mSmallIcon = Icon.CREATOR.createFromParcel(parcel);
+        }
         number = parcel.readInt();
         if (parcel.readInt() != 0) {
             contentIntent = PendingIntent.CREATOR.createFromParcel(parcel);
@@ -1590,7 +1592,12 @@
         parcel.writeInt(1);
 
         parcel.writeLong(when);
-        mSmallIcon.writeToParcel(parcel, 0);
+        if (mSmallIcon != null) {
+            parcel.writeInt(1);
+            mSmallIcon.writeToParcel(parcel, 0);
+        } else {
+            parcel.writeInt(0);
+        }
         parcel.writeInt(number);
         if (contentIntent != null) {
             parcel.writeInt(1);
@@ -3241,7 +3248,7 @@
             Notification n = new Notification();
             n.when = mWhen;
             n.mSmallIcon = mSmallIcon;
-            if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) {
+            if (mSmallIcon != null && mSmallIcon.getType() == Icon.TYPE_RESOURCE) {
                 n.icon = mSmallIcon.getResId();
             }
             n.iconLevel = mSmallIconLevel;