From 8011a28559c3974d075ac2533a67a8eeba9b42bf Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Mon, 1 Nov 2021 10:22:11 +0000 Subject: [PATCH] Always check if the view can be recycled. Previously, the recycling was only checked for multiple layout, as it was assumed the AppWidgetHostView would make the basic check. However, adapters views (e.g. ListView, ...) do not make any recycling check, instead relying on caching using the Layout id. The caching cannot be changed as it is common to other parts of Android. This CL ensures the view can be recycled when reapplied, always. Bug: 181985606 Test: atest android.widget.cts.RemoteViewsRecyclingTest Change-Id: Ib01c511e4a793cce1519157aea06e194a2d8f855 --- core/java/android/widget/RemoteViews.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 2357d13c8d41d..57b7d618917da 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -5746,11 +5746,9 @@ public class RemoteViews implements Parcelable, Filter { // persisted across change, and has the RemoteViews re-applied in a different situation // (orientation or size), we throw an exception, since the layouts may be completely // unrelated. - if (hasMultipleLayouts()) { - if (!rvToApply.canRecycleView(v)) { - throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" + - " that does not share the same root layout id."); - } + if (!rvToApply.canRecycleView(v)) { + throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" + + " that does not share the same root layout id."); } rvToApply.performApply(v, (ViewGroup) v.getParent(), handler, colorResources); @@ -5794,11 +5792,9 @@ public class RemoteViews implements Parcelable, Filter { // In the case that a view has this RemoteViews applied in one orientation, is persisted // across orientation change, and has the RemoteViews re-applied in the new orientation, // we throw an exception, since the layouts may be completely unrelated. - if (hasMultipleLayouts()) { - if (!rvToApply.canRecycleView(v)) { - throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" + - " that does not share the same root layout id."); - } + if (!rvToApply.canRecycleView(v)) { + throw new RuntimeException("Attempting to re-apply RemoteViews to a view that" + + " that does not share the same root layout id."); } return new AsyncApplyTask(rvToApply, (ViewGroup) v.getParent(),