@@ -60,7 +60,7 @@ public AdbDevice(string id, string model)
60
60
/// <summary>
61
61
/// Abstraction over using ADB to interact with the Quest.
62
62
/// </summary>
63
- public class AndroidDebugBridge
63
+ public class AndroidDebugBridge : IDisposable
64
64
{
65
65
/// <summary>
66
66
/// Package names that will not be included in the apps to patch list
@@ -95,6 +95,7 @@ public class AndroidDebugBridge
95
95
private readonly IUserPrompter _prompter ;
96
96
private readonly string _adbExecutableName = OperatingSystem . IsWindows ( ) ? "adb.exe" : "adb" ;
97
97
private readonly Action _quit ;
98
+ private readonly ProcessUtil _processUtil = new ( ) ;
98
99
99
100
/// <summary>
100
101
/// The minimum time between checks for the currently open ADB daemon.
@@ -144,7 +145,7 @@ public async Task PrepareAdbPath()
144
145
{
145
146
// Redownloading ADB - existing installation was not valid
146
147
Log . Information ( "Existing downloaded ADB was out of date or corrupted - fetching again" ) ;
147
- await ProcessUtil . InvokeAndCaptureOutput ( downloadedAdb , "kill-server" ) ; // Kill server first, otherwise directory will be in use, so can't be deleted.
148
+ await _processUtil . InvokeAndCaptureOutput ( downloadedAdb , "kill-server" ) ; // Kill server first, otherwise directory will be in use, so can't be deleted.
148
149
_adbPath = await _filesDownloader . GetFileLocation ( ExternalFileType . PlatformTools , true ) ;
149
150
}
150
151
else
@@ -166,7 +167,7 @@ private async Task<bool> SetAdbPathIfValid(string adbExecutablePath)
166
167
try
167
168
{
168
169
Log . Verbose ( "Checking if ADB at {AdbPath} is present and up-to-date" , adbExecutablePath ) ;
169
- var outputInfo = await ProcessUtil . InvokeAndCaptureOutput ( adbExecutablePath , "version" ) ;
170
+ var outputInfo = await _processUtil . InvokeAndCaptureOutput ( adbExecutablePath , "version" ) ;
170
171
string output = outputInfo . AllOutput ;
171
172
172
173
Log . Debug ( "Output from checking ADB version: {VerisonOutput}" , output ) ;
@@ -225,7 +226,7 @@ private async Task<List<AdbDevice>> ListDevices()
225
226
await PrepareAdbPath ( ) ;
226
227
}
227
228
228
- var output = await ProcessUtil . InvokeAndCaptureOutput ( _adbPath ! , "devices -l" ) ;
229
+ var output = await _processUtil . InvokeAndCaptureOutput ( _adbPath ! , "devices -l" ) ;
229
230
Log . Debug ( "Listing devices output {Output}" , output . AllOutput ) ;
230
231
231
232
string [ ] lines = output . StandardOutput . Trim ( ) . Split ( '\n ' ) ;
@@ -390,7 +391,7 @@ public async Task<ProcessOutput> RunCommand(string command, params int[] allowed
390
391
Log . Debug ( "Executing ADB command: {Command}" , $ "adb { command } ") ;
391
392
while ( true )
392
393
{
393
- var output = await ProcessUtil . InvokeAndCaptureOutput ( _adbPath , $ "-s { chosenDeviceId } " + command ) ;
394
+ var output = await _processUtil . InvokeAndCaptureOutput ( _adbPath , $ "-s { chosenDeviceId } " + command ) ;
394
395
if ( output . StandardOutput . Length > 0 )
395
396
{
396
397
Log . Verbose ( "Standard output: {StandardOutput}" , output . StandardOutput ) ;
@@ -827,5 +828,11 @@ public async Task<bool> FileExists(string path)
827
828
var directoryFiles = await ListDirectoryFiles ( dirName , true ) ;
828
829
return directoryFiles . Contains ( Path . GetFileName ( path ) ) ;
829
830
}
831
+
832
+ public void Dispose ( )
833
+ {
834
+ _logcatProcess ? . Dispose ( ) ;
835
+ _processUtil . Dispose ( ) ; // Ensure all ADB processes are killed.
836
+ }
830
837
}
831
838
}
0 commit comments