Merge "System font check for downloadable font" into sc-dev am: 05921e00c8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13429547 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ib5f120ba14ec3019e12090ce0f89fa922f34fc51
This commit is contained in:
@@ -657,6 +657,7 @@ package android {
|
|||||||
field @Deprecated public static final int fontProviderCerts = 16844125; // 0x101055d
|
field @Deprecated public static final int fontProviderCerts = 16844125; // 0x101055d
|
||||||
field @Deprecated public static final int fontProviderPackage = 16844119; // 0x1010557
|
field @Deprecated public static final int fontProviderPackage = 16844119; // 0x1010557
|
||||||
field @Deprecated public static final int fontProviderQuery = 16844113; // 0x1010551
|
field @Deprecated public static final int fontProviderQuery = 16844113; // 0x1010551
|
||||||
|
field public static final int fontProviderSystemFontFamily = 16844322; // 0x1010622
|
||||||
field public static final int fontStyle = 16844095; // 0x101053f
|
field public static final int fontStyle = 16844095; // 0x101053f
|
||||||
field public static final int fontVariationSettings = 16844144; // 0x1010570
|
field public static final int fontVariationSettings = 16844144; // 0x1010570
|
||||||
field public static final int fontWeight = 16844083; // 0x1010533
|
field public static final int fontWeight = 16844083; // 0x1010533
|
||||||
|
|||||||
@@ -47,14 +47,17 @@ public class FontResourcesParser {
|
|||||||
private final @NonNull String mProviderAuthority;
|
private final @NonNull String mProviderAuthority;
|
||||||
private final @NonNull String mProviderPackage;
|
private final @NonNull String mProviderPackage;
|
||||||
private final @NonNull String mQuery;
|
private final @NonNull String mQuery;
|
||||||
|
private final @Nullable String mSystemFontFamilyName;
|
||||||
private final @Nullable List<List<String>> mCerts;
|
private final @Nullable List<List<String>> mCerts;
|
||||||
|
|
||||||
public ProviderResourceEntry(@NonNull String authority, @NonNull String pkg,
|
public ProviderResourceEntry(@NonNull String authority, @NonNull String pkg,
|
||||||
@NonNull String query, @Nullable List<List<String>> certs) {
|
@NonNull String query, @Nullable List<List<String>> certs,
|
||||||
|
@Nullable String systemFontFamilyName) {
|
||||||
mProviderAuthority = authority;
|
mProviderAuthority = authority;
|
||||||
mProviderPackage = pkg;
|
mProviderPackage = pkg;
|
||||||
mQuery = query;
|
mQuery = query;
|
||||||
mCerts = certs;
|
mCerts = certs;
|
||||||
|
mSystemFontFamilyName = systemFontFamilyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull String getAuthority() {
|
public @NonNull String getAuthority() {
|
||||||
@@ -69,6 +72,10 @@ public class FontResourcesParser {
|
|||||||
return mQuery;
|
return mQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull String getSystemFontFamilyName() {
|
||||||
|
return mSystemFontFamilyName;
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable List<List<String>> getCerts() {
|
public @Nullable List<List<String>> getCerts() {
|
||||||
return mCerts;
|
return mCerts;
|
||||||
}
|
}
|
||||||
@@ -166,6 +173,8 @@ public class FontResourcesParser {
|
|||||||
String providerPackage = array.getString(R.styleable.FontFamily_fontProviderPackage);
|
String providerPackage = array.getString(R.styleable.FontFamily_fontProviderPackage);
|
||||||
String query = array.getString(R.styleable.FontFamily_fontProviderQuery);
|
String query = array.getString(R.styleable.FontFamily_fontProviderQuery);
|
||||||
int certsId = array.getResourceId(R.styleable.FontFamily_fontProviderCerts, 0);
|
int certsId = array.getResourceId(R.styleable.FontFamily_fontProviderCerts, 0);
|
||||||
|
String systemFontFamilyName = array.getString(
|
||||||
|
R.styleable.FontFamily_fontProviderSystemFontFamily);
|
||||||
array.recycle();
|
array.recycle();
|
||||||
if (authority != null && providerPackage != null && query != null) {
|
if (authority != null && providerPackage != null && query != null) {
|
||||||
while (parser.next() != XmlPullParser.END_TAG) {
|
while (parser.next() != XmlPullParser.END_TAG) {
|
||||||
@@ -191,7 +200,13 @@ public class FontResourcesParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ProviderResourceEntry(authority, providerPackage, query, certs);
|
return new ProviderResourceEntry(
|
||||||
|
authority,
|
||||||
|
providerPackage,
|
||||||
|
query,
|
||||||
|
certs,
|
||||||
|
systemFontFamilyName
|
||||||
|
);
|
||||||
}
|
}
|
||||||
List<FontFileResourceEntry> fonts = new ArrayList<>();
|
List<FontFileResourceEntry> fonts = new ArrayList<>();
|
||||||
while (parser.next() != XmlPullParser.END_TAG) {
|
while (parser.next() != XmlPullParser.END_TAG) {
|
||||||
|
|||||||
@@ -9276,6 +9276,12 @@
|
|||||||
{@deprecated Use app:fontProviderCerts with Jetpack Core library instead.}
|
{@deprecated Use app:fontProviderCerts with Jetpack Core library instead.}
|
||||||
-->
|
-->
|
||||||
<attr name="fontProviderCerts" format="reference" />
|
<attr name="fontProviderCerts" format="reference" />
|
||||||
|
<!-- Provides the system font family name to check before downloading the font. For example
|
||||||
|
if the fontProviderQuery asked for "Sans Serif", it is possible to define
|
||||||
|
fontProviderSystemFontFamily as "sans-serif" to tell the system to use "sans-serif" font
|
||||||
|
family if it exists on the system.
|
||||||
|
-->
|
||||||
|
<attr name="fontProviderSystemFontFamily" format="string" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<!-- Attributes that are read when parsing a tag. -->
|
<!-- Attributes that are read when parsing a tag. -->
|
||||||
|
|||||||
@@ -3058,6 +3058,7 @@
|
|||||||
<public name="sspSuffix" />
|
<public name="sspSuffix" />
|
||||||
<public name="pathAdvancedPattern" />
|
<public name="pathAdvancedPattern" />
|
||||||
<public name="sspAdvancedPattern" />
|
<public name="sspAdvancedPattern" />
|
||||||
|
<public name="fontProviderSystemFontFamily" />
|
||||||
</public-group>
|
</public-group>
|
||||||
|
|
||||||
<public-group type="drawable" first-id="0x010800b5">
|
<public-group type="drawable" first-id="0x010800b5">
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
|
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:fontProviderAuthority="com.example.test.fontprovider.authority"
|
android:fontProviderAuthority="com.example.test.fontprovider.authority"
|
||||||
android:fontProviderPackage="com.example.test.fontprovider.package"
|
android:fontProviderPackage="com.example.test.fontprovider.package"
|
||||||
android:fontProviderQuery="MyRequestedFont">
|
android:fontProviderQuery="MyRequestedFont"
|
||||||
|
android:fontProviderSystemFontFamily="my-request-font">
|
||||||
</font-family>
|
</font-family>
|
||||||
@@ -105,6 +105,7 @@ public class FontResourcesParserTest {
|
|||||||
assertEquals("com.example.test.fontprovider.authority", providerEntry.getAuthority());
|
assertEquals("com.example.test.fontprovider.authority", providerEntry.getAuthority());
|
||||||
assertEquals("com.example.test.fontprovider.package", providerEntry.getPackage());
|
assertEquals("com.example.test.fontprovider.package", providerEntry.getPackage());
|
||||||
assertEquals("MyRequestedFont", providerEntry.getQuery());
|
assertEquals("MyRequestedFont", providerEntry.getQuery());
|
||||||
|
assertEquals("my-request-font", providerEntry.getSystemFontFamilyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Typeface class specifies the typeface and intrinsic style of a font.
|
* The Typeface class specifies the typeface and intrinsic style of a font.
|
||||||
@@ -248,6 +249,21 @@ public class Typeface {
|
|||||||
return (mStyle & ITALIC) != 0;
|
return (mStyle & ITALIC) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the system has the font family with the name [familyName]. For example
|
||||||
|
* querying with "sans-serif" would check if the "sans-serif" family is defined in the system
|
||||||
|
* and return true if does.
|
||||||
|
*
|
||||||
|
* @param familyName The name of the font family, cannot be null. If null, exception will be
|
||||||
|
* thrown.
|
||||||
|
*/
|
||||||
|
private static boolean hasFontFamily(@NonNull String familyName) {
|
||||||
|
Objects.requireNonNull(familyName, "familyName cannot be null");
|
||||||
|
synchronized (SYSTEM_FONT_MAP_LOCK) {
|
||||||
|
return sSystemFontMap.containsKey(familyName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
* Used by Resources to load a font resource of type xml.
|
* Used by Resources to load a font resource of type xml.
|
||||||
@@ -257,6 +273,11 @@ public class Typeface {
|
|||||||
FamilyResourceEntry entry, AssetManager mgr, String path) {
|
FamilyResourceEntry entry, AssetManager mgr, String path) {
|
||||||
if (entry instanceof ProviderResourceEntry) {
|
if (entry instanceof ProviderResourceEntry) {
|
||||||
final ProviderResourceEntry providerEntry = (ProviderResourceEntry) entry;
|
final ProviderResourceEntry providerEntry = (ProviderResourceEntry) entry;
|
||||||
|
|
||||||
|
String systemFontFamilyName = providerEntry.getSystemFontFamilyName();
|
||||||
|
if (systemFontFamilyName != null && hasFontFamily(systemFontFamilyName)) {
|
||||||
|
return Typeface.create(systemFontFamilyName, NORMAL);
|
||||||
|
}
|
||||||
// Downloadable font
|
// Downloadable font
|
||||||
List<List<String>> givenCerts = providerEntry.getCerts();
|
List<List<String>> givenCerts = providerEntry.getCerts();
|
||||||
List<List<byte[]>> certs = new ArrayList<>();
|
List<List<byte[]>> certs = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user