summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Clara Bayarri <clarabayarri@google.com> 2017-04-07 17:56:30 +0100
committer Seigo Nonaka <nona@google.com> 2017-04-28 20:48:14 +0000
commitb7df9d0d6bd490c5db0085bc37ceafb9fd5b5e42 (patch)
tree0e0cc8191cab269b8e2979fcfa8ad78c971ce937
parentf49baef4b97b7745728486ac92aff4b53241d307 (diff)
Restricted Context layout font loading in TextView
When the context is restricted, avoid loading custom fonts in layouts. This is currently only done by TextView. Loading system fonts via their string name is still OK, just not by resource id. Test: cts attached in topic Bug: 35763094, 31218679 Change-Id: I0dc3a3eade0439c503c58a582b083d7ba1dd4aa3
-rw-r--r--core/java/android/widget/TextView.java33
1 files changed, 20 insertions, 13 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 492010c414fa..12a48a1913ac 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -913,10 +913,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
break;
case com.android.internal.R.styleable.TextAppearance_fontFamily:
- try {
- fontTypeface = appearance.getFont(attr);
- } catch (UnsupportedOperationException | Resources.NotFoundException e) {
- // Expected if it is not a font resource.
+ if (!context.isRestricted()) {
+ try {
+ fontTypeface = appearance.getFont(attr);
+ } catch (UnsupportedOperationException
+ | Resources.NotFoundException e) {
+ // Expected if it is not a font resource.
+ }
}
if (fontTypeface == null) {
fontFamily = appearance.getString(attr);
@@ -1230,11 +1233,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
break;
case com.android.internal.R.styleable.TextView_fontFamily:
- try {
- fontTypeface = a.getFont(attr);
- } catch (UnsupportedOperationException | Resources.NotFoundException e) {
- // Expected if it is not a resource reference or if it is a reference to
- // another resource type.
+ if (!context.isRestricted()) {
+ try {
+ fontTypeface = a.getFont(attr);
+ } catch (UnsupportedOperationException | Resources.NotFoundException e) {
+ // Expected if it is not a resource reference or if it is a reference to
+ // another resource type.
+ }
}
if (fontTypeface == null) {
fontFamily = a.getString(attr);
@@ -3381,10 +3386,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
Typeface fontTypeface = null;
String fontFamily = null;
- try {
- fontTypeface = ta.getFont(R.styleable.TextAppearance_fontFamily);
- } catch (UnsupportedOperationException | Resources.NotFoundException e) {
- // Expected if it is not a font resource.
+ if (!context.isRestricted()) {
+ try {
+ fontTypeface = ta.getFont(R.styleable.TextAppearance_fontFamily);
+ } catch (UnsupportedOperationException | Resources.NotFoundException e) {
+ // Expected if it is not a font resource.
+ }
}
if (fontTypeface == null) {
fontFamily = ta.getString(R.styleable.TextAppearance_fontFamily);