diff options
| author | 2019-01-18 11:49:55 -0800 | |
|---|---|---|
| committer | 2019-01-30 16:19:29 +0000 | |
| commit | 3b95621e12247337e831855becf8fe8e0e98c8d5 (patch) | |
| tree | bb776a6ff303a553c5c29838802f7f01b94df923 | |
| parent | 34b11c92b34c8244c47fc2c1f9d8eb733b884004 (diff) | |
[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
Merged-In: Ib6b62d79a9ca7aefefff8639752aa5838e491038
Change-Id: I2f28f6912499825e52c17cc163be9c0fe93855cb
| -rw-r--r-- | api/test-current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/view/LayoutInflater.java | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index af455fb4abb6..30c6fdf55cbe 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -1790,6 +1790,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 f2259b045c0a..2ee72bffc9ec 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.res.Resources; @@ -389,9 +390,13 @@ public abstract class LayoutInflater { } private void initPrecompiledViews() { + initPrecompiledViews( + SystemProperties.getBoolean(USE_PRECOMPILED_LAYOUT_SYSTEM_PROPERTY, false)); + } + + private void initPrecompiledViews(boolean enablePrecompiledViews) { + mUseCompiledView = enablePrecompiledViews; try { - mUseCompiledView = - SystemProperties.getBoolean(USE_PRECOMPILED_LAYOUT_SYSTEM_PROPERTY, false); if (mUseCompiledView) { mPrecompiledClassLoader = mContext.getClassLoader(); String dexFile = mContext.getCodeCacheDir() + COMPILED_VIEW_DEX_FILE_NAME; @@ -409,6 +414,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); } /** |