Skip to content

Commit 4b508b3

Browse files
committed
Check for new ADB servers with min 5 second interval
Useful for cases where QP is opened THEN another app that kills the ADB server
1 parent bd3e3f2 commit 4b508b3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

QuestPatcher.Core/AndroidDebugBridge.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ public class AndroidDebugBridge
7272
private readonly Func<DisconnectionType, Task> _onDisconnect;
7373
private readonly string _adbExecutableName = OperatingSystem.IsWindows() ? "adb.exe" : "adb";
7474

75+
/// <summary>
76+
/// The minimum time between checks for the currently open ADB daemon.
77+
/// QP will automatically switch to a different ADB install if a daemon is started with that install. (and the install is new enough to work with QP.)
78+
/// This allows QP to avoid killing an ADB daemon another app is using. (which would happen if it tried to use its own install and the versions were different.)
79+
/// </summary>
80+
private static readonly TimeSpan DaemonCheckInterval = TimeSpan.FromSeconds(5.0);
81+
7582
private string? _adbPath;
83+
private DateTime _lastDaemonCheck; // The last time at which QP checked for existing ADB daemons
7684
private Process? _logcatProcess;
7785

7886
public AndroidDebugBridge(ExternalFilesDownloader filesDownloader, Func<DisconnectionType, Task> onDisconnect)
@@ -179,6 +187,8 @@ private async Task<bool> SetAdbPathIfValid(string adbExecutablePath)
179187

180188
private async Task<bool> FindExistingAdbServer()
181189
{
190+
_lastDaemonCheck = DateTime.Now;
191+
182192
Log.Debug("Checking for existing daemon");
183193
foreach (string adbPath in FindRunningAdbPath())
184194
{
@@ -230,6 +240,14 @@ public async Task<ProcessOutput> RunCommand(string command, params int[] allowed
230240
{
231241
await PrepareAdbPath();
232242
}
243+
else
244+
{
245+
var now = DateTime.UtcNow;
246+
if ((now - _lastDaemonCheck) > DaemonCheckInterval)
247+
{
248+
await FindExistingAdbServer();
249+
}
250+
}
233251
Debug.Assert(_adbPath != null);
234252

235253
Log.Debug("Executing ADB command: {Command}", $"adb {command}");

0 commit comments

Comments
 (0)