Loading core/java/android/app/ActivityManager.java +7 −0 Original line number Diff line number Diff line Loading @@ -403,6 +403,13 @@ public class ActivityManager { */ public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3; /** * Flag for IActivityManaqer.startActivity: launch the app for * debugging and suspend threads. * @hide */ public static final int START_FLAG_DEBUG_SUSPEND = 1 << 4; /** * Result for IActivityManaqer.broadcastIntent: success! * @hide Loading core/java/android/app/ActivityThread.java +47 −17 Original line number Diff line number Diff line Loading @@ -6885,26 +6885,13 @@ public final class ActivityThread extends ClientTransactionHandler final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); // Wait for debugger after we have notified the system to finish attach application if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { Slog.w(TAG, "Application " + data.info.getPackageName() + " is waiting for the debugger ..."); try { mgr.showWaitingForDebugger(mAppThread, true); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Debug.waitForDebugger(); try { mgr.showWaitingForDebugger(mAppThread, false); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } waitForDebugger(data); } else if (data.debugMode == ApplicationThreadConstants.DEBUG_SUSPEND) { suspendAllAndSendVmStart(data); } // Nothing special to do in case of DEBUG_ON. } try { Loading Loading @@ -6988,6 +6975,49 @@ public final class ActivityThread extends ClientTransactionHandler } } @UnsupportedAppUsage private void waitForDebugger(AppBindData data) { final IActivityManager mgr = ActivityManager.getService(); Slog.w(TAG, "Application " + data.info.getPackageName() + " is waiting for the debugger ..."); try { mgr.showWaitingForDebugger(mAppThread, true); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Debug.waitForDebugger(); try { mgr.showWaitingForDebugger(mAppThread, false); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } @UnsupportedAppUsage private void suspendAllAndSendVmStart(AppBindData data) { final IActivityManager mgr = ActivityManager.getService(); Slog.w(TAG, "Application " + data.info.getPackageName() + " is suspending. Debugger needs to resume to continue."); try { mgr.showWaitingForDebugger(mAppThread, true); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Debug.suspendAllAndSendVmStart(); try { mgr.showWaitingForDebugger(mAppThread, false); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } private void handleSetContentCaptureOptionsCallback(String packageName) { if (mContentCaptureOptionsCallback != null) { return; Loading core/java/android/app/ApplicationThreadConstants.java +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public final class ApplicationThreadConstants { public static final int DEBUG_OFF = 0; public static final int DEBUG_ON = 1; public static final int DEBUG_WAIT = 2; public static final int DEBUG_SUSPEND = 3; // the package has been removed, clean up internal references public static final int PACKAGE_REMOVED = 0; Loading services/core/java/com/android/server/am/ActivityManagerService.java +22 −3 Original line number Diff line number Diff line Loading @@ -1441,6 +1441,9 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") private boolean mWaitForDebugger = false; @GuardedBy("this") private boolean mSuspendUponWait = false; @GuardedBy("this") private boolean mDebugTransient = false; Loading Loading @@ -5011,9 +5014,15 @@ public class ActivityManagerService extends IActivityManager.Stub try { int testMode = ApplicationThreadConstants.DEBUG_OFF; if (mDebugApp != null && mDebugApp.equals(processName)) { testMode = mWaitForDebugger ? ApplicationThreadConstants.DEBUG_WAIT : ApplicationThreadConstants.DEBUG_ON; if (mWaitForDebugger) { if (mSuspendUponWait) { testMode = ApplicationThreadConstants.DEBUG_SUSPEND; } else { testMode = ApplicationThreadConstants.DEBUG_WAIT; } } else { testMode = ApplicationThreadConstants.DEBUG_ON; } app.setDebugging(true); if (mDebugTransient) { mDebugApp = mOrigDebugApp; Loading Loading @@ -7160,6 +7169,11 @@ public class ActivityManagerService extends IActivityManager.Stub public void setDebugApp(String packageName, boolean waitForDebugger, boolean persistent) { setDebugApp(packageName, waitForDebugger, persistent, false); } private void setDebugApp(String packageName, boolean waitForDebugger, boolean persistent, boolean suspendUponWait) { enforceCallingPermission(android.Manifest.permission.SET_DEBUG_APP, "setDebugApp()"); Loading @@ -7185,6 +7199,7 @@ public class ActivityManagerService extends IActivityManager.Stub } mDebugApp = packageName; mWaitForDebugger = waitForDebugger; mSuspendUponWait = suspendUponWait; mDebugTransient = !persistent; if (packageName != null) { forceStopPackageLocked(packageName, -1, false, false, true, true, Loading Loading @@ -17872,6 +17887,10 @@ public class ActivityManagerService extends IActivityManager.Stub setDebugApp(aInfo.processName, true, false); } if ((startFlags & ActivityManager.START_FLAG_DEBUG_SUSPEND) != 0) { setDebugApp(aInfo.processName, true, false, true); } if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); } services/core/java/com/android/server/am/ActivityManagerShellCommand.java +2 −0 Original line number Diff line number Diff line Loading @@ -412,6 +412,8 @@ final class ActivityManagerShellCommand extends ShellCommand { public boolean handleOption(String opt, ShellCommand cmd) { if (opt.equals("-D")) { mStartFlags |= ActivityManager.START_FLAG_DEBUG; } else if (opt.equals("--suspend")) { mStartFlags |= ActivityManager.START_FLAG_DEBUG_SUSPEND; } else if (opt.equals("-N")) { mStartFlags |= ActivityManager.START_FLAG_NATIVE_DEBUGGING; } else if (opt.equals("-W")) { Loading Loading
core/java/android/app/ActivityManager.java +7 −0 Original line number Diff line number Diff line Loading @@ -403,6 +403,13 @@ public class ActivityManager { */ public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3; /** * Flag for IActivityManaqer.startActivity: launch the app for * debugging and suspend threads. * @hide */ public static final int START_FLAG_DEBUG_SUSPEND = 1 << 4; /** * Result for IActivityManaqer.broadcastIntent: success! * @hide Loading
core/java/android/app/ActivityThread.java +47 −17 Original line number Diff line number Diff line Loading @@ -6885,26 +6885,13 @@ public final class ActivityThread extends ClientTransactionHandler final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites(); final StrictMode.ThreadPolicy writesAllowedPolicy = StrictMode.getThreadPolicy(); // Wait for debugger after we have notified the system to finish attach application if (data.debugMode != ApplicationThreadConstants.DEBUG_OFF) { if (data.debugMode == ApplicationThreadConstants.DEBUG_WAIT) { Slog.w(TAG, "Application " + data.info.getPackageName() + " is waiting for the debugger ..."); try { mgr.showWaitingForDebugger(mAppThread, true); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Debug.waitForDebugger(); try { mgr.showWaitingForDebugger(mAppThread, false); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } waitForDebugger(data); } else if (data.debugMode == ApplicationThreadConstants.DEBUG_SUSPEND) { suspendAllAndSendVmStart(data); } // Nothing special to do in case of DEBUG_ON. } try { Loading Loading @@ -6988,6 +6975,49 @@ public final class ActivityThread extends ClientTransactionHandler } } @UnsupportedAppUsage private void waitForDebugger(AppBindData data) { final IActivityManager mgr = ActivityManager.getService(); Slog.w(TAG, "Application " + data.info.getPackageName() + " is waiting for the debugger ..."); try { mgr.showWaitingForDebugger(mAppThread, true); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Debug.waitForDebugger(); try { mgr.showWaitingForDebugger(mAppThread, false); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } @UnsupportedAppUsage private void suspendAllAndSendVmStart(AppBindData data) { final IActivityManager mgr = ActivityManager.getService(); Slog.w(TAG, "Application " + data.info.getPackageName() + " is suspending. Debugger needs to resume to continue."); try { mgr.showWaitingForDebugger(mAppThread, true); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } Debug.suspendAllAndSendVmStart(); try { mgr.showWaitingForDebugger(mAppThread, false); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } } private void handleSetContentCaptureOptionsCallback(String packageName) { if (mContentCaptureOptionsCallback != null) { return; Loading
core/java/android/app/ApplicationThreadConstants.java +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public final class ApplicationThreadConstants { public static final int DEBUG_OFF = 0; public static final int DEBUG_ON = 1; public static final int DEBUG_WAIT = 2; public static final int DEBUG_SUSPEND = 3; // the package has been removed, clean up internal references public static final int PACKAGE_REMOVED = 0; Loading
services/core/java/com/android/server/am/ActivityManagerService.java +22 −3 Original line number Diff line number Diff line Loading @@ -1441,6 +1441,9 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") private boolean mWaitForDebugger = false; @GuardedBy("this") private boolean mSuspendUponWait = false; @GuardedBy("this") private boolean mDebugTransient = false; Loading Loading @@ -5011,9 +5014,15 @@ public class ActivityManagerService extends IActivityManager.Stub try { int testMode = ApplicationThreadConstants.DEBUG_OFF; if (mDebugApp != null && mDebugApp.equals(processName)) { testMode = mWaitForDebugger ? ApplicationThreadConstants.DEBUG_WAIT : ApplicationThreadConstants.DEBUG_ON; if (mWaitForDebugger) { if (mSuspendUponWait) { testMode = ApplicationThreadConstants.DEBUG_SUSPEND; } else { testMode = ApplicationThreadConstants.DEBUG_WAIT; } } else { testMode = ApplicationThreadConstants.DEBUG_ON; } app.setDebugging(true); if (mDebugTransient) { mDebugApp = mOrigDebugApp; Loading Loading @@ -7160,6 +7169,11 @@ public class ActivityManagerService extends IActivityManager.Stub public void setDebugApp(String packageName, boolean waitForDebugger, boolean persistent) { setDebugApp(packageName, waitForDebugger, persistent, false); } private void setDebugApp(String packageName, boolean waitForDebugger, boolean persistent, boolean suspendUponWait) { enforceCallingPermission(android.Manifest.permission.SET_DEBUG_APP, "setDebugApp()"); Loading @@ -7185,6 +7199,7 @@ public class ActivityManagerService extends IActivityManager.Stub } mDebugApp = packageName; mWaitForDebugger = waitForDebugger; mSuspendUponWait = suspendUponWait; mDebugTransient = !persistent; if (packageName != null) { forceStopPackageLocked(packageName, -1, false, false, true, true, Loading Loading @@ -17872,6 +17887,10 @@ public class ActivityManagerService extends IActivityManager.Stub setDebugApp(aInfo.processName, true, false); } if ((startFlags & ActivityManager.START_FLAG_DEBUG_SUSPEND) != 0) { setDebugApp(aInfo.processName, true, false, true); } if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); }
services/core/java/com/android/server/am/ActivityManagerShellCommand.java +2 −0 Original line number Diff line number Diff line Loading @@ -412,6 +412,8 @@ final class ActivityManagerShellCommand extends ShellCommand { public boolean handleOption(String opt, ShellCommand cmd) { if (opt.equals("-D")) { mStartFlags |= ActivityManager.START_FLAG_DEBUG; } else if (opt.equals("--suspend")) { mStartFlags |= ActivityManager.START_FLAG_DEBUG_SUSPEND; } else if (opt.equals("-N")) { mStartFlags |= ActivityManager.START_FLAG_NATIVE_DEBUGGING; } else if (opt.equals("-W")) { Loading