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

Commit 097a3062 authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

GraphicsEnv: refactor to unify the debuggable logic

By default, PR_SET_DUMPABLE is 0 for zygote spawned apps, except in the
following circumstances:
1. ro.debuggable=1 (global debuggable enabled, i.e., userdebug or eng builds).
2. android:debuggable="true" in the manifest for an individual application.
3. An app which explicitly calls prctl(PR_SET_DUMPABLE, 1).
4. GraphicsEnv calls prctl(PR_SET_DUMPABLE, 1) in the presence of
   <meta-data android:name="com.android.graphics.injectLayers.enable"
              android:value="true"/>
   in the application manifest.

So checking both ro.debuggable=1 and PR_GET_DUMPABLE is redundant.

Bug: 144186877
Test: CtsAngleIntegrationHostTestCases
Test: CtsRootlessGpuDebugHostTest
Change-Id: Ica49254df2c7c090808411935cdeb8efd4e3cb51
parent 5a234006
Loading
Loading
Loading
Loading
+6 −19
Original line number Diff line number Diff line
@@ -176,13 +176,6 @@ public class GraphicsEnvironment {
        return 0;
    }

    /**
     * Check whether application is debuggable
     */
    private static boolean isDebuggable(Context context) {
        return (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) > 0;
    }

    /**
     * Check whether application is has set the manifest metadata for layer injection.
     */
@@ -246,7 +239,7 @@ public class GraphicsEnvironment {
        // 2. ENABLE_GPU_DEBUG_LAYERS is true
        // 3. Package name is equal to GPU_DEBUG_APP

        if (isDebuggable(context) || (getCanLoadSystemLibraries() == 1) || canInjectLayers(ai)) {
        if (isDebuggable() || canInjectLayers(ai)) {

            final int enable = coreSettings.getInt(Settings.Global.ENABLE_GPU_DEBUG_LAYERS, 0);

@@ -441,9 +434,7 @@ public class GraphicsEnvironment {
     * Check for ANGLE debug package, but only for apps that can load them (dumpable)
     */
    private String getAngleDebugPackage(Context context, Bundle coreSettings) {
        final boolean appIsDebuggable = isDebuggable(context);
        final boolean deviceIsDebuggable = getCanLoadSystemLibraries() == 1;
        if (appIsDebuggable || deviceIsDebuggable) {
        if (isDebuggable()) {
            String debugPackage;

            if (coreSettings != null) {
@@ -478,12 +469,8 @@ public class GraphicsEnvironment {
         *  - devices that are running a userdebug build (ro.debuggable) or can inject libraries for
         *    debugging (PR_SET_DUMPABLE).
         */
        final boolean appIsDebuggable = isDebuggable(context);
        final boolean deviceIsDebuggable = getCanLoadSystemLibraries() == 1;
        if (!(appIsDebuggable || deviceIsDebuggable)) {
            Log.v(TAG, "Skipping loading temporary rules file: "
                    + "appIsDebuggable = " + appIsDebuggable + ", "
                    + "adbRootEnabled = " + deviceIsDebuggable);
        if (!isDebuggable()) {
            Log.v(TAG, "Skipping loading temporary rules file");
            return false;
        }

@@ -742,7 +729,7 @@ public class GraphicsEnvironment {

        final boolean enablePrereleaseDriver =
                (ai.metaData != null && ai.metaData.getBoolean(METADATA_DEVELOPER_DRIVER_ENABLE))
                || getCanLoadSystemLibraries() == 1;
                || isDebuggable();

        // Priority for Game Driver settings global on confliction (Higher priority comes first):
        // 1. GAME_DRIVER_ALL_APPS
@@ -918,7 +905,7 @@ public class GraphicsEnvironment {
        return "";
    }

    private static native int getCanLoadSystemLibraries();
    private static native boolean isDebuggable();
    private static native void setLayerPaths(ClassLoader classLoader, String layerPaths);
    private static native void setDebugLayers(String layers);
    private static native void setDebugLayersGLES(String layers);
+3 −3
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@

namespace {

int getCanLoadSystemLibraries_native() {
    return android::GraphicsEnv::getInstance().getCanLoadSystemLibraries();
bool isDebuggable_native() {
    return android::GraphicsEnv::getInstance().isDebuggable();
}

void setDriverPathAndSphalLibraries_native(JNIEnv* env, jobject clazz, jstring path,
@@ -94,7 +94,7 @@ void hintActivityLaunch_native(JNIEnv* env, jobject clazz) {
}

const JNINativeMethod g_methods[] = {
    { "getCanLoadSystemLibraries", "()I", reinterpret_cast<void*>(getCanLoadSystemLibraries_native) },
    { "isDebuggable", "()Z", reinterpret_cast<void*>(isDebuggable_native) },
    { "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) },
    { "setGpuStats", "(Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;I)V", reinterpret_cast<void*>(setGpuStats_native) },
    { "setInjectLayersPrSetDumpable", "()Z", reinterpret_cast<void*>(setInjectLayersPrSetDumpable_native) },