forked from xamarin/Essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectivity.uwp.cs
77 lines (68 loc) · 2.77 KB
/
Connectivity.uwp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections.Generic;
using System.Linq;
using Windows.Networking.Connectivity;
namespace Xamarin.Essentials
{
public static partial class Connectivity
{
static void StartListeners() =>
NetworkInformation.NetworkStatusChanged += NetworkStatusChanged;
static void NetworkStatusChanged(object sender) =>
OnConnectivityChanged();
static void StopListeners() =>
NetworkInformation.NetworkStatusChanged -= NetworkStatusChanged;
static NetworkAccess PlatformNetworkAccess
{
get
{
var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null)
return NetworkAccess.Unknown;
var level = profile.GetNetworkConnectivityLevel();
switch (level)
{
case NetworkConnectivityLevel.LocalAccess:
return NetworkAccess.Local;
case NetworkConnectivityLevel.InternetAccess:
return NetworkAccess.Internet;
case NetworkConnectivityLevel.ConstrainedInternetAccess:
return NetworkAccess.ConstrainedInternet;
default:
return NetworkAccess.None;
}
}
}
static IEnumerable<ConnectionProfile> PlatformConnectionProfiles
{
get
{
var networkInterfaceList = NetworkInformation.GetConnectionProfiles();
foreach (var interfaceInfo in networkInterfaceList.Where(nii => nii.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.None))
{
var type = ConnectionProfile.Unknown;
if (interfaceInfo.NetworkAdapter != null)
{
// http://www.iana.org/assignments/ianaiftype-mib/ianaiftype-mib
switch (interfaceInfo.NetworkAdapter.IanaInterfaceType)
{
case 6:
type = ConnectionProfile.Ethernet;
break;
case 71:
type = ConnectionProfile.WiFi;
break;
case 243:
case 244:
type = ConnectionProfile.Cellular;
break;
// xbox wireless, can skip
case 281:
continue;
}
}
yield return type;
}
}
}
}
}