Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 987c7a95 authored by Eric Holk's avatar Eric Holk
Browse files

[layout compilation] Disable precompiled layouts when preferCodeIntegrity is set

This feature involves generating and loading code on the
application. Applications may use the preferCodeIntegrity flag to indicate they
do not want this behavior, so we need to respect this preference. We also
disable loading precompiled layouts for privapps.

Bug: 111895153
Change-Id: I5c563e9f6eb7dd5eb7aac7df3838888f71b38866
parent 51d41479
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.SystemService;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -398,10 +399,23 @@ public abstract class LayoutInflater {
    }

    private void initPrecompiledViews() {
        try {
        // Check if precompiled layouts are enabled by a system property.
        mUseCompiledView =
            SystemProperties.getBoolean(USE_PRECOMPILED_LAYOUT_SYSTEM_PROPERTY, false);
            if (mUseCompiledView) {
        if (!mUseCompiledView) {
            return;
        }

        // Make sure the application allows code generation
        ApplicationInfo appInfo = mContext.getApplicationInfo();
        if ((appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PREFER_CODE_INTEGRITY) != 0
            || appInfo.isPrivilegedApp()) {
            mUseCompiledView = false;
            return;
        }

        // Try to load the precompiled layout file.
        try {
            mPrecompiledClassLoader = mContext.getClassLoader();
            String dexFile = mContext.getCodeCacheDir() + COMPILED_VIEW_DEX_FILE_NAME;
            if (new File(dexFile).exists()) {
@@ -411,7 +425,6 @@ public abstract class LayoutInflater {
                // layouts.
                mUseCompiledView = false;
            }
            }
        } catch (Throwable e) {
            if (DEBUG) {
                Log.e(TAG, "Failed to initialized precompiled views layouts", e);