Allow debugging only for apps forked from zygote DO NOT MERGE
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 7a09b8322c)
Change-Id: I2400ecc8aea7579c43300efccf288b69f70eef53
This commit is contained in:
@@ -221,14 +221,14 @@ int main(int argc, char* const argv[])
|
|||||||
|
|
||||||
if (zygote) {
|
if (zygote) {
|
||||||
runtime.start("com.android.internal.os.ZygoteInit",
|
runtime.start("com.android.internal.os.ZygoteInit",
|
||||||
startSystemServer ? "start-system-server" : "");
|
startSystemServer ? "start-system-server" : "", zygote);
|
||||||
} else if (className) {
|
} else if (className) {
|
||||||
// Remainder of args get passed to startup class main()
|
// Remainder of args get passed to startup class main()
|
||||||
runtime.mClassName = className;
|
runtime.mClassName = className;
|
||||||
runtime.mArgC = argc - i;
|
runtime.mArgC = argc - i;
|
||||||
runtime.mArgV = argv + i;
|
runtime.mArgV = argv + i;
|
||||||
runtime.start("com.android.internal.os.RuntimeInit",
|
runtime.start("com.android.internal.os.RuntimeInit",
|
||||||
application ? "application" : "tool");
|
application ? "application" : "tool", zygote);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: no class name or --zygote supplied.\n");
|
fprintf(stderr, "Error: no class name or --zygote supplied.\n");
|
||||||
app_usage();
|
app_usage();
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ void AndroidRuntime::parseExtraOpts(char* extraOptsBuf)
|
|||||||
*
|
*
|
||||||
* Returns 0 on success.
|
* Returns 0 on success.
|
||||||
*/
|
*/
|
||||||
int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
|
int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
JavaVMInitArgs initArgs;
|
JavaVMInitArgs initArgs;
|
||||||
@@ -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 */
|
* Enable debugging only for apps forked from zygote.
|
||||||
opt.optionString =
|
* Set suspend=y to pause during VM init and use android ADB transport.
|
||||||
"-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y";
|
*/
|
||||||
mOptions.add(opt);
|
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");
|
ALOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
|
||||||
if (checkJni) {
|
if (checkJni) {
|
||||||
@@ -802,7 +806,7 @@ char* AndroidRuntime::toSlashClassName(const char* className)
|
|||||||
* Passes the main function two arguments, the class name and the specified
|
* Passes the main function two arguments, the class name and the specified
|
||||||
* options string.
|
* 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",
|
ALOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
|
||||||
className != NULL ? className : "(unknown)");
|
className != NULL ? className : "(unknown)");
|
||||||
@@ -835,7 +839,7 @@ void AndroidRuntime::start(const char* className, const char* options)
|
|||||||
JniInvocation jni_invocation;
|
JniInvocation jni_invocation;
|
||||||
jni_invocation.Init(NULL);
|
jni_invocation.Init(NULL);
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
if (startVm(&mJavaVM, &env) != 0) {
|
if (startVm(&mJavaVM, &env, zygote) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onVmCreated(env);
|
onVmCreated(env);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
|
|
||||||
int addVmArguments(int argc, const char* const argv[]);
|
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);
|
void exit(int code);
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static int startReg(JNIEnv* env);
|
static int startReg(JNIEnv* env);
|
||||||
void parseExtraOpts(char* extraOptsBuf);
|
void parseExtraOpts(char* extraOptsBuf);
|
||||||
int startVm(JavaVM** pJavaVM, JNIEnv** pEnv);
|
int startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote);
|
||||||
|
|
||||||
Vector<JavaVMOption> mOptions;
|
Vector<JavaVMOption> mOptions;
|
||||||
bool mExitWithoutCleanup;
|
bool mExitWithoutCleanup;
|
||||||
|
|||||||
Reference in New Issue
Block a user