Merge "Fix crash with decorated custom notifications" into nyc-dev
This commit is contained in:
@@ -3556,7 +3556,8 @@ public class Notification implements Parcelable
|
||||
mStyle.buildStyled(mN);
|
||||
}
|
||||
|
||||
if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
|
||||
if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N
|
||||
&& (mStyle == null || !mStyle.displayCustomViewInline())) {
|
||||
if (mN.contentView == null) {
|
||||
mN.contentView = createContentView();
|
||||
mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT,
|
||||
@@ -4570,6 +4571,11 @@ public class Notification implements Parcelable
|
||||
private void buildIntoRemoteViewContent(RemoteViews remoteViews,
|
||||
RemoteViews customContent) {
|
||||
remoteViews.removeAllViews(R.id.notification_main_column);
|
||||
// Need to clone customContent before adding, because otherwise it can no longer be
|
||||
// parceled independently of remoteViews.
|
||||
if (customContent != null) {
|
||||
customContent = customContent.clone();
|
||||
}
|
||||
remoteViews.addView(R.id.notification_main_column, customContent);
|
||||
// also update the end margin if there is an image
|
||||
int endMargin = mBuilder.mContext.getResources().getDimensionPixelSize(
|
||||
@@ -4674,6 +4680,11 @@ public class Notification implements Parcelable
|
||||
private RemoteViews buildIntoRemoteView(RemoteViews remoteViews, int id,
|
||||
RemoteViews customContent) {
|
||||
remoteViews.removeAllViews(id);
|
||||
// Need to clone customContent before adding, because otherwise it can no longer be
|
||||
// parceled independently of remoteViews.
|
||||
if (customContent != null) {
|
||||
customContent = customContent.clone();
|
||||
}
|
||||
remoteViews.addView(id, customContent);
|
||||
return remoteViews;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import android.os.ServiceManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -754,9 +755,16 @@ public abstract class NotificationListenerService extends Service {
|
||||
private void maybePopulateRemoteViews(Notification notification) {
|
||||
if (getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
|
||||
Builder builder = Builder.recoverBuilder(getContext(), notification);
|
||||
notification.contentView = builder.createContentView();
|
||||
notification.bigContentView = builder.createBigContentView();
|
||||
notification.headsUpContentView = builder.createHeadsUpContentView();
|
||||
|
||||
// Some styles wrap Notification's contentView, bigContentView and headsUpContentView.
|
||||
// First inflate them all, only then set them to avoid recursive wrapping.
|
||||
RemoteViews content = builder.createContentView();
|
||||
RemoteViews big = builder.createBigContentView();
|
||||
RemoteViews headsUp = builder.createHeadsUpContentView();
|
||||
|
||||
notification.contentView = content;
|
||||
notification.bigContentView = big;
|
||||
notification.headsUpContentView = headsUp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user