diff options
-rw-r--r-- | apct-tests/perftests/core/Android.bp | 23 | ||||
-rw-r--r-- | apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java | 26 |
2 files changed, 42 insertions, 7 deletions
diff --git a/apct-tests/perftests/core/Android.bp b/apct-tests/perftests/core/Android.bp index 92dbc263cb34..c5419637dec8 100644 --- a/apct-tests/perftests/core/Android.bp +++ b/apct-tests/perftests/core/Android.bp @@ -1,3 +1,19 @@ +// +// Copyright (C) 2020 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. +// + android_test { name: "CorePerfTests", @@ -23,17 +39,14 @@ android_test { libs: ["android.test.base"], + java_resources: [ ":GoogleFontDancingScript", ], + data: [":perfetto_artifacts"], platform_apis: true, jni_libs: ["libperftestscore_jni"], - // Use google-fonts/dancing-script for the performance metrics - // ANDROIDMK TRANSLATION ERROR: Only $(LOCAL_PATH)/.. values are allowed - // LOCAL_ASSET_DIR := $(TOP)/external/google-fonts/dancing-script - test_suites: ["device-tests"], certificate: "platform", - } diff --git a/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java b/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java index 884745699789..e83c64c37678 100644 --- a/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java +++ b/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java @@ -27,6 +27,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; +import com.android.internal.util.Preconditions; import com.android.perftests.core.R; import org.junit.Rule; @@ -73,10 +74,31 @@ public class TypefaceCreatePerfTest { final AssetManager am = context.getAssets(); while (state.keepRunning()) { - Typeface face = Typeface.createFromAsset(am, TEST_FONT_NAME); + Typeface face = createFromNonAsset(am, TEST_FONT_NAME); } } + /** + * {@link AssetManager#openNonAsset(String)} variant of + * {@link Typeface#createFromAsset(AssetManager, String)}. + */ + private static Typeface createFromNonAsset(AssetManager mgr, String path) { + Preconditions.checkNotNull(path); // for backward compatibility + Preconditions.checkNotNull(mgr); + + Typeface typeface = new Typeface.Builder(mgr, path).build(); + if (typeface != null) return typeface; + // check if the file exists, and throw an exception for backward compatibility + //noinspection EmptyTryBlock + try (InputStream inputStream = mgr.openNonAsset(path)) { + // Purposely empty + } catch (IOException e) { + throw new RuntimeException("Font asset not found " + path); + } + + return Typeface.DEFAULT; + } + @Test public void testCreate_fromFile() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); @@ -90,7 +112,7 @@ public class TypefaceCreatePerfTest { throw new RuntimeException(e); } - try (InputStream in = am.open(TEST_FONT_NAME); + try (InputStream in = am.openNonAsset(TEST_FONT_NAME); OutputStream out = new FileOutputStream(outFile)) { byte[] buf = new byte[1024]; int n = 0; |