From 1b989de3d7fd2e263fd9d3255549272ce5c78d17 Mon Sep 17 00:00:00 2001 From: Mythri Alle Date: Mon, 12 Sep 2022 17:03:21 +0000 Subject: [PATCH] Don't enable jdwp by default on userdebug builds We would like to have userdebug builds as close to user builds as possible so don't enable jdwp by default on userdebug builds. This means that we won't be able to attach a debugger to non-debuggable builds in userdebug builds by default. However, this support can be enabled by setting persist.debuggable.dalvik.vm.jdwp.enabled property. Eng builds still enable jdwp by default. Bug: 240410400 Test: System boots Change-Id: Iad52254be9b9bc8c9deac8b3ad46e9db1b610160 --- core/java/com/android/internal/os/Zygote.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java index b1e7d15cbf4a9..ea5f0b2f21445 100644 --- a/core/java/com/android/internal/os/Zygote.java +++ b/core/java/com/android/internal/os/Zygote.java @@ -1000,17 +1000,25 @@ static void applyUidSecurityPolicy(ZygoteArguments args, Credentials peer) } } + /** + * This will enable jdwp by default for all apps. It is OK to cache this property + * because we expect to reboot the system whenever this property changes + */ + private static final boolean ENABLE_JDWP = SystemProperties.get( + "persist.debuggable.dalvik.vm.jdwp.enabled").equals("1"); + /** * Applies debugger system properties to the zygote arguments. * - * If "ro.debuggable" is "1", all apps are debuggable. Otherwise, - * the debugger state is specified via the "--enable-jdwp" flag - * in the spawn request. + * For eng builds all apps are debuggable. On userdebug and user builds + * if persist.debuggable.dalvik.vm.jdwp.enabled is 1 all apps are + * debuggable. Otherwise, the debugger state is specified via the + * "--enable-jdwp" flag in the spawn request. * * @param args non-null; zygote spawner args */ static void applyDebuggerSystemProperty(ZygoteArguments args) { - if (RoSystemProperties.DEBUGGABLE) { + if (Build.IS_ENG || ENABLE_JDWP) { args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_JDWP; } }