From 55c9d73918240c9a56b1a5a0bfccea6b184abbd2 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Tue, 26 Apr 2016 12:24:55 -0700 Subject: [PATCH] Do not set waitForDebugger if the process to be debugged already started For non-persistent debug settings, mDebugApp and mWaitForDebugger flags will only be restored when we get attachApplication. If the process is already running, we can't wait for debugger and there will be no attachApplication calls coming. We should leave the settings unmodified, otherwise after two such calls, both mDebugApp and mOrigDebugApp will point to the same app, and the debug settings can never be restored. bug: 27931552 Change-Id: Id53e21bbe154f45bf2ca12bb5d7fd56279bae653 --- .../server/am/ActivityStackSupervisor.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index f281683571cce..66bc51cf477ed 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1097,7 +1097,21 @@ public final class ActivityStackSupervisor implements DisplayListener { // Don't debug things in the system process if (!aInfo.processName.equals("system")) { if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { - mService.setDebugApp(aInfo.processName, true, false); + final ProcessRecord app = mService.getProcessRecordLocked( + aInfo.processName, aInfo.applicationInfo.uid, true); + // If the process already started, we can't wait for debugger and shouldn't + // modify the debug settings. + // For non-persistent debug, normally we set the debug app here, and restores + // to the original at attachApplication time. However, if the app process + // already exists, we won't get another attachApplication, and the debug setting + // never gets restored. Furthermore, if we get two such calls back-to-back, + // both mOrigDebugApp and mDebugApp will become the same app, and it won't be + // cleared even if we get attachApplication after the app process is killed. + if (app == null || app.thread == null) { + mService.setDebugApp(aInfo.processName, true, false); + } else { + Slog.w(TAG, "Ignoring waitForDebugger because process already exists"); + } } if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) {