diff --git a/apct-tests/perftests/core/res/font/samplefont.ttf b/apct-tests/perftests/core/res/font/samplefont.ttf
new file mode 100644
index 0000000000000..b8302d4ea30f8
Binary files /dev/null and b/apct-tests/perftests/core/res/font/samplefont.ttf differ
diff --git a/apct-tests/perftests/core/res/font/samplefont_source.ttx b/apct-tests/perftests/core/res/font/samplefont_source.ttx
new file mode 100644
index 0000000000000..40fa268057725
--- /dev/null
+++ b/apct-tests/perftests/core/res/font/samplefont_source.ttx
@@ -0,0 +1,177 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Sample Font
+
+
+ Regular
+
+
+ Sample Font
+
+
+ SampleFont-Regular
+
+
+ Sample Font
+
+
+ Regular
+
+
+ Sample Font
+
+
+ SampleFont-Regular
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/apct-tests/perftests/core/res/font/samplexmlfont.xml b/apct-tests/perftests/core/res/font/samplexmlfont.xml
new file mode 100644
index 0000000000000..b226446c8e2ee
--- /dev/null
+++ b/apct-tests/perftests/core/res/font/samplexmlfont.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
diff --git a/apct-tests/perftests/core/res/layout/test_textview_font_family_file.xml b/apct-tests/perftests/core/res/layout/test_textview_font_family_file.xml
new file mode 100644
index 0000000000000..3689a640a77af
--- /dev/null
+++ b/apct-tests/perftests/core/res/layout/test_textview_font_family_file.xml
@@ -0,0 +1,20 @@
+
+
diff --git a/apct-tests/perftests/core/res/layout/test_textview_font_family_string.xml b/apct-tests/perftests/core/res/layout/test_textview_font_family_string.xml
new file mode 100644
index 0000000000000..5f236f5598261
--- /dev/null
+++ b/apct-tests/perftests/core/res/layout/test_textview_font_family_string.xml
@@ -0,0 +1,20 @@
+
+
diff --git a/apct-tests/perftests/core/res/layout/test_textview_font_family_xml.xml b/apct-tests/perftests/core/res/layout/test_textview_font_family_xml.xml
new file mode 100644
index 0000000000000..0331fa5799222
--- /dev/null
+++ b/apct-tests/perftests/core/res/layout/test_textview_font_family_xml.xml
@@ -0,0 +1,20 @@
+
+
diff --git a/apct-tests/perftests/core/res/values/strings.xml b/apct-tests/perftests/core/res/values/strings.xml
index 5d1f6f01dcb1e..7ab325f79dc76 100644
--- a/apct-tests/perftests/core/res/values/strings.xml
+++ b/apct-tests/perftests/core/res/values/strings.xml
@@ -28,4 +28,5 @@
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text
+ text text
diff --git a/apct-tests/perftests/core/src/android/widget/TextViewFontFamilyLayoutPerfTest.java b/apct-tests/perftests/core/src/android/widget/TextViewFontFamilyLayoutPerfTest.java
new file mode 100644
index 0000000000000..4b6da6ba345a4
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/widget/TextViewFontFamilyLayoutPerfTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package android.widget;
+
+import android.content.Context;
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.LargeTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.view.LayoutInflater;
+
+import com.android.perftests.core.R;
+
+import java.util.Collection;
+import java.util.Arrays;
+
+import org.junit.Test;
+import org.junit.Rule;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertTrue;
+
+@LargeTest
+@RunWith(Parameterized.class)
+public class TextViewFontFamilyLayoutPerfTest {
+ @Parameters(name = "{0}")
+ public static Collection layouts() {
+ return Arrays.asList(new Object[][] {
+ { "String fontFamily attribute", R.layout.test_textview_font_family_string},
+ { "File fontFamily attribute", R.layout.test_textview_font_family_file},
+ { "XML fontFamily attribute", R.layout.test_textview_font_family_xml},
+ });
+ }
+
+ private int mLayoutId;
+
+ public TextViewFontFamilyLayoutPerfTest(String key, int layoutId) {
+ mLayoutId = layoutId;
+ }
+
+ @Rule
+ public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Test
+ public void testConstruction() throws Throwable {
+ final Context context = InstrumentationRegistry.getTargetContext();
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ final LayoutInflater inflator =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ while (state.keepRunning()) {
+ inflator.inflate(mLayoutId, null, false);
+ }
+ }
+}
diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java
index bdfef8326fdf4..b3adf82c75a43 100644
--- a/core/java/android/content/res/ResourcesImpl.java
+++ b/core/java/android/content/res/ResourcesImpl.java
@@ -772,6 +772,10 @@ public class ResourcesImpl {
}
final String file = value.string.toString();
+ if (!file.startsWith("res/")) {
+ return null;
+ }
+
Typeface cached = Typeface.findFromCache(mAssets, file);
if (cached != null) {
return cached;