Don't overwrite remote views with null values.

Change-Id: Iac4f92c72b0a514c8ec7ef462eca382988f5525e
Fixes: 28939640
diff --git a/v4/api20/android/support/v4/app/NotificationCompatApi20.java b/v4/api20/android/support/v4/app/NotificationCompatApi20.java
index 8797a07..036fb24 100644
--- a/v4/api20/android/support/v4/app/NotificationCompatApi20.java
+++ b/v4/api20/android/support/v4/app/NotificationCompatApi20.java
@@ -99,8 +99,12 @@
         public Notification build() {
             b.setExtras(mExtras);
             Notification notification = b.build();
-            notification.contentView = mContentView;
-            notification.bigContentView = mBigContentView;
+            if (mContentView != null) {
+                notification.contentView = mContentView;
+            }
+            if (mBigContentView != null) {
+                notification.bigContentView = mBigContentView;
+            }
             return notification;
         }
     }
diff --git a/v4/api21/android/support/v4/app/NotificationCompatApi21.java b/v4/api21/android/support/v4/app/NotificationCompatApi21.java
index 5da3646..f060486 100644
--- a/v4/api21/android/support/v4/app/NotificationCompatApi21.java
+++ b/v4/api21/android/support/v4/app/NotificationCompatApi21.java
@@ -130,9 +130,15 @@
         public Notification build() {
             b.setExtras(mExtras);
             Notification notification = b.build();
-            notification.contentView =  mContentView;
-            notification.bigContentView = mBigContentView;
-            notification.headsUpContentView = mHeadsUpContentView;
+            if (mContentView != null) {
+                notification.contentView = mContentView;
+            }
+            if (mBigContentView != null) {
+                notification.bigContentView = mBigContentView;
+            }
+            if (mHeadsUpContentView != null) {
+                notification.headsUpContentView = mHeadsUpContentView;
+            }
             return notification;
         }
     }
diff --git a/v4/api24/android/support/v4/app/NotificationCompatApi24.java b/v4/api24/android/support/v4/app/NotificationCompatApi24.java
index 65c5d73..e533b21 100644
--- a/v4/api24/android/support/v4/app/NotificationCompatApi24.java
+++ b/v4/api24/android/support/v4/app/NotificationCompatApi24.java
@@ -94,10 +94,16 @@
                     .setColor(color)
                     .setVisibility(visibility)
                     .setPublicVersion(publicVersion)
-                    .setRemoteInputHistory(remoteInputHistory)
-                    .setCustomContentView(contentView)
-                    .setCustomBigContentView(bigContentView)
-                    .setCustomHeadsUpContentView(headsUpContentView);
+                    .setRemoteInputHistory(remoteInputHistory);
+            if (contentView != null) {
+                b.setCustomContentView(contentView);
+            }
+            if (bigContentView != null) {
+                b.setCustomBigContentView(bigContentView);
+            }
+            if (headsUpContentView != null) {
+                b.setCustomHeadsUpContentView(headsUpContentView);
+            }
             for (String person: people) {
                 b.addPerson(person);
             }
diff --git a/v4/java/android/support/v4/app/NotificationCompat.java b/v4/java/android/support/v4/app/NotificationCompat.java
index 6c18db6..d7b778c 100644
--- a/v4/java/android/support/v4/app/NotificationCompat.java
+++ b/v4/java/android/support/v4/app/NotificationCompat.java
@@ -526,7 +526,9 @@
             if (b.mPriority > PRIORITY_DEFAULT) {
                 result.flags |= FLAG_HIGH_PRIORITY;
             }
-            result.contentView =  b.mContentView;
+            if (b.mContentView != null) {
+                result.contentView = b.mContentView;
+            }
             return result;
         }
 
@@ -604,7 +606,9 @@
             if (b.mPriority > PRIORITY_DEFAULT) {
                 result.flags |= FLAG_HIGH_PRIORITY;
             }
-            result.contentView =  b.mContentView;
+            if (b.mContentView != null) {
+                result.contentView = b.mContentView;
+            }
             return result;
         }
     }
@@ -615,7 +619,9 @@
             Notification notification = NotificationCompatHoneycomb.add(b.mContext, b.mNotification,
                     b.mContentTitle, b.mContentText, b.mContentInfo, b.mTickerView,
                     b.mNumber, b.mContentIntent, b.mFullScreenIntent, b.mLargeIcon);
-            notification.contentView =  b.mContentView;
+            if (b.mContentView != null) {
+                notification.contentView = b.mContentView;
+            }
             return notification;
         }
     }
@@ -629,7 +635,9 @@
                             b.mTickerView, b.mNumber, b.mContentIntent, b.mFullScreenIntent, b.mLargeIcon,
                             b.mProgressMax, b.mProgress, b.mProgressIndeterminate);
             Notification notification = extender.build(b, builder);
-            notification.contentView =  b.mContentView;
+            if (b.mContentView != null) {
+                notification.contentView = b.mContentView;
+            }
             return notification;
         }
     }
diff --git a/v4/jellybean/android/support/v4/app/NotificationCompatJellybean.java b/v4/jellybean/android/support/v4/app/NotificationCompatJellybean.java
index f467845..261d8c4 100644
--- a/v4/jellybean/android/support/v4/app/NotificationCompatJellybean.java
+++ b/v4/jellybean/android/support/v4/app/NotificationCompatJellybean.java
@@ -153,8 +153,12 @@
                 // Add the action extras sparse array if any action was added with extras.
                 getExtras(notif).putSparseParcelableArray(EXTRA_ACTION_EXTRAS, actionExtrasMap);
             }
-            notif.contentView = mContentView;
-            notif.bigContentView = mBigContentView;
+            if (mContentView != null) {
+                notif.contentView = mContentView;
+            }
+            if (mBigContentView != null) {
+                notif.bigContentView = mBigContentView;
+            }
             return notif;
         }
     }
diff --git a/v4/kitkat/android/support/v4/app/NotificationCompatKitKat.java b/v4/kitkat/android/support/v4/app/NotificationCompatKitKat.java
index e332830..3039458 100644
--- a/v4/kitkat/android/support/v4/app/NotificationCompatKitKat.java
+++ b/v4/kitkat/android/support/v4/app/NotificationCompatKitKat.java
@@ -117,8 +117,12 @@
             }
             b.setExtras(mExtras);
             Notification notification = b.build();
-            notification.contentView = mContentView;
-            notification.bigContentView = mBigContentView;
+            if (mContentView != null) {
+                notification.contentView = mContentView;
+            }
+            if (mBigContentView != null) {
+                notification.bigContentView = mBigContentView;
+            }
             return notification;
         }
     }