Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

GH-643: Add Android P targeting and support 28 support #669

Merged
merged 8 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ List all API changes here (or just put None), example:

Added:

- string - string Class.Property { get; set; }
- void Class.Method();
- `string Class.Property { get; set; }`
- `void Class.Method();`

Changed:

- object Cell.OldPropertyName => object Cell.NewPropertyName
- `object Cell.OldPropertyName` => `object Cell.NewPropertyName`

If there is an entirely new API, then you can use a more verbose style:

```csharp
public static class NewClass {
public static int SomeProperty { get; set; }
public static void SomeMethod(string value);
}
```


### Behavioral Changes ###

Expand Down
16 changes: 8 additions & 8 deletions DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.20" />
Expand Down
18 changes: 9 additions & 9 deletions DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.6.60" PrivateAssets="All" />
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.6.61" PrivateAssets="All" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.3.3" />
<PackageReference Include="UnitTests.HeadlessRunner" Version="2.0.0" />
Expand All @@ -48,13 +48,13 @@
</SDKReference>
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) ">
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion DeviceTests/DeviceTests.UWP/DeviceTests.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UnitTests.HeadlessRunner" Version="2.0.0" />
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.9" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.3.3" />
Expand Down
2 changes: 1 addition & 1 deletion DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.20" />
<PackageReference Include="UnitTests.HeadlessRunner" Version="2.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ If building on Visual Studio 2017, you will need the following SDKs and workload

### You will need the following SDKs

* Android 8.1 SDK Installed
* Android 9.0, 8.1, 8.0, 7.1, 7.0, & 6.0 SDK Installed
* UWP 10.0.16299 SDK Installed

If using Visual Studio for Mac the project can be built at the command line with MSBuild. To change the project type that you are working with, simply edit Xamarin.Essentials.csproj and modify the TargetFrameworks for only the project type you want to use.
Expand Down
24 changes: 12 additions & 12 deletions Samples/Samples.Android/Samples.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.10.0" />
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="27.0.2.1" />
<PackageReference Include="Microsoft.AppCenter" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.13.0" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Samples/Samples.UWP/Samples.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.10.0" />
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Microsoft.AppCenter" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.13.0" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.5" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Samples/Samples.iOS/Samples.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.10.0" />
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Microsoft.AppCenter" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.13.0" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Samples/Samples/Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AppCenter" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.10.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.10.0" />
<PackageReference Include="Xamarin.Forms" Version="3.3.0.967583" />
<PackageReference Include="Microsoft.AppCenter" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="1.13.0" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="1.13.0" />
<PackageReference Include="Xamarin.Forms" Version="3.5.0.129452" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions Xamarin.Essentials/Browser/Browser.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ static Task<bool> PlatformOpenAsync(Uri uri, BrowserLaunchMode launchMode)
var tabsIntent = tabsBuilder.Build();
tabsIntent.Intent.SetFlags(ActivityFlags.ClearTop);
tabsIntent.Intent.SetFlags(ActivityFlags.NewTask);
#if __ANDROID_25__
tabsIntent.LaunchUrl(Platform.AppContext, nativeUri);
#else
tabsIntent.LaunchUrl(Platform.GetCurrentActivity(true), nativeUri);
#endif
break;
case BrowserLaunchMode.External:
var intent = new Intent(Intent.ActionView, nativeUri);
Expand Down
12 changes: 12 additions & 0 deletions Xamarin.Essentials/Connectivity/Connectivity.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ static void StartListeners()

conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

#pragma warning disable CS0618 // Type or member is obsolete
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant has been deprecated in favor of https://developer.android.com/reference/android/net/ConnectivityManager.html#registerNetworkCallback(android.net.NetworkRequest,%20android.app.PendingIntent)

IMHO this should be replaced as this means that future Android versions will not support this anymore.

Platform.AppContext.RegisterReceiver(conectivityReceiver, new IntentFilter(ConnectivityManager.ConnectivityAction));
#pragma warning restore CS0618 // Type or member is obsolete
}

static void StopListeners()
Expand Down Expand Up @@ -64,7 +66,9 @@ static NetworkAccess PlatformNetworkAccess

var info = manager.GetNetworkInfo(network);

#pragma warning disable CS0618 // Type or member is obsolete
if (info == null || !info.IsAvailable)
#pragma warning restore CS0618 // Type or member is obsolete
continue;

// Check to see if it has the internet capability
Expand Down Expand Up @@ -95,12 +99,16 @@ static NetworkAccess PlatformNetworkAccess

void ProcessNetworkInfo(NetworkInfo info)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (info == null || !info.IsAvailable)
#pragma warning restore CS0618 // Type or member is obsolete
return;

if (info.IsConnected)
currentAccess = IsBetterAccess(currentAccess, NetworkAccess.Internet);
#pragma warning disable CS0618 // Type or member is obsolete
else if (info.IsConnectedOrConnecting)
#pragma warning restore CS0618 // Type or member is obsolete
currentAccess = IsBetterAccess(currentAccess, NetworkAccess.ConstrainedInternet);
}

Expand Down Expand Up @@ -154,10 +162,12 @@ static IEnumerable<ConnectionProfile> PlatformConnectionProfiles

ConnectionProfile? ProcessNetworkInfo(NetworkInfo info)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (info == null || !info.IsAvailable || !info.IsConnectedOrConnecting)
return null;

return GetConnectionType(info.Type, info.TypeName);
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Expand Down Expand Up @@ -219,7 +229,9 @@ public ConnectivityBroadcastReceiver(Action onChanged) =>

public override async void OnReceive(Context context, Intent intent)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (intent.Action != ConnectivityManager.ConnectivityAction)
#pragma warning restore CS0618 // Type or member is obsolete
return;

// await 500ms to ensure that the the connection manager updates
Expand Down
4 changes: 3 additions & 1 deletion Xamarin.Essentials/Email/Email.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ static Intent CreateIntent(EmailMessage message)
if (message?.BodyFormat == EmailBodyFormat.Html)
{
ISpanned html;
if (Platform.HasApiLevel(BuildVersionCodes.N))
#if __ANDROID_24__
if (Platform.HasApiLevelN)
{
html = Html.FromHtml(message.Body, FromHtmlOptions.ModeLegacy);
}
else
#endif
{
#pragma warning disable CS0618 // Type or member is obsolete
html = Html.FromHtml(message.Body);
Expand Down
7 changes: 6 additions & 1 deletion Xamarin.Essentials/PhoneDialer/PhoneDialer.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ static void PlatformOpen(string number)
ValidateOpen(number);

var phoneNumber = string.Empty;
if (Platform.HasApiLevel(BuildVersionCodes.N))
#if __ANDROID_24__
if (Platform.HasApiLevelN)
phoneNumber = PhoneNumberUtils.FormatNumber(number, Java.Util.Locale.GetDefault(Java.Util.Locale.Category.Format).Country);
else if (Platform.HasApiLevel(BuildVersionCodes.Lollipop))
#else
if (Platform.HasApiLevel(BuildVersionCodes.Lollipop))
#endif

phoneNumber = PhoneNumberUtils.FormatNumber(number, Java.Util.Locale.Default.Country);
else
#pragma warning disable CS0618
Expand Down
42 changes: 40 additions & 2 deletions Xamarin.Essentials/Platform/Platform.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,41 @@ internal static bool IsIntentSupported(Intent intent)
return activities.Any();
}

internal static bool HasApiLevelN =>
#if __ANDROID_24__
HasApiLevel(BuildVersionCodes.N);
#else
false;
#endif

internal static bool HasApiLevelNMr1 =>
#if __ANDROID_25__
HasApiLevel(BuildVersionCodes.NMr1);
#else
false;
#endif

internal static bool HasApiLevelO =>
#if __ANDROID_26__
HasApiLevel(BuildVersionCodes.O);
#else
false;
#endif

internal static bool HasApiLevelOMr1 =>
#if __ANDROID_27__
HasApiLevel(BuildVersionCodes.OMr1);
#else
false;
#endif

internal static bool HasApiLevelP =>
#if __ANDROID_28__
HasApiLevel(BuildVersionCodes.P);
#else
false;
#endif

internal static bool HasApiLevel(BuildVersionCodes versionCode) =>
(int)Build.VERSION.SdkInt >= (int)versionCode;

Expand Down Expand Up @@ -92,8 +127,10 @@ internal static Java.Util.Locale GetLocale()
{
var resources = AppContext.Resources;
var config = resources.Configuration;
if (HasApiLevel(BuildVersionCodes.N))
#if __ANDROID_24__
if (HasApiLevelN)
return config.Locales.Get(0);
#endif

return config.Locale;
}
Expand All @@ -103,7 +140,8 @@ internal static void SetLocale(Java.Util.Locale locale)
Java.Util.Locale.Default = locale;
var resources = AppContext.Resources;
var config = resources.Configuration;
if (HasApiLevel(BuildVersionCodes.N))

if (HasApiLevelN)
config.SetLocale(locale);
else
config.Locale = locale;
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Vibration/Vibration.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void PlatformVibrate(TimeSpan duration)

var time = (long)duration.TotalMilliseconds;
#if __ANDROID_26__
if (Platform.HasApiLevel(BuildVersionCodes.O))
if (Platform.HasApiLevelO)
{
Platform.Vibrator.Vibrate(VibrationEffect.CreateOneShot(time, VibrationEffect.DefaultAmplitude));
return;
Expand Down
Loading