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

chore: ConnectionProfile de-obsoleting #5597

Merged
merged 1 commit into from
Jun 4, 2021
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
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