Skip to content

Commit

Permalink
Allow debugging only for apps forked from zygote
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 7a09b83)

Change-Id: Ib5b6d3bc4d45389993c3c54226df5a7b72479d19
  • Loading branch information
Sebastien Hertz authored and LordNerevar committed Oct 17, 2015
1 parent 7233c04 commit ae91b03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmds/app_process/app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ int main(int argc, char* const argv[])

if (zygote) {
runtime.start("com.android.internal.os.ZygoteInit",
startSystemServer ? "start-system-server" : "");
startSystemServer ? "start-system-server" : "", zygote);
} else if (className) {
// Remainder of args get passed to startup class main()
runtime.mClassName = className;
runtime.mArgC = argc - i;
runtime.mArgV = argv + i;
runtime.start("com.android.internal.os.RuntimeInit",
application ? "application" : "tool");
application ? "application" : "tool", zygote);
} else {
fprintf(stderr, "Error: no class name or --zygote supplied.\n");
app_usage();
Expand Down
20 changes: 12 additions & 8 deletions core/jni/AndroidRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
*
* Returns 0 on success.
*/
int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
{
int result = -1;
JavaVMInitArgs initArgs;
Expand Down Expand Up @@ -633,11 +633,15 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
}
}

/* enable debugging; set suspend=y to pause during VM init */
/* use android ADB transport */
opt.optionString =
"-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
mOptions.add(opt);
/*
* Enable debugging only for apps forked from zygote.
* Set suspend=y to pause during VM init and use android ADB transport.
*/
if (zygote) {
opt.optionString =
"-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
mOptions.add(opt);
}

ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
if (checkJni) {
Expand Down Expand Up @@ -795,7 +799,7 @@ char* AndroidRuntime::toSlashClassName(const char* className)
* Passes the main function two arguments, the class name and the specified
* options string.
*/
void AndroidRuntime::start(const char* className, const char* options)
void AndroidRuntime::start(const char* className, const char* options, bool zygote)
{
ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
className != NULL ? className : "(unknown)");
Expand Down Expand Up @@ -828,7 +832,7 @@ void AndroidRuntime::start(const char* className, const char* options)
JniInvocation jni_invocation;
jni_invocation.Init(NULL);
JNIEnv* env;
if (startVm(&mJavaVM, &env) != 0) {
if (startVm(&mJavaVM, &env, zygote) != 0) {
return;
}
onVmCreated(env);
Expand Down
4 changes: 2 additions & 2 deletions include/android_runtime/AndroidRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AndroidRuntime

int addVmArguments(int argc, const char* const argv[]);

void start(const char *classname, const char* options);
void start(const char *classname, const char* options, bool zygote);

void exit(int code);

Expand Down Expand Up @@ -116,7 +116,7 @@ class AndroidRuntime
private:
static int startReg(JNIEnv* env);
void parseExtraOpts(char* extraOptsBuf);
int startVm(JavaVM** pJavaVM, JNIEnv** pEnv);
int startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote);

Vector<JavaVMOption> mOptions;
bool mExitWithoutCleanup;
Expand Down

0 comments on commit ae91b03

Please sign in to comment.