Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Xamarin.AndroidTools/Debugging/DebuggingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class DebuggingExtensions
// Twenty retries at 250 ms intervals allow up to five seconds for the process to appear.
const int GET_PID_RETRY_COUNT = 20;
const int WAIT_BEFORE_RETRY_GET_PID = 250;
const int WAIT_FOR_DEBUGGER_TO_ATTACH_MS = 1400;
internal static readonly TimeSpan WaitForDebuggerReadinessTimeout = TimeSpan.FromSeconds (30);

/// <summary>
/// Starts the process debugging using the given execution configuration
Expand Down Expand Up @@ -181,10 +181,7 @@ public static async Task ConnectJdwpAsync(this AndroidDevice androidDevice, Exec
await AdbServer.Default.ForwardPort (androidDevice, "tcp", jdwpClient.Port, "jdwp", pid, token).ConfigureAwait (false);
try {
await jdwpClient.ConnectAsync (token).ConfigureAwait (false);

// Keep the Connection for 1300 milliseconds, otherwise the Android OS ignores the connection!
// https://github.com/aosp-mirror/platform_frameworks_base/blob/6b28a227400749f4f8ad1f56799370e7c2cab149/core/java/android/os/Debug.java#L101C50-L101C54
await Task.Delay (WAIT_FOR_DEBUGGER_TO_ATTACH_MS, token).ConfigureAwait (false);
await jdwpClient.WaitForDebuggerReadinessAsync (WaitForDebuggerReadinessTimeout, config.LogWiter, token).ConfigureAwait (false);

await jdwpClient.DisconnectAsync ().ConfigureAwait (false);
} finally {
Expand Down
26 changes: 26 additions & 0 deletions src/Xamarin.AndroidTools/Debugging/Java/DdmCommandPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Buffers.Binary;
using System.Text;

namespace Xamarin.AndroidTools.Debugging.Java
{
internal class DdmCommandPacket : CommandPacket
{
public DdmCommandPacket (string chunkType, ReadOnlyMemory<byte> chunkData)
{
if (chunkType == null)
throw new ArgumentNullException (nameof (chunkType));
if (chunkType.Length != 4)
throw new ArgumentException ("DDM chunk types must contain exactly four ASCII characters.", nameof (chunkType));

CommandSet = 0xc7;
Command = 0x01;

var data = new byte [8 + chunkData.Length];
Encoding.ASCII.GetBytes (chunkType, 0, chunkType.Length, data, 0);
BinaryPrimitives.WriteInt32BigEndian (data.AsSpan (4, 4), chunkData.Length);
chunkData.CopyTo (data.AsMemory (8));
Data = data;
}
}
}
Loading
Loading