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

NetworkInterface.GetAllNetworkInterfaces() on Android leads to FileNotFoundException #77441

Closed
kdotdk opened this issue Oct 25, 2022 · 12 comments

Comments

@kdotdk
Copy link

kdotdk commented Oct 25, 2022

Description

This has been reported previously in #3617 but problem still exists.

I have tried the following combinations:

  • Works on Android 9 API 28 (Physical Tablet)
  • Works on Android 10 API 29 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 11 API 30 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 12 API 31 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 13 API 32 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Windows 11 Windows Subsystem for Android Version 2207.40000.8.0

Steps to Reproduce

  1. Get MAUI sample app

  2. Add Permissions:
    [assembly: UsesPermission(Android.Manifest.Permission.AccessNetworkState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeNetworkState)]
    [assembly: UsesPermission(Android.Manifest.Permission.AccessWifiState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeWifiMulticastState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeWifiState)]
    [assembly: UsesPermission(Android.Manifest.Permission.Internet)]

  3. Add a call to System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() on a button click (E.g. in AboutPage TabCommand)

Result the application crash with FileNotFoundException.

Link to public reproduction project repository

https://github.com/dotnet/maui-samples/tree/main/6.0/Fundamentals/Shell

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11-13 + Windows Subsystem for Android Version 2207.40000.8.0

Did you find any workaround?

No response

Relevant log output

windows-subsystem-android-crash-log.txt

@PureWeen PureWeen transferred this issue from dotnet/maui Oct 25, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 25, 2022
@jonathanpeppers
Copy link
Member

/cc @grendello it's possible this is something in xamarin/xamarin-android

@grendello
Copy link
Contributor

@jonathanpeppers it's possible, although the code that lives in xamarin/xamarin-android (and which was moved to dotnet/runtime recently) deals with enumerating interface addresses, not interfaces themselves. The code which enumerates interfaces lives in dotnet/runtime. I'll try to repro this issue and when/if I see the trace I'll be able to tell more.

@grendello
Copy link
Contributor

Note that it might be due to tightened security on Android, since they have been gradually restricting access to bits and pieces of information about the system.

@kdotdk
Copy link
Author

kdotdk commented Oct 26, 2022

  • Issue updated with used permissions
  • Log from Windows Subsystem for Android Windows 11 added

Note first line:
10-26 08:37:07.924 4736 4736 W DOTNET_NETLINK: Failed to bind to the netlink socket. Permission denied

@grendello
Copy link
Contributor

Yes, that's what it appears to be. xamarin/xamarin-android does use netlink when getifaddrs is not available in bionic (the Android libc). dotnet/runtime ported xamarin/xamarin-android getifaddrs implementation recently. getifaddrs is available (at least as a public API) on Android >= 24 (this is a compile time dependency), so if the runtime is built against an earlier version of Android API (both Xamarin.Android and dotnet/runtime are built against API 21) the netlink implementation is very likely used.

Until very recently the dotnet/runtime implementation always used the netlink implementation, with the commit linked to previously switching to the same strategy as the implementation in Xamarin.Android, to dynamically look up getifaddrs and, if found, use that instead of the netlink code. This fix might be required for the enumeration to work on Android 30 and above.

/cc @simonrozsival was your fix above backported to net6? Or is it going to be part of only net7+?

@ghost
Copy link

ghost commented Oct 26, 2022

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

This has been reported previously in #3617 but problem still exists.

I have tried the following combinations:

  • Works on Android 9 API 28 (Physical Tablet)
  • Works on Android 10 API 29 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 11 API 30 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 12 API 31 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 13 API 32 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Windows 11 Windows Subsystem for Android Version 2207.40000.8.0

Steps to Reproduce

  1. Get MAUI sample app

  2. Add Permissions:
    [assembly: UsesPermission(Android.Manifest.Permission.AccessNetworkState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeNetworkState)]
    [assembly: UsesPermission(Android.Manifest.Permission.AccessWifiState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeWifiMulticastState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeWifiState)]
    [assembly: UsesPermission(Android.Manifest.Permission.Internet)]

  3. Add a call to System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() on a button click (E.g. in AboutPage TabCommand)

Result the application crash with FileNotFoundException.

Link to public reproduction project repository

https://github.com/dotnet/maui-samples/tree/main/6.0/Fundamentals/Shell

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11-13 + Windows Subsystem for Android Version 2207.40000.8.0

Did you find any workaround?

No response

Relevant log output

windows-subsystem-android-crash-log.txt

Author: kdotdk
Assignees: -
Labels:

os-android, untriaged

Milestone: -

@ghost
Copy link

ghost commented Oct 26, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

This has been reported previously in #3617 but problem still exists.

I have tried the following combinations:

  • Works on Android 9 API 28 (Physical Tablet)
  • Works on Android 10 API 29 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 11 API 30 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 12 API 31 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Android 13 API 32 (Visual Studio Pixel 5 Emulator, Win 10)
  • Fails on Windows 11 Windows Subsystem for Android Version 2207.40000.8.0

Steps to Reproduce

  1. Get MAUI sample app

  2. Add Permissions:
    [assembly: UsesPermission(Android.Manifest.Permission.AccessNetworkState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeNetworkState)]
    [assembly: UsesPermission(Android.Manifest.Permission.AccessWifiState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeWifiMulticastState)]
    [assembly: UsesPermission(Android.Manifest.Permission.ChangeWifiState)]
    [assembly: UsesPermission(Android.Manifest.Permission.Internet)]

  3. Add a call to System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() on a button click (E.g. in AboutPage TabCommand)

Result the application crash with FileNotFoundException.

Link to public reproduction project repository

https://github.com/dotnet/maui-samples/tree/main/6.0/Fundamentals/Shell

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11-13 + Windows Subsystem for Android Version 2207.40000.8.0

Did you find any workaround?

No response

Relevant log output

windows-subsystem-android-crash-log.txt

Author: kdotdk
Assignees: -
Labels:

area-System.Net, os-android, untriaged

Milestone: -

@simonrozsival
Copy link
Member

@grendello the most recent fix should be included in a servicing release of .NET 6 soon: #77260

@kdotdk
Copy link
Author

kdotdk commented Dec 14, 2022

Have tried with new .Net 6.0.12.
It works on Android 11 API 30 (Visual Studio Pixel 5 Emulator, Win 10) 👍
(I have not access to Physical Android Device )

@akoeplinger
Copy link
Member

Thanks for the feedback and great to hear it works now! I assume we can close this issue then or is there something left?

@kdotdk
Copy link
Author

kdotdk commented Dec 16, 2022

I have no other issues for now

@kdotdk kdotdk closed this as completed Dec 16, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 16, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 15, 2023
@karelz karelz added this to the 8.0.0 milestone Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants