Loading core/java/android/widget/RemoteViews.java +38 −1 Original line number Original line Diff line number Diff line Loading @@ -1294,6 +1294,15 @@ public class RemoteViews implements Parcelable, Filter { : mItems : mItems : mCollectionCache.getItemsForId(mIntentId); : mCollectionCache.getItemsForId(mIntentId); if (items.hasLegacyNullItems()) { Log.e(LOG_TAG, "Legacy null RemoteViews encountered in " + "RemoteViewsFactory#getRemoteCollectionItems. Widget should not provide " + "null RemoteViews in collections. Use setRemoteAdapter(viewId, items) " + "instead to provide items."); throw new ActionException("Null entries encountered in " + "RemoteViewsFactory#getRemoteCollectionItems"); } // Ensure that we are applying to an AppWidget root // Ensure that we are applying to an AppWidget root if (!(rootParent instanceof AppWidgetHostView)) { if (!(rootParent instanceof AppWidgetHostView)) { Log.e(LOG_TAG, "setRemoteAdapter can only be used for " Log.e(LOG_TAG, "setRemoteAdapter can only be used for " Loading Loading @@ -9529,15 +9538,23 @@ public class RemoteViews implements Parcelable, Filter { private final RemoteViews[] mViews; private final RemoteViews[] mViews; private final boolean mHasStableIds; private final boolean mHasStableIds; private final int mViewTypeCount; private final int mViewTypeCount; private final boolean mHasLegacyNullItems; private HierarchyRootData mHierarchyRootData; private HierarchyRootData mHierarchyRootData; RemoteCollectionItems( RemoteCollectionItems( long[] ids, RemoteViews[] views, boolean hasStableIds, int viewTypeCount) { long[] ids, RemoteViews[] views, boolean hasStableIds, int viewTypeCount) { this(ids, views, hasStableIds, viewTypeCount, /* hasLegacyNullItems= */ false); } RemoteCollectionItems( long[] ids, RemoteViews[] views, boolean hasStableIds, int viewTypeCount, boolean hasLegacyNullItems) { mIds = ids; mIds = ids; mViews = views; mViews = views; mHasStableIds = hasStableIds; mHasStableIds = hasStableIds; mViewTypeCount = viewTypeCount; mViewTypeCount = viewTypeCount; mHasLegacyNullItems = hasLegacyNullItems; if (ids.length != views.length) { if (ids.length != views.length) { throw new IllegalArgumentException( throw new IllegalArgumentException( "RemoteCollectionItems has different number of ids and views"); "RemoteCollectionItems has different number of ids and views"); Loading Loading @@ -9566,6 +9583,7 @@ public class RemoteViews implements Parcelable, Filter { RemoteCollectionItems(@NonNull Parcel in, @Nullable HierarchyRootData hierarchyRootData) { RemoteCollectionItems(@NonNull Parcel in, @Nullable HierarchyRootData hierarchyRootData) { mHasStableIds = in.readBoolean(); mHasStableIds = in.readBoolean(); mViewTypeCount = in.readInt(); mViewTypeCount = in.readInt(); mHasLegacyNullItems = in.readBoolean(); int length = in.readInt(); int length = in.readInt(); mIds = new long[length]; mIds = new long[length]; in.readLongArray(mIds); in.readLongArray(mIds); Loading Loading @@ -9618,6 +9636,7 @@ public class RemoteViews implements Parcelable, Filter { dest.writeBoolean(mHasStableIds); dest.writeBoolean(mHasStableIds); dest.writeInt(mViewTypeCount); dest.writeInt(mViewTypeCount); dest.writeBoolean(mHasLegacyNullItems); dest.writeInt(mIds.length); dest.writeInt(mIds.length); dest.writeLongArray(mIds); dest.writeLongArray(mIds); Loading Loading @@ -9818,6 +9837,10 @@ public class RemoteViews implements Parcelable, Filter { return mHasStableIds; return mHasStableIds; } } boolean hasLegacyNullItems() { return mHasLegacyNullItems; } @NonNull @NonNull public static final Creator<RemoteCollectionItems> CREATOR = public static final Creator<RemoteCollectionItems> CREATOR = new Creator<RemoteCollectionItems>() { new Creator<RemoteCollectionItems>() { Loading @@ -9840,6 +9863,7 @@ public class RemoteViews implements Parcelable, Filter { private final List<RemoteViews> mViews = new ArrayList<>(); private final List<RemoteViews> mViews = new ArrayList<>(); private boolean mHasStableIds; private boolean mHasStableIds; private int mViewTypeCount; private int mViewTypeCount; private boolean mHasLegacyNullItems; /** /** * Adds a {@link RemoteViews} to the collection. * Adds a {@link RemoteViews} to the collection. Loading Loading @@ -9891,6 +9915,18 @@ public class RemoteViews implements Parcelable, Filter { return this; return this; } } /** * Set if the {@code RemoteCollectionItems} has null items. This can only happen during * remote adapter conversion, and we will throw an exception when the action is applied. * * @hide */ @NonNull public Builder setHasLegacyNullItems(boolean hasLegacyNullItems) { mHasLegacyNullItems = hasLegacyNullItems; return this; } /** Creates the {@link RemoteCollectionItems} defined by this builder. */ /** Creates the {@link RemoteCollectionItems} defined by this builder. */ @NonNull @NonNull public RemoteCollectionItems build() { public RemoteCollectionItems build() { Loading @@ -9906,7 +9942,8 @@ public class RemoteViews implements Parcelable, Filter { mIds.toArray(), mIds.toArray(), mViews.toArray(new RemoteViews[0]), mViews.toArray(new RemoteViews[0]), mHasStableIds, mHasStableIds, Math.max(mViewTypeCount, 1)); Math.max(mViewTypeCount, 1), mHasLegacyNullItems); } } } } Loading core/java/android/widget/RemoteViewsService.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -148,6 +148,10 @@ public abstract class RemoteViewsService extends Service { for (int i = 0; i < numOfEntries; i++) { for (int i = 0; i < numOfEntries; i++) { final long currentItemId = getItemId(i); final long currentItemId = getItemId(i); final RemoteViews currentView = getViewAt(i); final RemoteViews currentView = getViewAt(i); if (currentView == null) { itemsBuilder.setHasLegacyNullItems(true); break; } currentView.writeToParcel(capSizeTestParcel, 0); currentView.writeToParcel(capSizeTestParcel, 0); if (capSizeTestParcel.dataSize() > capSize) { if (capSizeTestParcel.dataSize() > capSize) { break; break; Loading Loading
core/java/android/widget/RemoteViews.java +38 −1 Original line number Original line Diff line number Diff line Loading @@ -1294,6 +1294,15 @@ public class RemoteViews implements Parcelable, Filter { : mItems : mItems : mCollectionCache.getItemsForId(mIntentId); : mCollectionCache.getItemsForId(mIntentId); if (items.hasLegacyNullItems()) { Log.e(LOG_TAG, "Legacy null RemoteViews encountered in " + "RemoteViewsFactory#getRemoteCollectionItems. Widget should not provide " + "null RemoteViews in collections. Use setRemoteAdapter(viewId, items) " + "instead to provide items."); throw new ActionException("Null entries encountered in " + "RemoteViewsFactory#getRemoteCollectionItems"); } // Ensure that we are applying to an AppWidget root // Ensure that we are applying to an AppWidget root if (!(rootParent instanceof AppWidgetHostView)) { if (!(rootParent instanceof AppWidgetHostView)) { Log.e(LOG_TAG, "setRemoteAdapter can only be used for " Log.e(LOG_TAG, "setRemoteAdapter can only be used for " Loading Loading @@ -9529,15 +9538,23 @@ public class RemoteViews implements Parcelable, Filter { private final RemoteViews[] mViews; private final RemoteViews[] mViews; private final boolean mHasStableIds; private final boolean mHasStableIds; private final int mViewTypeCount; private final int mViewTypeCount; private final boolean mHasLegacyNullItems; private HierarchyRootData mHierarchyRootData; private HierarchyRootData mHierarchyRootData; RemoteCollectionItems( RemoteCollectionItems( long[] ids, RemoteViews[] views, boolean hasStableIds, int viewTypeCount) { long[] ids, RemoteViews[] views, boolean hasStableIds, int viewTypeCount) { this(ids, views, hasStableIds, viewTypeCount, /* hasLegacyNullItems= */ false); } RemoteCollectionItems( long[] ids, RemoteViews[] views, boolean hasStableIds, int viewTypeCount, boolean hasLegacyNullItems) { mIds = ids; mIds = ids; mViews = views; mViews = views; mHasStableIds = hasStableIds; mHasStableIds = hasStableIds; mViewTypeCount = viewTypeCount; mViewTypeCount = viewTypeCount; mHasLegacyNullItems = hasLegacyNullItems; if (ids.length != views.length) { if (ids.length != views.length) { throw new IllegalArgumentException( throw new IllegalArgumentException( "RemoteCollectionItems has different number of ids and views"); "RemoteCollectionItems has different number of ids and views"); Loading Loading @@ -9566,6 +9583,7 @@ public class RemoteViews implements Parcelable, Filter { RemoteCollectionItems(@NonNull Parcel in, @Nullable HierarchyRootData hierarchyRootData) { RemoteCollectionItems(@NonNull Parcel in, @Nullable HierarchyRootData hierarchyRootData) { mHasStableIds = in.readBoolean(); mHasStableIds = in.readBoolean(); mViewTypeCount = in.readInt(); mViewTypeCount = in.readInt(); mHasLegacyNullItems = in.readBoolean(); int length = in.readInt(); int length = in.readInt(); mIds = new long[length]; mIds = new long[length]; in.readLongArray(mIds); in.readLongArray(mIds); Loading Loading @@ -9618,6 +9636,7 @@ public class RemoteViews implements Parcelable, Filter { dest.writeBoolean(mHasStableIds); dest.writeBoolean(mHasStableIds); dest.writeInt(mViewTypeCount); dest.writeInt(mViewTypeCount); dest.writeBoolean(mHasLegacyNullItems); dest.writeInt(mIds.length); dest.writeInt(mIds.length); dest.writeLongArray(mIds); dest.writeLongArray(mIds); Loading Loading @@ -9818,6 +9837,10 @@ public class RemoteViews implements Parcelable, Filter { return mHasStableIds; return mHasStableIds; } } boolean hasLegacyNullItems() { return mHasLegacyNullItems; } @NonNull @NonNull public static final Creator<RemoteCollectionItems> CREATOR = public static final Creator<RemoteCollectionItems> CREATOR = new Creator<RemoteCollectionItems>() { new Creator<RemoteCollectionItems>() { Loading @@ -9840,6 +9863,7 @@ public class RemoteViews implements Parcelable, Filter { private final List<RemoteViews> mViews = new ArrayList<>(); private final List<RemoteViews> mViews = new ArrayList<>(); private boolean mHasStableIds; private boolean mHasStableIds; private int mViewTypeCount; private int mViewTypeCount; private boolean mHasLegacyNullItems; /** /** * Adds a {@link RemoteViews} to the collection. * Adds a {@link RemoteViews} to the collection. Loading Loading @@ -9891,6 +9915,18 @@ public class RemoteViews implements Parcelable, Filter { return this; return this; } } /** * Set if the {@code RemoteCollectionItems} has null items. This can only happen during * remote adapter conversion, and we will throw an exception when the action is applied. * * @hide */ @NonNull public Builder setHasLegacyNullItems(boolean hasLegacyNullItems) { mHasLegacyNullItems = hasLegacyNullItems; return this; } /** Creates the {@link RemoteCollectionItems} defined by this builder. */ /** Creates the {@link RemoteCollectionItems} defined by this builder. */ @NonNull @NonNull public RemoteCollectionItems build() { public RemoteCollectionItems build() { Loading @@ -9906,7 +9942,8 @@ public class RemoteViews implements Parcelable, Filter { mIds.toArray(), mIds.toArray(), mViews.toArray(new RemoteViews[0]), mViews.toArray(new RemoteViews[0]), mHasStableIds, mHasStableIds, Math.max(mViewTypeCount, 1)); Math.max(mViewTypeCount, 1), mHasLegacyNullItems); } } } } Loading
core/java/android/widget/RemoteViewsService.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -148,6 +148,10 @@ public abstract class RemoteViewsService extends Service { for (int i = 0; i < numOfEntries; i++) { for (int i = 0; i < numOfEntries; i++) { final long currentItemId = getItemId(i); final long currentItemId = getItemId(i); final RemoteViews currentView = getViewAt(i); final RemoteViews currentView = getViewAt(i); if (currentView == null) { itemsBuilder.setHasLegacyNullItems(true); break; } currentView.writeToParcel(capSizeTestParcel, 0); currentView.writeToParcel(capSizeTestParcel, 0); if (capSizeTestParcel.dataSize() > capSize) { if (capSizeTestParcel.dataSize() > capSize) { break; break; Loading