diff options
author | Marek Safar <marek.safar@gmail.com> | 2016-10-18 00:30:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-18 00:30:34 +0300 |
commit | 804794a9a97ec9dc2fc4521341502e0abd6eb7bd (patch) | |
tree | ff947f29376af6db93232b9c42fe5f82533286f7 | |
parent | 1998314ee2e5367620c9c9dee193552716ee22cb (diff) | |
parent | c439b678878aa9ebeee1ce29853a295f5184b19f (diff) |
Merge pull request #3781 from grendello/networkinfoatkcocoa-test
With Android 7.0 (Nougat) it is no longer possible to read some
-rw-r--r-- | mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs b/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs index d1bf2e763b0..56d0e4d61f9 100644 --- a/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs +++ b/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs @@ -631,6 +631,19 @@ namespace System.Net.NetworkInformation { string iface_operstate_path; string iface_flags_path; +#if MONODROID + [DllImport ("__Internal")] + protected static extern int _monodroid_get_android_api_level (); + + [DllImport ("__Internal")] + protected static extern bool _monodroid_get_network_interface_up_state (string ifname, ref bool is_up); + + [DllImport ("__Internal")] + protected static extern bool _monodroid_get_network_interface_supports_multicast (string ifname, ref bool supports_multicast); + + bool android_use_java_api; +#endif + internal string IfacePath { get { return iface_path; } } @@ -641,6 +654,9 @@ namespace System.Net.NetworkInformation { iface_path = "/sys/class/net/" + name + "/"; iface_operstate_path = iface_path + "operstate"; iface_flags_path = iface_path + "flags"; +#if MONODROID + android_use_java_api = _monodroid_get_android_api_level () >= 24; +#endif } public override IPInterfaceProperties GetIPProperties () @@ -659,6 +675,23 @@ namespace System.Net.NetworkInformation { public override OperationalStatus OperationalStatus { get { +#if MONODROID + if (android_use_java_api) { + // Starting from API 24 (Android 7 "Nougat") Android restricts access to many + // files in the /sys filesystem (see https://code.google.com/p/android/issues/detail?id=205565 + // for more information) and therefore we are forced to call into Java API in + // order to get the information. Alas, what we can obtain in this way is quite + // limited. In the case of OperationalStatus we can only determine whether the + // interface is up or down. There is a way to get more detailed information but + // it requires an instance of the Android Context class which is not available + // to us here. + bool is_up = false; + if (_monodroid_get_network_interface_up_state (Name, ref is_up)) + return is_up ? OperationalStatus.Up : OperationalStatus.Down; + else + return OperationalStatus.Unknown; + } +#endif if (!Directory.Exists (iface_path)) return OperationalStatus.Unknown; @@ -695,6 +728,17 @@ namespace System.Net.NetworkInformation { public override bool SupportsMulticast { get { +#if MONODROID + if (android_use_java_api) { + // Starting from API 24 (Android 7 "Nougat") Android restricts access to many + // files in the /sys filesystem (see https://code.google.com/p/android/issues/detail?id=205565 + // for more information) and therefore we are forced to call into Java API in + // order to get the information. + bool supports_multicast = false; + _monodroid_get_network_interface_supports_multicast (Name, ref supports_multicast); + return supports_multicast; + } +#endif if (!Directory.Exists (iface_path)) return false; |