From 2837eab16bc6d9188692613ad2f9d3a77d9d87a2 Mon Sep 17 00:00:00 2001 From: Pierre Barbier de Reuille Date: Wed, 7 Apr 2021 10:54:46 +0100 Subject: [PATCH] Replace RemoteViews#setViewId with a constructor This is a request of the API Council. There was a hidden and, AFAICT, un-used constructor with the same signature, which I have removed. Before replacing the constructor I checked the whole OS builds and run with the constructor simply removed. Fix: 182824754 Test: atest CtsWidgetTestCases:RemoteViewsRecyclingTest Test: atest CtsWidgetTestCases:RemoteViewsTest Change-Id: I0f12d2fa520cf4f0d54a7e3859337cc9a395ae66 --- core/api/current.txt | 2 +- core/java/android/widget/RemoteViews.java | 36 ++++++----------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 3d00bda551bc9..86e403ec7d86d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -55495,6 +55495,7 @@ package android.widget { public class RemoteViews implements android.view.LayoutInflater.Filter android.os.Parcelable { ctor public RemoteViews(String, int); + ctor public RemoteViews(@NonNull String, @LayoutRes int, @IdRes int); ctor public RemoteViews(android.widget.RemoteViews, android.widget.RemoteViews); ctor public RemoteViews(@NonNull java.util.Map); ctor public RemoteViews(android.widget.RemoteViews); @@ -55568,7 +55569,6 @@ package android.widget { method public void setTextViewText(@IdRes int, CharSequence); method public void setTextViewTextSize(@IdRes int, int, float); method public void setUri(@IdRes int, String, android.net.Uri); - method public void setViewId(@IdRes int); method public void setViewLayoutHeight(@IdRes int, float, int); method public void setViewLayoutHeightDimen(@IdRes int, @DimenRes int); method public void setViewLayoutMargin(@IdRes int, int, float, int); diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 29c78b54b64d0..f49aa741f9ab4 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -3263,16 +3263,14 @@ public class RemoteViews implements Parcelable, Filter { /** * Create a new RemoteViews object that will display the views contained - * in the specified layout file. + * in the specified layout file and change the id of the root view to the specified one. * - * @param packageName Name of the package that contains the layout resource. - * @param userId The user under which the package is running. - * @param layoutId The id of the layout resource. - * - * @hide + * @param packageName Name of the package that contains the layout resource + * @param layoutId The id of the layout resource */ - public RemoteViews(String packageName, int userId, @LayoutRes int layoutId) { - this(getApplicationInfo(packageName, userId), layoutId); + public RemoteViews(@NonNull String packageName, @LayoutRes int layoutId, @IdRes int viewId) { + this(packageName, layoutId); + this.mViewId = viewId; } /** @@ -3727,7 +3725,7 @@ public class RemoteViews implements Parcelable, Filter { * The {@code stableId} will be used to identify a potential view to recycled when the remote * view is inflated. Views can be re-used if inserted in the same order, potentially with * some views appearing / disappearing. To be recycled the view must not change the layout - * used to inflate it or its view id (see {@link RemoteViews#setViewId}). + * used to inflate it or its view id (see {@link RemoteViews#RemoteViews(String, int, int)}). * * Note: if a view is re-used, all the actions will be re-applied on it. However, its properties * are not reset, so what was applied in previous round will have an effect. As a view may be @@ -6340,25 +6338,9 @@ public class RemoteViews implements Parcelable, Filter { } /** - * Set the ID of the top-level view of the XML layout. - * - * The view's ID is changed right after inflation, before it gets added to its parent. The ID - * of a given view can never change after the initial inflation. - * - * Set to {@link View#NO_ID} to reset and simply keep the id defined in the XML layout. - * - * @throws UnsupportedOperationException if the method is called on a RemoteViews defined in - * term of other RemoteViews (e.g. {@link #RemoteViews(RemoteViews, RemoteViews)}). + * Get the ID of the top-level view of the XML layout, if set using + * {@link RemoteViews#RemoteViews(String, int, int)}. */ - public void setViewId(@IdRes int viewId) { - if (hasMultipleLayouts()) { - throw new UnsupportedOperationException( - "The viewId can only be set on RemoteViews defined from a XML layout."); - } - mViewId = viewId; - } - - /** Get the ID of the top-level view of the XML layout, as set by {@link #setViewId}. */ public @IdRes int getViewId() { return mViewId; }