Skip to content

Apple: Fix NRE when listing devices that are not paired #1127

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

Merged
merged 1 commit into from
Jan 8, 2024
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 @@ -30,13 +30,15 @@ private class DeviceInfo
public string UDID { get; }
public string Type { get; }
public string OSVersion { get; }
public bool IsPaired { get; }

public DeviceInfo(string name, string uDID, string type, string oSVersion)
public DeviceInfo(string name, string uDID, string type, string oSVersion, bool isPaired = true)
{
Name = name;
UDID = uDID;
Type = type;
OSVersion = oSVersion;
IsPaired = isPaired;
}
}

Expand Down Expand Up @@ -129,7 +131,8 @@ private void AsText(SystemInfo info)
foreach (var dev in info.Devices)
{
var uuid = Arguments.ShowDevicesUUID ? $" {dev.UDID} " : "";
Console.WriteLine($" {dev.Name.PadRight(maxLength)}{uuid} {dev.OSVersion,-13} {dev.Type}");
var notPaired = dev.IsPaired ? "" : "(not paired) ";
Console.WriteLine($" {notPaired}{dev.Name.PadRight(maxLength)}{uuid} {dev.OSVersion,-13} {dev.Type}");
}
}
else
Expand Down Expand Up @@ -213,7 +216,8 @@ protected override async Task<ExitCode> InvokeInternal(Extensions.Logging.ILogge
name: dev.Name,
uDID: dev.DeviceIdentifier,
type: $"{dev.DeviceClass} {dev.DevicePlatform}",
oSVersion: dev.OSVersion));
oSVersion: dev.OSVersion,
isPaired: dev.IsPaired));
}

if (Arguments.UseJson)
Expand Down
25 changes: 15 additions & 10 deletions src/Microsoft.DotNet.XHarness.iOS.Shared/Hardware/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public Device(
string deviceIdentifier,
DeviceClass deviceClass,
string name,
string buildVersion,
string productVersion,
string productType,
string? buildVersion,
string? productVersion,
string? productType,
string interfaceType,
string companionIdentifier = null,
string? companionIdentifier = null,
bool? isUsableForDebugging = null,
bool isLocked = false,
bool isPaired = false)
Expand All @@ -47,19 +47,19 @@ public Device(

public string DeviceIdentifier { get; }
public DeviceClass DeviceClass { get; }
public string CompanionIdentifier { get; }
public string? CompanionIdentifier { get; }
public string Name { get; }
public string BuildVersion { get; }
public string ProductVersion { get; }
public string ProductType { get; }
public string? BuildVersion { get; }
public string? ProductVersion { get; }
public string? ProductType { get; }
public string InterfaceType { get; }
public bool? IsUsableForDebugging { get; }
public bool IsLocked { get; }
public bool IsPaired { get; }

public string UDID => DeviceIdentifier;

public string OSVersion => ProductVersion;
public string? OSVersion => ProductVersion;

// Add a speed property that can be used to sort a list of devices according to speed.
public int DebugSpeed => InterfaceType?.ToLowerInvariant() switch
Expand All @@ -83,7 +83,7 @@ public Device(

public bool Supports32Bit => DevicePlatform switch
{
DevicePlatform.iOS => Version.Parse(ProductVersion).Major < 11,
DevicePlatform.iOS => ProductVersion != null && Version.Parse(ProductVersion).Major < 11,
DevicePlatform.tvOS => false,
DevicePlatform.watchOS => true,
DevicePlatform.xrOS => false,
Expand All @@ -96,6 +96,11 @@ public Architecture Architecture
{
var model = ProductType;

if (model == null)
{
return Architecture.Unknown;
}

// https://www.theiphonewiki.com/wiki/Models
if (model.StartsWith("iPhone", StringComparison.Ordinal))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.DotNet.XHarness.iOS.Shared.Hardware;

public enum Architecture
{
Unknown,
ARMv6,
ARMv7,
ARMv7k,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public interface IHardwareDevice : IDevice
{
string DeviceIdentifier { get; }
DeviceClass DeviceClass { get; }
string CompanionIdentifier { get; }
string BuildVersion { get; }
string ProductVersion { get; }
string ProductType { get; }
string? CompanionIdentifier { get; }
string? BuildVersion { get; }
string? ProductVersion { get; }
string? ProductType { get; }
string InterfaceType { get; }
bool? IsUsableForDebugging { get; }
bool IsLocked { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<NoWarn>$(NoWarn);8600;8601;8602;8603;8604</NoWarn>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<NoWarn>$(NoWarn);8600;8601;8602;8603;8604;8632</NoWarn>
</PropertyGroup>

<!-- Remove files that are only included inside of the packaged iOS app and are not to be compiled as part of this project -->
Expand Down