Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09dfdfe9 authored by Jeff DeCew's avatar Jeff DeCew Committed by Automerger Merge Worker
Browse files

Merge "Allow passing 0 to RemoteViews.setDimen() or setAttr()" into sc-dev am: 5e7b103e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14191410

Change-Id: I03667edb0e857f53501a5f9e2a87631cf253892b
parents bf229add 5e7b103e
Loading
Loading
Loading
Loading
+100 −50
Original line number Original line Diff line number Diff line
@@ -1905,31 +1905,49 @@ public class RemoteViews implements Parcelable, Filter {
        }
        }


        @Override
        @Override
        protected @NonNull Object getParameterValue(View view) throws ActionException {
        protected Object getParameterValue(View view) throws ActionException {
            Resources resources = view.getContext().getResources();
            Resources resources = view.getContext().getResources();
            try {
            try {
                switch (this.mResourceType) {
                switch (this.mResourceType) {
                    case DIMEN_RESOURCE:
                    case DIMEN_RESOURCE:
                        if (this.type == BaseReflectionAction.INT) {
                        switch (this.type) {
                            return resources.getDimensionPixelSize(this.mResId);
                            case BaseReflectionAction.INT:
                                return mResId == 0 ? 0 : resources.getDimensionPixelSize(mResId);
                            case BaseReflectionAction.FLOAT:
                                return mResId == 0 ? 0f : resources.getDimension(mResId);
                            default:
                                throw new ActionException(
                                        "dimen resources must be used as INT or FLOAT, "
                                                + "not " + this.type);
                        }
                        }
                        return resources.getDimension(this.mResId);
                    case COLOR_RESOURCE:
                    case COLOR_RESOURCE:
                        switch (this.type) {
                        switch (this.type) {
                            case BaseReflectionAction.INT:
                            case BaseReflectionAction.INT:
                                return view.getContext().getColor(this.mResId);
                                return mResId == 0 ? 0 : view.getContext().getColor(mResId);
                            case BaseReflectionAction.COLOR_STATE_LIST:
                            case BaseReflectionAction.COLOR_STATE_LIST:
                                return view.getContext().getColorStateList(this.mResId);
                                return mResId == 0
                                        ? null : view.getContext().getColorStateList(mResId);
                            default:
                            default:
                                throw new ActionException(
                                throw new ActionException(
                                        "color resources must be used as int or ColorStateList, "
                                        "color resources must be used as INT or COLOR_STATE_LIST,"
                                                + " not " + this.type);
                                                + " not " + this.type);
                        }
                        }
                    case STRING_RESOURCE:
                    case STRING_RESOURCE:
                        return resources.getText(this.mResId);
                        switch (this.type) {
                            case BaseReflectionAction.CHAR_SEQUENCE:
                                return mResId == 0 ? null : resources.getText(mResId);
                            case BaseReflectionAction.STRING:
                                return mResId == 0 ? null : resources.getString(mResId);
                            default:
                                throw new ActionException(
                                        "string resources must be used as STRING or CHAR_SEQUENCE,"
                                                + " not " + this.type);
                        }
                    default:
                    default:
                        throw new ActionException("unknown resource type: " + this.mResourceType);
                        throw new ActionException("unknown resource type: " + this.mResourceType);
                }
                }
            } catch (ActionException ex) {
                throw ex;
            } catch (Throwable t) {
            } catch (Throwable t) {
                throw new ActionException(t);
                throw new ActionException(t);
            }
            }
@@ -1971,21 +1989,27 @@ public class RemoteViews implements Parcelable, Filter {
        }
        }


        @Override
        @Override
        protected @NonNull Object getParameterValue(View view) throws ActionException {
        protected Object getParameterValue(View view) throws ActionException {
            try {
            TypedArray typedArray = view.getContext().obtainStyledAttributes(new int[]{mAttrId});
                TypedArray typedArray = view.getContext().obtainStyledAttributes(
                        new int[]{this.mAttrId});
            try {
            try {
                    if (typedArray.getType(0) == TypedValue.TYPE_NULL) {
                // When mAttrId == 0, we will depend on the default values below
                if (mAttrId != 0 && typedArray.getType(0) == TypedValue.TYPE_NULL) {
                    throw new ActionException("Attribute 0x" + Integer.toHexString(this.mAttrId)
                    throw new ActionException("Attribute 0x" + Integer.toHexString(this.mAttrId)
                            + " is not defined");
                            + " is not defined");
                }
                }
                switch (this.mResourceType) {
                switch (this.mResourceType) {
                    case DIMEN_RESOURCE:
                    case DIMEN_RESOURCE:
                            if (this.type == BaseReflectionAction.INT) {
                        switch (this.type) {
                            case BaseReflectionAction.INT:
                                return typedArray.getDimensionPixelSize(0, 0);
                                return typedArray.getDimensionPixelSize(0, 0);
                            }
                            case BaseReflectionAction.FLOAT:
                                return typedArray.getDimension(0, 0);
                                return typedArray.getDimension(0, 0);
                            default:
                                throw new ActionException(
                                        "dimen attribute 0x" + Integer.toHexString(this.mAttrId)
                                                + " must be used as INT or FLOAT,"
                                                + " not " + this.type);
                        }
                    case COLOR_RESOURCE:
                    case COLOR_RESOURCE:
                        switch (this.type) {
                        switch (this.type) {
                            case BaseReflectionAction.INT:
                            case BaseReflectionAction.INT:
@@ -1994,27 +2018,33 @@ public class RemoteViews implements Parcelable, Filter {
                                return typedArray.getColorStateList(0);
                                return typedArray.getColorStateList(0);
                            default:
                            default:
                                throw new ActionException(
                                throw new ActionException(
                                            "Color attribute 0x" + Integer.toHexString(this.mAttrId)
                                        "color attribute 0x" + Integer.toHexString(this.mAttrId)
                                                    + " must be used as int or ColorStateList");
                                                + " must be used as INT or COLOR_STATE_LIST,"
                                                + " not " + this.type);
                        }
                        }
                    case STRING_RESOURCE:
                    case STRING_RESOURCE:
                            String value = typedArray.getString(0);
                        switch (this.type) {
                            if (value == null) {
                            case BaseReflectionAction.CHAR_SEQUENCE:
                                throw new ActionException("Attribute 0x"
                                return typedArray.getText(0);
                                        + Integer.toHexString(this.mAttrId)
                            case BaseReflectionAction.STRING:
                                        + " is not a defined or is not a string");
                                return typedArray.getString(0);
                            default:
                                throw new ActionException(
                                        "string attribute 0x" + Integer.toHexString(this.mAttrId)
                                                + " must be used as STRING or CHAR_SEQUENCE,"
                                                + " not " + this.type);
                        }
                        }
                            return value;
                    default:
                    default:
                        // Note: This can only be an implementation error.
                        // Note: This can only be an implementation error.
                        throw new ActionException(
                        throw new ActionException(
                                "Unknown resource type: " + this.mResourceType);
                                "Unknown resource type: " + this.mResourceType);
                }
                }
                } finally {
            } catch (ActionException ex) {
                    typedArray.recycle();
                throw ex;
                }
            } catch (Throwable t) {
            } catch (Throwable t) {
                throw new ActionException(t);
                throw new ActionException(t);
            } finally {
                typedArray.recycle();
            }
            }
        }
        }


@@ -4519,7 +4549,7 @@ public class RemoteViews implements Parcelable, Filter {
     *
     *
     * @param viewId The id of the view to change
     * @param viewId The id of the view to change
     * @param type The margin being set e.g. {@link #MARGIN_END}
     * @param type The margin being set e.g. {@link #MARGIN_END}
     * @param attr a dimension attribute to apply to the margin.
     * @param attr a dimension attribute to apply to the margin, or 0 to clear the margin.
     */
     */
    public void setViewLayoutMarginAttr(@IdRes int viewId, @MarginType int type,
    public void setViewLayoutMarginAttr(@IdRes int viewId, @MarginType int type,
            @AttrRes int attr) {
            @AttrRes int attr) {
@@ -4702,6 +4732,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The dimension will be resolved from the resources at the time the {@link RemoteViews} is
     * The dimension will be resolved from the resources at the time the {@link RemoteViews} is
     * (re-)applied.
     * (re-)applied.
     *
     *
     * Undefined resources will result in an exception, except 0 which will resolve to 0.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param dimenResource The resource to resolve and pass as argument to the method.
     * @param dimenResource The resource to resolve and pass as argument to the method.
@@ -4736,6 +4768,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The dimension will be resolved from the theme attribute at the time the
     * The dimension will be resolved from the theme attribute at the time the
     * {@link RemoteViews} is (re-)applied.
     * {@link RemoteViews} is (re-)applied.
     *
     *
     * Unresolvable attributes will result in an exception, except 0 which will resolve to 0.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param dimenAttr The attribute to resolve and pass as argument to the method.
     * @param dimenAttr The attribute to resolve and pass as argument to the method.
@@ -4752,6 +4786,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The Color will be resolved from the resources at the time the {@link RemoteViews} is (re-)
     * The Color will be resolved from the resources at the time the {@link RemoteViews} is (re-)
     * applied.
     * applied.
     *
     *
     * Undefined resources will result in an exception, except 0 which will resolve to 0.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param colorResource The resource to resolve and pass as argument to the method.
     * @param colorResource The resource to resolve and pass as argument to the method.
@@ -4768,6 +4804,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The Color will be resolved from the theme attribute at the time the {@link RemoteViews} is
     * The Color will be resolved from the theme attribute at the time the {@link RemoteViews} is
     * (re-)applied.
     * (re-)applied.
     *
     *
     * Unresolvable attributes will result in an exception, except 0 which will resolve to 0.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param colorAttribute The theme attribute to resolve and pass as argument to the method.
     * @param colorAttribute The theme attribute to resolve and pass as argument to the method.
@@ -4846,6 +4884,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The ColorStateList will be resolved from the resources at the time the {@link RemoteViews} is
     * The ColorStateList will be resolved from the resources at the time the {@link RemoteViews} is
     * (re-)applied.
     * (re-)applied.
     *
     *
     * Undefined resources will result in an exception, except 0 which will resolve to null.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param colorResource The resource to resolve and pass as argument to the method.
     * @param colorResource The resource to resolve and pass as argument to the method.
@@ -4863,6 +4903,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The ColorStateList will be resolved from the theme attribute at the time the
     * The ColorStateList will be resolved from the theme attribute at the time the
     * {@link RemoteViews} is (re-)applied.
     * {@link RemoteViews} is (re-)applied.
     *
     *
     * Unresolvable attributes will result in an exception, except 0 which will resolve to null.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param colorAttr The theme attribute to resolve and pass as argument to the method.
     * @param colorAttr The theme attribute to resolve and pass as argument to the method.
@@ -4903,6 +4945,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The dimension will be resolved from the resources at the time the {@link RemoteViews} is
     * The dimension will be resolved from the resources at the time the {@link RemoteViews} is
     * (re-)applied.
     * (re-)applied.
     *
     *
     * Undefined resources will result in an exception, except 0 which will resolve to 0f.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param dimenResource The resource to resolve and pass as argument to the method.
     * @param dimenResource The resource to resolve and pass as argument to the method.
@@ -4939,6 +4983,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The dimension will be resolved from the theme attribute at the time the {@link RemoteViews}
     * The dimension will be resolved from the theme attribute at the time the {@link RemoteViews}
     * is (re-)applied.
     * is (re-)applied.
     *
     *
     * Unresolvable attributes will result in an exception, except 0 which will resolve to 0f.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param dimenAttr The attribute to resolve and pass as argument to the method.
     * @param dimenAttr The attribute to resolve and pass as argument to the method.
@@ -5000,6 +5046,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The CharSequence will be resolved from the resources at the time the {@link RemoteViews} is
     * The CharSequence will be resolved from the resources at the time the {@link RemoteViews} is
     * (re-)applied.
     * (re-)applied.
     *
     *
     * Undefined resources will result in an exception, except 0 which will resolve to null.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param stringResource The resource to resolve and pass as argument to the method.
     * @param stringResource The resource to resolve and pass as argument to the method.
@@ -5017,6 +5065,8 @@ public class RemoteViews implements Parcelable, Filter {
     * The CharSequence will be resolved from the theme attribute at the time the
     * The CharSequence will be resolved from the theme attribute at the time the
     * {@link RemoteViews} is (re-)applied.
     * {@link RemoteViews} is (re-)applied.
     *
     *
     * Unresolvable attributes will result in an exception, except 0 which will resolve to null.
     *
     * @param viewId The id of the view on which to call the method.
     * @param viewId The id of the view on which to call the method.
     * @param methodName The name of the method to call.
     * @param methodName The name of the method to call.
     * @param stringAttribute The attribute to resolve and pass as argument to the method.
     * @param stringAttribute The attribute to resolve and pass as argument to the method.