summaryrefslogtreecommitdiff
path: root/core/java/android/widget/RemoteViews.java
diff options
context:
space:
mode:
authorZhen Zhang <zzhen@google.com>2019-11-12 10:51:00 -0800
committerZhen Zhang <zzhen@google.com>2019-11-12 17:18:44 -0800
commit6e9e5faa9799a8715d80400928b97b452b269fb0 (patch)
tree38d6d44af00920b67906cb2c1a831536ee0e1239 /core/java/android/widget/RemoteViews.java
parente8ed32f81daa5a1e67e8b6fad9706c3699ddcf40 (diff)
Use static filter for inflater of RemoteViews
This will get rid of the RemoteViews leak caused by ViewStub keeping reference of LayoutInflater. But subclasses of RemoteViews won't be affected to avoid breaking overriden usage. Bug: 141699084 Test: Manually test. Leak disappeared. atest RemoteViewsTest Change-Id: I1b287a166df92e424208ae35eb84bfd6aa553ddf
Diffstat (limited to 'core/java/android/widget/RemoteViews.java')
-rw-r--r--core/java/android/widget/RemoteViews.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 86cec5e0f0a2..c571737cec8f 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -202,6 +202,14 @@ public class RemoteViews implements Parcelable, Filter {
public static final int FLAG_USE_LIGHT_BACKGROUND_LAYOUT = 4;
/**
+ * Used to restrict the views which can be inflated
+ *
+ * @see android.view.LayoutInflater.Filter#onLoadClass(java.lang.Class)
+ */
+ private static final LayoutInflater.Filter INFLATER_FILTER =
+ (clazz) -> clazz.isAnnotationPresent(RemoteViews.RemoteView.class);
+
+ /**
* Application that hosts the remote views.
*
* @hide
@@ -3413,13 +3421,24 @@ public class RemoteViews implements Parcelable, Filter {
// Clone inflater so we load resources from correct context and
// we don't add a filter to the static version returned by getSystemService.
inflater = inflater.cloneInContext(inflationContext);
- inflater.setFilter(this);
+ inflater.setFilter(shouldUseStaticFilter() ? INFLATER_FILTER : this);
View v = inflater.inflate(rv.getLayoutId(), parent, false);
v.setTagInternal(R.id.widget_frame, rv.getLayoutId());
return v;
}
/**
+ * A static filter is much lighter than RemoteViews itself. It's optimized here only for
+ * RemoteVies class. Subclasses should always override this and return true if not overriding
+ * {@link this#onLoadClass(Class)}.
+ *
+ * @hide
+ */
+ protected boolean shouldUseStaticFilter() {
+ return this.getClass().equals(RemoteViews.class);
+ }
+
+ /**
* Implement this interface to receive a callback when
* {@link #applyAsync} or {@link #reapplyAsync} is finished.
* @hide
@@ -3686,11 +3705,15 @@ public class RemoteViews implements Parcelable, Filter {
return (mActions == null) ? 0 : mActions.size();
}
- /* (non-Javadoc)
+ /**
* Used to restrict the views which can be inflated
*
* @see android.view.LayoutInflater.Filter#onLoadClass(java.lang.Class)
+ * @deprecated Used by system to enforce safe inflation of {@link RemoteViews}. Apps should not
+ * override this method. Changing of this method will NOT affect the process where RemoteViews
+ * is rendered.
*/
+ @Deprecated
public boolean onLoadClass(Class clazz) {
return clazz.isAnnotationPresent(RemoteView.class);
}