[debugging] Protect managed-only cold activity startup from ANRs - #12786
Draft
davidnguyen-tech wants to merge 2 commits into
Draft
davidnguyen-tech wants to merge 2 commits into
davidnguyen-tech wants to merge 2 commits into
Conversation
Use a bounded transient non-wait debug-app transaction for eligible cold activity launches, observe process attach before clearing, and preserve unsupported launch paths with explicit diagnostics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment on lines
31
to
+36
| public async static Task StartWithDebuggingAsync(this IAndroidDevice device, ExecutionConfiguration configuration, CancellationToken token) | ||
| { | ||
| if (configuration.RunCommand is AmStartCommand) { | ||
| var gate = ManagedActivityLaunch.GetGate (device.ID); | ||
| if (!await gate.WaitAsync (TimeSpan.FromSeconds (30), token).ConfigureAwait (false)) | ||
| throw new TimeoutException (Properties.Resources.ManagedLaunchGateTimeout); |
Member
There was a problem hiding this comment.
We want to delete the src/Mono.AndroidTools and src/Xamarin.AndroidTools projects.
Could the fix (am set-debug-app <package> call) go in:
dotnet runwould use: https://github.com/dotnet/android/blob/main/src/Microsoft.Android.Run/Program.cs- Current main would use this task for
-t:Runtarget: https://github.com/dotnet/android/blob/main/src/Xamarin.Android.Build.Debugging.Tasks/Tasks/RunActivity.cs
It should be behind existing flags that knows they are attempting to debug.
Eventually, we'll unify these two, but I was going to wait until we branch for .NET 11.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Protect eligible managed-only cold activity launches with a bounded, transient
am set-debug-app <package>transaction, without-wor--persistent. Keep the existing Java-debugging opt-in and MSBuild defaults unchanged.Disabling
am start -Davoids Java debugger waiting but does not mark an intentional early managed pause as debugging. AOSP distinguishesDEBUG_ONfromDEBUG_WAIT; the former retains ActivityManager's per-process debugging/ANR exemption without waiting for a Java debugger. See ActivityManagerService, ActivityThread, and ProcessErrorStateRecord.Behavior and safety boundaries
mDebugging=trueafter attach. PID visibility alone is insufficient; noam start -Wor application-code readiness wait is introduced.Android's debug-app command force-stops a package across all users, which is why protection is restricted to single-user cold launches. There is no atomic compare-and-clear API: unrelated adb clients, same-package concurrent external ownership, disconnection and late remote execution remain platform limitations. An observed different owner is not cleared.
Validation
126 targeted tests pass against the real shared launch implementation and ADB transport using a private TCP fake server. Regressions were demonstrated red before corrections, including real
Stopping:/Starting:output, custom-process eligibility, component-only launches, fallback cancellation, and gate diagnostics. Coverage includes PID-before-attach, timeout, cleanup/launch double failure, ownership changes, retries, malformed post-mutation state and pre-arm unsupported layouts.The original reviewed implementation is commit
663060b22b02f872217f8c602db5671ad64ce03a. Publication merge06b2860e6fb1f6e9adc71de71aaa7b8a77946b59preserves that commit and incorporates upstream main00c4f3d99d4a138fc3c0818369126b18b80457ee, whose sole additional change is nullable annotations in the installer'sPlatform.cs. The seven-file implementation patch is unchanged. All 126 targeted tests were rerun on the publication merge: 126 passed, 0 failed, 0 skipped.Built the supported netstandard2.0 product libraries and AndroidSdk netstandard2.0/net10.0 graph; net10.0 tests ran with configured major runtime roll-forward on .NET 11. Fixtures are source-shaped deterministic responses, not device captures. No live device/OEM breakpoint validation or full native SDK build was performed. This draft is not a production runtime sign-off.