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

Commit 4b5a4d22 authored by Clara Bayarri's avatar Clara Bayarri
Browse files

Declarative downloadable fonts

Implement support for downloadable font requests in xml. Given the
xml fonts feature in O, this adds support to not only declare
local font files as font resources, but also Downloadable fonts
from a fonts provider.

A provider returns a font family (of one or more files) given a
query, so the new attributes are added to the font-family tag.

Additionally, add support to pre-declare downloadable font resources
in the Android Manifest. These will then be fetched at app startup
time so they are available to use from the Typeface cache asap.

When retrieving downloadable fonts via resources, the cache is
checked to see if the font is already there and is used, otherwise
a request is sent to the provider and the default font is returned
as we need a result synchronously.

To do this, the developer declares an additional fonts xml resource
file with the list of fonts to preload and links it in the manifest
with a meta-data tag.

E.g.:

res/font/mydownloadedfont.xml

<font-family xmlns:android="http://schemas.android.com/apk/res/android"
        android:fontProviderAuthority="com.example.test.fontprovider"
        android:fontProviderQuery="myrequestedfont">
</font-family>

res/font/preloaded_fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font android:font="@font/mydownloadedfont" />
</font-family>

and in the AndroidManifest.xml

<meta-data android:name="preloaded_fonts"
    android:resource="@font/preloaded_fonts" />

Bug: 34660500, 34658116
Test: WIP, need to add more
Change-Id: I1d92555e115e241bf23b59e6f5c6cca6c7361de7
parent 0bb70091
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -601,6 +601,8 @@ package android {
    field public static final int font = 16844082; // 0x1010532
    field public static final int fontFamily = 16843692; // 0x10103ac
    field public static final int fontFeatureSettings = 16843959; // 0x10104b7
    field public static final int fontProviderAuthority = 16844114; // 0x1010552
    field public static final int fontProviderQuery = 16844115; // 0x1010553
    field public static final int fontStyle = 16844081; // 0x1010531
    field public static final int fontWeight = 16844083; // 0x1010533
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
+2 −0
Original line number Diff line number Diff line
@@ -713,6 +713,8 @@ package android {
    field public static final int font = 16844082; // 0x1010532
    field public static final int fontFamily = 16843692; // 0x10103ac
    field public static final int fontFeatureSettings = 16843959; // 0x10104b7
    field public static final int fontProviderAuthority = 16844114; // 0x1010552
    field public static final int fontProviderQuery = 16844115; // 0x1010553
    field public static final int fontStyle = 16844081; // 0x1010531
    field public static final int fontWeight = 16844083; // 0x1010533
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
+2 −0
Original line number Diff line number Diff line
@@ -601,6 +601,8 @@ package android {
    field public static final int font = 16844082; // 0x1010532
    field public static final int fontFamily = 16843692; // 0x10103ac
    field public static final int fontFeatureSettings = 16843959; // 0x10104b7
    field public static final int fontProviderAuthority = 16844114; // 0x1010552
    field public static final int fontProviderQuery = 16844115; // 0x1010553
    field public static final int fontStyle = 16844081; // 0x1010531
    field public static final int fontWeight = 16844083; // 0x1010533
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
+18 −0
Original line number Diff line number Diff line
@@ -5587,6 +5587,24 @@ public final class ActivityThread {
        } finally {
            StrictMode.setThreadPolicy(savedPolicy);
        }

        // Preload fonts resources
        try {
            final ApplicationInfo info =
                    sPackageManager.getApplicationInfo(
                            data.appInfo.packageName,
                            PackageManager.GET_META_DATA /*flags*/,
                            UserHandle.myUserId());
            if (info.metaData != null) {
                final int preloadedFontsResource = info.metaData.getInt(
                        ApplicationInfo.METADATA_PRELOADED_FONTS, 0);
                if (preloadedFontsResource != 0) {
                    data.info.mResources.preloadFonts(preloadedFontsResource);
                }
            }
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /*package*/ final void finishInstrumentation(int resultCode, Bundle results) {
+5 −0
Original line number Diff line number Diff line
@@ -572,6 +572,11 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public int privateFlags;

    /**
     * @hide
     */
    public static final String METADATA_PRELOADED_FONTS = "preloaded_fonts";

    /**
     * The required smallest screen width the application can run on.  If 0,
     * nothing has been specified.  Comes from
Loading