Skip to content

[tests] Fix network interface tests for Android 30 #4868

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
Jun 25, 2020
Merged
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
12 changes: 10 additions & 2 deletions src/Mono.Android/Test/System.Net/NetworkInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ bool IsInterfaceUp (MNetworkInterface inf)

default:
// Android considers 'lo' to be always up
return inf.NetworkInterfaceType == NetworkInterfaceType.Loopback;
return IsLoopbackInterface (inf);
}
}

Expand All @@ -188,9 +188,10 @@ byte[] GetHardwareAddress (MNetworkInterface inf)
var ret = new List <InterfaceInfo> ();

foreach (MNetworkInterface inf in interfaces) {
Console.WriteLine ($"inf: {inf} (name: {inf.Name}; type: {inf.NetworkInterfaceType})");
ret.Add (new InterfaceInfo {
Name = inf.Name,
IsLoopback = inf.NetworkInterfaceType == NetworkInterfaceType.Loopback,
IsLoopback = IsLoopbackInterface (inf),
IsUp = IsInterfaceUp (inf),
HardwareAddress = GetHardwareAddress (inf),
Addresses = CollectAddresses (inf)
Expand Down Expand Up @@ -220,5 +221,12 @@ byte[] GetHardwareAddress (MNetworkInterface inf)

return ret;
}

static bool IsLoopbackInterface (MNetworkInterface inf)
{
// Android 30 will not tell us the interface type if the app targets API 30, we need to look at the
// name then.
return inf.NetworkInterfaceType == NetworkInterfaceType.Loopback || String.Compare ("lo", inf.Name, StringComparison.OrdinalIgnoreCase) == 0;
}
}
}