From 25aa4edaa81810747929c871f9ab69fd3d176f7f Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 18 Jan 2019 11:49:55 -0800 Subject: [PATCH] [layout precompilation] Add testing hook for precompiled layouts We want to be able to control at a fine grained level whether precompiled layouts are enabled so we can compare inflation results with and without. This changes adds a @TestApi method that supports this. Bug: 111895153 Change-Id: Ib6b62d79a9ca7aefefff8639752aa5838e491038 --- api/test-current.txt | 4 ++++ core/java/android/view/LayoutInflater.java | 23 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/api/test-current.txt b/api/test-current.txt index 01faa23606881..660756ac8274e 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -2366,6 +2366,10 @@ package android.view { method public boolean isSystemGroup(); } + public abstract class LayoutInflater { + method public void setPrecompiledLayoutsEnabledForTesting(boolean); + } + public final class MotionEvent extends android.view.InputEvent implements android.os.Parcelable { method public void setActionButton(int); method public void setButtonState(int); diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java index dc7c343c2c3e5..6061cb2963eb5 100644 --- a/core/java/android/view/LayoutInflater.java +++ b/core/java/android/view/LayoutInflater.java @@ -20,6 +20,7 @@ import android.annotation.LayoutRes; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemService; +import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -399,10 +400,15 @@ public abstract class LayoutInflater { } private void initPrecompiledViews() { - // Check if precompiled layouts are enabled by a system property. - mUseCompiledView = - SystemProperties.getBoolean(USE_PRECOMPILED_LAYOUT_SYSTEM_PROPERTY, false); + initPrecompiledViews( + SystemProperties.getBoolean(USE_PRECOMPILED_LAYOUT_SYSTEM_PROPERTY, false)); + } + + private void initPrecompiledViews(boolean enablePrecompiledViews) { + mUseCompiledView = enablePrecompiledViews; + if (!mUseCompiledView) { + mPrecompiledClassLoader = null; return; } @@ -431,6 +437,17 @@ public abstract class LayoutInflater { } mUseCompiledView = false; } + if (!mUseCompiledView) { + mPrecompiledClassLoader = null; + } + } + + /** + * @hide for use by CTS tests + */ + @TestApi + public void setPrecompiledLayoutsEnabledForTesting(boolean enablePrecompiledLayouts) { + initPrecompiledViews(enablePrecompiledLayouts); } /**