Skip to content

Commit

Permalink
Merge pull request unoplatform#5597 from pkar70/ConnectionProfileDeOb…
Browse files Browse the repository at this point in the history
…solete

chore: ConnectionProfile de-obsoleting
  • Loading branch information
mergify[bot] authored Jun 4, 2021
2 parents 612ebb7 + 77751ab commit 540091f
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,45 @@ private ConnectionProfile()
{
NetworkInformation.VerifyNetworkStateAccess();
_connectivityManager = (AndroidConnectivityManager)ContextHelper.Current.GetSystemService(Context.ConnectivityService);
#pragma warning disable CS0618 // Type or member is obsolete
NetworkInfo info = _connectivityManager.ActiveNetworkInfo;
if (info?.IsConnected == true)

if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.LollipopMr1)
{
IsWwanConnectionProfile = IsConnectionWwan(info.Type);
IsWlanConnectionProfile = IsConnectionWlan(info.Type);
var activeNetwork = _connectivityManager.ActiveNetwork;
if (activeNetwork != null)
{
var netCaps = _connectivityManager.GetNetworkCapabilities(activeNetwork);
if (netCaps != null)
{
IsWlanConnectionProfile = netCaps.HasTransport(Android.Net.TransportType.Wifi);
IsWwanConnectionProfile = netCaps.HasTransport(Android.Net.TransportType.Cellular);
}
}
}
else
{
#pragma warning disable CS0618 // Type or member is obsolete
NetworkInfo info = _connectivityManager.ActiveNetworkInfo;
if (info?.IsConnected == true)
{
IsWwanConnectionProfile = IsConnectionWwan(info.Type);
IsWlanConnectionProfile = IsConnectionWlan(info.Type);
}
#pragma warning restore CS0618 // Type or member is obsolete
}
}

public ConnectionCost GetConnectionCost() =>
new ConnectionCost(
public ConnectionCost GetConnectionCost()
{
if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.JellyBean)
{ // below API 16, we don't have IsActiveNetworkMetered method
return new ConnectionCost(NetworkCostType.Unknown);
}

return new ConnectionCost(
_connectivityManager.IsActiveNetworkMetered ?
NetworkCostType.Fixed : // we currently don't make distinction between variable and fixed metered connection on Android
NetworkCostType.Unrestricted);
}

/// <summary>
/// Code based on Xamarin.Essentials implementation with some modifications.
Expand Down

0 comments on commit 540091f

Please sign in to comment.