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

Commit 73c05042 authored by Cody Northrop's avatar Cody Northrop Committed by Courtney Goeltzenleuchter
Browse files

Create ANGLE namespace in GraphicsEnvironment

This commit does the following:

* Create a new Android Setting for use during development,
  "angle_enabled_app", which can be used to load ANGLE
  only for specified applications.

  Usage:
    adb shell settings put global angle_enabled_app <package-name>

* When the package name condition is met, build a namespace
  that points to the ANGLE APK.  The namespace will be used
  by the EGL Loader to find ANGLE libs.

* The APK may be the pre-installed version in /system/app/ANGLE,
  or it may be an updated version from the Play Store, which will
  reside somewhere under /data/app/*.

Test: Manual

Change-Id: Ia0475cf80cf5c2589e52fdb3c8f3672696357923
parent 56c7a326
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,