diff options
| author | Alan Viverette <alanv@google.com> | 2014-06-27 16:10:54 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2014-06-27 23:11:55 +0000 |
| commit | abda54808800512891c2d8e2f6048b0fee568c83 (patch) | |
| tree | 761baf93a61ae1d063d818475f56863abc7e941f /core/java/android/widget/TextView.java | |
| parent | d4e3cdde83deb7ef27ac6836158abc589ba22dba (diff) | |
Fix unsafe public methods that take TypedArray
BUG: 15782973
Change-Id: Ifeb032976cd20cf25fe7ecea83eab9d71a16ebc3
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index d470586d6e99..8567bedd7322 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -7992,43 +7992,39 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Returns the TextView_textColor attribute from the - * TypedArray, if set, or the TextAppearance_textColor - * from the TextView_textAppearance attribute, if TextView_textColor - * was not set directly. + * Returns the TextView_textColor attribute from the TypedArray, if set, or + * the TextAppearance_textColor from the TextView_textAppearance attribute, + * if TextView_textColor was not set directly. */ public static ColorStateList getTextColors(Context context, TypedArray attrs) { - ColorStateList colors; - colors = attrs.getColorStateList(com.android.internal.R.styleable. - TextView_textColor); - + // It's not safe to use this method from apps. The parameter 'attrs' + // must have been obtained using the TextView filter array which is not + // available to the SDK. As such, we grab a default TypedArray with the + // right filter instead here. + final TypedArray a = context.obtainStyledAttributes(R.styleable.TextView); + ColorStateList colors = a.getColorStateList(R.styleable.TextView_textColor); if (colors == null) { - int ap = attrs.getResourceId(com.android.internal.R.styleable. - TextView_textAppearance, -1); - if (ap != -1) { - TypedArray appearance; - appearance = context.obtainStyledAttributes(ap, - com.android.internal.R.styleable.TextAppearance); - colors = appearance.getColorStateList(com.android.internal.R.styleable. - TextAppearance_textColor); + final int ap = a.getResourceId(R.styleable.TextView_textAppearance, 0); + if (ap != 0) { + final TypedArray appearance = context.obtainStyledAttributes( + ap, R.styleable.TextAppearance); + colors = appearance.getColorStateList(R.styleable.TextAppearance_textColor); appearance.recycle(); } } + a.recycle(); return colors; } /** - * Returns the default color from the TextView_textColor attribute - * from the AttributeSet, if set, or the default color from the - * TextAppearance_textColor from the TextView_textAppearance attribute, - * if TextView_textColor was not set directly. + * Returns the default color from the TextView_textColor attribute from the + * AttributeSet, if set, or the default color from the + * TextAppearance_textColor from the TextView_textAppearance attribute, if + * TextView_textColor was not set directly. */ - public static int getTextColor(Context context, - TypedArray attrs, - int def) { - ColorStateList colors = getTextColors(context, attrs); - + public static int getTextColor(Context context, TypedArray attrs, int def) { + final ColorStateList colors = getTextColors(context, attrs); if (colors == null) { return def; } else { |
