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

Commit b7df9d0d authored by Clara Bayarri's avatar Clara Bayarri Committed by Seigo Nonaka
Browse files

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
parent f49baef4
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -913,11 +913,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        break;

                    case com.android.internal.R.styleable.TextAppearance_fontFamily:
                        if (!context.isRestricted()) {
                            try {
                                fontTypeface = appearance.getFont(attr);
                        } catch (UnsupportedOperationException | Resources.NotFoundException e) {
                            } catch (UnsupportedOperationException
                                    | Resources.NotFoundException e) {
                                // Expected if it is not a font resource.
                            }
                        }
                        if (fontTypeface == null) {
                            fontFamily = appearance.getString(attr);
                        }
@@ -1230,12 +1233,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    break;

                case com.android.internal.R.styleable.TextView_fontFamily:
                    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,11 +3386,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

        Typeface fontTypeface = null;
        String fontFamily = null;
        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);
        }