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

Commit 91485734 authored by Courtney Goeltzenleuchter's avatar Courtney Goeltzenleuchter Committed by Android (Google) Code Review
Browse files

Merge "Create ANGLE namespace in GraphicsEnvironment"

parents a7554382 73c05042
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class GraphicsEnvironment {
    private static final boolean DEBUG = false;
    private static final String TAG = "GraphicsEnvironment";
    private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0";
    private static final String ANGLE_PACKAGE_NAME = "com.android.angle";

    private ClassLoader mClassLoader;
    private String mLayerPath;
@@ -54,6 +55,7 @@ public class GraphicsEnvironment {
     */
    public void setup(Context context) {
        setupGpuLayers(context);
        setupAngle(context);
        chooseDriver(context);
    }

@@ -130,6 +132,52 @@ public class GraphicsEnvironment {
        setLayerPaths(mClassLoader, layerPaths);
    }

    /**
     * Selectively enable ANGLE for applications
     */
    private static void setupAngle(Context context) {

        String angleEnabledApp =
                Settings.Global.getString(context.getContentResolver(),
                                          Settings.Global.ANGLE_ENABLED_APP);

        String packageName = context.getPackageName();

        // Only provide an ANGLE namespace if the package name matches setting
        if ((angleEnabledApp != null && packageName != null)
                && (!angleEnabledApp.isEmpty() && !packageName.isEmpty())
                && angleEnabledApp.equals(packageName)) {

            if (DEBUG) Log.v(TAG, "ANGLE enabled for " + packageName);

            ApplicationInfo angleInfo;

            try {
                angleInfo = context.getPackageManager().getApplicationInfo(ANGLE_PACKAGE_NAME,
                    PackageManager.MATCH_SYSTEM_ONLY);
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "ANGLE package '" + ANGLE_PACKAGE_NAME + "' not installed");
                return;
            }

            String abi = chooseAbi(angleInfo);

            // Build a path that includes installed native libs and APK
            StringBuilder sb = new StringBuilder();
            sb.append(angleInfo.nativeLibraryDir)
                .append(File.pathSeparator)
                .append(angleInfo.sourceDir)
                .append("!/lib/")
                .append(abi);
            String paths = sb.toString();

            if (DEBUG) Log.v(TAG, "ANGLE package libs: " + paths);

            // Providing any path will trigger namespace creation
            setAnglePath(paths);
        }
    }

    /**
     * Choose whether the current process should use the builtin or an updated driver.
     */
@@ -218,4 +266,5 @@ public class GraphicsEnvironment {
    private static native void setLayerPaths(ClassLoader classLoader, String layerPaths);
    private static native void setDebugLayers(String layers);
    private static native void setDriverPath(String path);
    private static native void setAnglePath(String path);
}
+6 −0
Original line number Diff line number Diff line
@@ -11580,6 +11580,12 @@ public final class Settings {
         */
        public static final String GPU_DEBUG_APP = "gpu_debug_app";
        /**
         * App should try to use ANGLE
         * @hide
         */
        public static final String ANGLE_ENABLED_APP = "angle_enabled_app";
        /**
         * Ordered GPU debug layer list
         * i.e. <layer1>:<layer2>:...:<layerN>
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@ void setDriverPath(JNIEnv* env, jobject clazz, jstring path) {
    android::GraphicsEnv::getInstance().setDriverPath(pathChars.c_str());
}

void setAnglePath(JNIEnv* env, jobject clazz, jstring path) {
    ScopedUtfChars pathChars(env, path);
    android::GraphicsEnv::getInstance().setAnglePath(pathChars.c_str());
}

void setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) {
    android::NativeLoaderNamespace* appNamespace = android::FindNativeLoaderNamespaceByClassLoader(
        env, classLoader);
@@ -44,6 +49,7 @@ void setDebugLayers_native(JNIEnv* env, jobject clazz, jstring layers) {

const JNINativeMethod g_methods[] = {
    { "setDriverPath", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPath) },
    { "setAnglePath", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setAnglePath) },
    { "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) },
    { "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) },
};
+1 −0
Original line number Diff line number Diff line
@@ -447,6 +447,7 @@ public class SettingsBackupTest {
                    Settings.Global.ENABLE_GPU_DEBUG_LAYERS,
                    Settings.Global.GPU_DEBUG_APP,
                    Settings.Global.GPU_DEBUG_LAYERS,
                    Settings.Global.ANGLE_ENABLED_APP,
                    Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
                    Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
                    Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,