Move Decorated+MediaStyle big contentView into the style

Make DecoratedMediaStyle and MediaStyle provide their own
big contentView through their respective makeBigContentView
methods.

This removes the requirement to use v7 Notification for
MediaStyle notifications.

Test: Manual inspection
BUG: 28983951
Change-Id: I8a4e09616d365eb4c7294d4ac3a52475da07973a
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
index 1e0a249..0ae60d4 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
@@ -35,9 +35,8 @@
 
 /**
  * An extension of {@link android.support.v4.app.NotificationCompat} which supports
- * {@link android.support.v7.app.NotificationCompat.MediaStyle}
- * and {@link android.support.v7.app.NotificationCompat.DecoratedMediaCustomViewStyle}.
- * You should start using this variant if you need support any of these styles.
+ * {@link android.support.v7.app.NotificationCompat.DecoratedMediaCustomViewStyle}.
+ * You should start using this variant if you need support this style.
  */
 public class NotificationCompat extends android.support.v4.app.NotificationCompat {
 
@@ -73,46 +72,6 @@
         return null;
     }
 
-    @RequiresApi(16)
-    private static void addBigStyleToBuilderJellybean(Notification n,
-            android.support.v4.app.NotificationCompat.Builder b) {
-        if (b.mStyle instanceof MediaStyle) {
-            MediaStyle mediaStyle = (MediaStyle) b.mStyle;
-            RemoteViews innerView = b.getBigContentView() != null
-                    ? b.getBigContentView()
-                    : b.getContentView();
-            boolean isDecorated = b.mStyle instanceof DecoratedMediaCustomViewStyle
-                    && innerView != null;
-            NotificationCompatImplBase.overrideMediaBigContentView(n, b.mContext,
-                    b.mContentTitle, b.mContentText, b.mContentInfo, b.mNumber, b.mLargeIcon,
-                    b.mSubText, b.mUseChronometer, b.getWhenIfShowing(), b.getPriority(), 0,
-                    b.mActions, mediaStyle.mShowCancelButton, mediaStyle.mCancelButtonIntent,
-                    isDecorated);
-            if (isDecorated) {
-                NotificationCompatImplBase.buildIntoRemoteViews(b.mContext, n.bigContentView,
-                        innerView);
-            }
-        }
-    }
-
-    @RequiresApi(21)
-    private static void addBigStyleToBuilderLollipop(Notification n,
-            android.support.v4.app.NotificationCompat.Builder b) {
-        RemoteViews innerView = b.getBigContentView() != null
-                ? b.getBigContentView()
-                : b.getContentView();
-        if (b.mStyle instanceof DecoratedMediaCustomViewStyle && innerView != null) {
-            NotificationCompatImplBase.overrideMediaBigContentView(n, b.mContext,
-                    b.mContentTitle, b.mContentText, b.mContentInfo, b.mNumber, b.mLargeIcon,
-                    b.mSubText, b.mUseChronometer, b.getWhenIfShowing(), b.getPriority(), 0,
-                    b.mActions, false /* showCancelButton */, null /* cancelButtonIntent */,
-                    true /* decoratedCustomView */);
-                    NotificationCompatImplBase.buildIntoRemoteViews(b.mContext, n.bigContentView,
-                            innerView);
-            setBackgroundColor(b.mContext, n.bigContentView, b.getColor());
-        }
-    }
-
     private static void setBackgroundColor(Context context, RemoteViews views, int color) {
         if (color == COLOR_DEFAULT) {
             color = context.getResources().getColor(
@@ -162,29 +121,12 @@
                 return super.getExtender();
             } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                 return new LollipopExtender();
-            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
-                return new JellybeanExtender();
             } else {
                 return super.getExtender();
             }
         }
     }
 
-    @RequiresApi(16)
-    private static class JellybeanExtender extends BuilderExtender {
-
-        JellybeanExtender() {
-        }
-
-        @Override
-        public Notification build(android.support.v4.app.NotificationCompat.Builder b,
-                NotificationBuilderWithBuilderAccessor builder) {
-            Notification n = super.build(b, builder);
-            addBigStyleToBuilderJellybean(n, b);
-            return n;
-        }
-    }
-
     @RequiresApi(21)
     private static class LollipopExtender extends BuilderExtender {
 
@@ -195,7 +137,6 @@
         public Notification build(android.support.v4.app.NotificationCompat.Builder b,
                 NotificationBuilderWithBuilderAccessor builder) {
             Notification n = super.build(b, builder);
-            addBigStyleToBuilderLollipop(n, b);
             addHeadsUpToBuilderLollipop(n, b);
             return n;
         }
@@ -326,6 +267,8 @@
                 NotificationCompatImpl21.addMediaStyle(builder,
                         mActionsToShowInCompact,
                         mToken != null ? mToken.getToken() : null);
+            } else if (mShowCancelButton) {
+                builder.getBuilder().setOngoing(true);
             }
         }
 
@@ -352,6 +295,29 @@
                     mBuilder.getPriority(), mBuilder.mActions, mActionsToShowInCompact,
                     mShowCancelButton, mCancelButtonIntent, isDecorated);
         }
+
+        /**
+         * @hide
+         */
+        @RestrictTo(LIBRARY_GROUP)
+        @Override
+        public RemoteViews makeBigContentView(NotificationBuilderWithBuilderAccessor builder) {
+            if (Build.VERSION.SDK_INT >= 21) {
+                // No custom content view required
+                return null;
+            }
+            return generateBigContentView(false);
+        }
+
+        RemoteViews generateBigContentView(boolean isDecorated) {
+            return NotificationCompatImplBase.generateMediaBigView(
+                    mBuilder.mContext, mBuilder.mContentTitle, mBuilder.mContentText,
+                    mBuilder.mContentInfo, mBuilder.mNumber, mBuilder.mLargeIcon,
+                    mBuilder.mSubText, mBuilder.mUseChronometer,
+                    mBuilder.getWhenIfShowing(), mBuilder.getPriority(), 0,
+                    mBuilder.mActions, mShowCancelButton, mCancelButtonIntent,
+                    isDecorated);
+        }
     }
 
 
@@ -561,5 +527,32 @@
             }
             return null;
         }
+
+        /**
+         * @hide
+         */
+        @RestrictTo(LIBRARY_GROUP)
+        @Override
+        public RemoteViews makeBigContentView(NotificationBuilderWithBuilderAccessor builder) {
+            if (Build.VERSION.SDK_INT >= 24) {
+                // No custom big content view required
+                return null;
+            }
+            RemoteViews innerView = mBuilder.getBigContentView() != null
+                    ? mBuilder.getBigContentView()
+                    : mBuilder.getContentView();
+            if (innerView == null) {
+                // No expandable notification
+                return null;
+            }
+            RemoteViews bigContentView = generateBigContentView(true);
+            NotificationCompatImplBase.buildIntoRemoteViews(mBuilder.mContext,
+                    bigContentView,
+                    innerView);
+            if (Build.VERSION.SDK_INT >= 21) {
+                setBackgroundColor(mBuilder.mContext, bigContentView, mBuilder.getColor());
+            }
+            return bigContentView;
+        }
     }
 }
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java b/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
index c1432c9..5875962 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompatImplBase.java
@@ -16,7 +16,6 @@
 
 package android.support.v7.app;
 
-import android.app.Notification;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.res.Resources;
@@ -116,21 +115,6 @@
         return view;
     }
 
-    @RequiresApi(16)
-    public static <T extends NotificationCompatBase.Action> void overrideMediaBigContentView(
-            Notification n, Context context, CharSequence contentTitle, CharSequence contentText,
-            CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText,
-            boolean useChronometer, long when, int priority, int color, List<T> actions,
-            boolean showCancelButton, PendingIntent cancelButtonIntent,
-            boolean decoratedCustomView) {
-        n.bigContentView = generateMediaBigView(context, contentTitle, contentText, contentInfo,
-                number, largeIcon, subText, useChronometer, when, priority, color, actions,
-                showCancelButton, cancelButtonIntent, decoratedCustomView);
-        if (showCancelButton) {
-            n.flags |= Notification.FLAG_ONGOING_EVENT;
-        }
-    }
-
     @RequiresApi(11)
     public static <T extends NotificationCompatBase.Action> RemoteViews generateMediaBigView(
             Context context, CharSequence contentTitle, CharSequence contentText,