From 7a09b8322cab26d6e3da1362d3c74964ae66b5d4 Mon Sep 17 00:00:00 2001 From: Sebastien Hertz Date: Mon, 10 Aug 2015 18:55:34 +0200 Subject: Allow debugging only for apps forked from zygote When starting the runtime from app_process, we only pass JDWP options if starting zygote. It prevents from opening a JDWP connection in non-zygote programs while Android apps (forked from zygote) remain debuggable. Bug: 23050463 Change-Id: If8ea719063a65db4cdeed69a838b52e87b078b08 --- core/jni/AndroidRuntime.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index bae2cde..bcf20c9 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -535,7 +535,7 @@ bool AndroidRuntime::parseCompilerRuntimeOption(const char* property, * * Returns 0 on success. */ -int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) +int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote) { JavaVMInitArgs initArgs; char propBuf[PROPERTY_VALUE_MAX]; @@ -671,9 +671,13 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:"); parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC="); - /* enable debugging; set suspend=y to pause during VM init */ - /* use android ADB transport */ - addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y"); + /* + * Enable debugging only for apps forked from zygote. + * Set suspend=y to pause during VM init and use android ADB transport. + */ + if (zygote) { + addOption("-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y"); + } parseRuntimeOption("dalvik.vm.lockprof.threshold", lockProfThresholdBuf, @@ -968,7 +972,7 @@ jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) { * Passes the main function two arguments, the class name and the specified * options string. */ -void AndroidRuntime::start(const char* className, const Vector& options) +void AndroidRuntime::start(const char* className, const Vector& options, bool zygote) { ALOGD(">>>>>> START %s uid %d <<<<<<\n", className != NULL ? className : "(unknown)", getuid()); @@ -1004,7 +1008,7 @@ void AndroidRuntime::start(const char* className, const Vector& options JniInvocation jni_invocation; jni_invocation.Init(NULL); JNIEnv* env; - if (startVm(&mJavaVM, &env) != 0) { + if (startVm(&mJavaVM, &env, zygote) != 0) { return; } onVmCreated(env); -- cgit v1.1