Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Android boot tests using mDNS for device IDs #115

Merged
merged 1 commit into from
Jan 1, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -617,33 +617,101 @@ public async Task<int> ExecuteBuildGraphNodeAsync(
"platform-tools",
"adb.exe");

var adbArguments = new List<LogicalProcessArgument>();
var deviceIdDescriptor = "(default)";
if (!string.IsNullOrWhiteSpace(deviceId))
if (deviceId.Contains("._tcp.", StringComparison.Ordinal))
{
adbArguments.Add("-s");
adbArguments.Add(deviceId);
deviceIdDescriptor = deviceId;
// Pre-connect via mDNS. This is necessary because if we're not already connected to the device when Gauntlet runs, it will append :5555 to the address, which we don't want for mDNS.
_logger.LogInformation($"Checking mDNS service is running...");
await _processExecutor.ExecuteAsync(
new ProcessSpecification
{
FilePath = adbFilePath,
Arguments = ["mdns", "check"],
},
CaptureSpecification.Passthrough,
cancellationToken).ConfigureAwait(false);

_logger.LogInformation($"Reporting what mDNS services can be discovered for diagnostic purposes:");
await _processExecutor.ExecuteAsync(
new ProcessSpecification
{
FilePath = adbFilePath,
Arguments = ["mdns", "services"],
},
CaptureSpecification.Passthrough,
cancellationToken).ConfigureAwait(false);

_logger.LogInformation($"Connecting to Android device '{deviceId}' via mDNS before Gauntlet starts...");
await _processExecutor.ExecuteAsync(
new ProcessSpecification
{
FilePath = adbFilePath,
Arguments = ["connect", deviceId],
},
CaptureSpecification.Passthrough,
cancellationToken).ConfigureAwait(false);

_logger.LogInformation($"Checking that we're connected to Android device '{deviceId}' via mDNS and authorized...");
var devicesStringBuilder = new StringBuilder();
await _processExecutor.ExecuteAsync(
new ProcessSpecification
{
FilePath = adbFilePath,
Arguments = ["devices"],
},
CaptureSpecification.CreateFromSanitizedStdoutStringBuilder(devicesStringBuilder),
cancellationToken).ConfigureAwait(false);

var found = false;
var devicesList = devicesStringBuilder.ToString()
.Replace("\r\n", "\n", StringComparison.Ordinal)
.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
foreach (var deviceEntry in devicesList)
{
if (deviceEntry.StartsWith(deviceId, StringComparison.Ordinal) &&
deviceEntry.EndsWith("device", StringComparison.Ordinal))
{
found = true;
}
}
if (!found)
{
_logger.LogError($"Did not detect authorized connection to '{deviceId}' with 'adb devices':");
_logger.LogError(devicesStringBuilder.ToString());
return 1;
}

_logger.LogInformation($"Successfully connected to Android device '{deviceId} over mDNS!");
}

adbArguments.AddRange([
"shell",
"-n",
"am",
"broadcast",
"-a",
"com.oculus.vrpowermanager.prox_close"
]);

_logger.LogInformation($"Turning off Quest proximity sensor for device: {deviceIdDescriptor}. This is expected to gracefully fail if the device is not a Meta Quest device.");
await _processExecutor.ExecuteAsync(
new ProcessSpecification
{
var adbArguments = new List<LogicalProcessArgument>();
var deviceIdDescriptor = "(default)";
if (!string.IsNullOrWhiteSpace(deviceId))
{
FilePath = adbFilePath,
Arguments = adbArguments,
},
CaptureSpecification.Passthrough,
cancellationToken).ConfigureAwait(false);
adbArguments.Add("-s");
adbArguments.Add(deviceId);
deviceIdDescriptor = deviceId;
}

adbArguments.AddRange([
"shell",
"-n",
"am",
"broadcast",
"-a",
"com.oculus.vrpowermanager.prox_close"
]);

_logger.LogInformation($"Turning off Quest proximity sensor for device: {deviceIdDescriptor}. This is expected to gracefully fail if the device is not a Meta Quest device.");
await _processExecutor.ExecuteAsync(
new ProcessSpecification
{
FilePath = adbFilePath,
Arguments = adbArguments,
},
CaptureSpecification.Passthrough,
cancellationToken).ConfigureAwait(false);
}
}

return 0;
Expand Down
3 changes: 3 additions & 0 deletions UET/Redpoint.Uet.SdkManagement/Sdk/AndroidSdkSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public Task<EnvironmentForSdkUsage> GetRuntimeEnvironmentForSdkPackage(string sd
{ "ANDROID_HOME", Path.Combine(sdkPackagePath, "Sdk") },
{ "NDKROOT", Path.Combine(sdkPackagePath, "Sdk", "ndk", ndkVersion) },
{ "JAVA_HOME", Path.Combine(sdkPackagePath, "Jdk", jreVersion) },

// Use the openscreen library to allow ADB to discover devices via mDNS without Bonjour installed.
{ "ADB_MDNS_OPENSCREEN", "1" },
}
});
}
Expand Down
Loading