* Fix some crashing tests

* Replace all versions of PlatformVersion with BCL

* maybe this crases the compiler?

* Fix this too

* this

* :')

* Make sure all the bits are installed

* - fix typeface create for API 23 in tests

* this

* Skip the tests on older androids

Co-authored-by: Rui Marinho <me@ruimarinho.net>
Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
This commit is contained in:
Matthew Leibowitz 2022-04-08 15:04:58 +02:00 коммит произвёл GitHub
Родитель 3956bbf194
Коммит e171d1fe74
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
15 изменённых файлов: 79 добавлений и 25 удалений

Просмотреть файл

@ -72,6 +72,11 @@ stages:
# androidApiLevels: [ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21 ] # fix the issue of getting the test results off
iosVersions: [ 'latest', '14.5', '13.7', '12.4' ]
provisionatorChannel: ${{ parameters.provisionatorChannel }}
${{ if not(or(parameters.BuildEverything, and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'devdiv')))) }}:
androidApiLevels: [ 30, 23 ]
# androidApiLevels: [ 30, 21 ] # fix the issue of getting the test results off
iosVersions: [ 'latest' ]
provisionatorChannel: ${{ parameters.provisionatorChannel }}
projects:
- name: essentials
desc: Essentials

Просмотреть файл

@ -100,16 +100,25 @@ string ANDROID_API_SDKS = Environment.GetEnvironmentVariable ("ANDROID_API_SDKS"
if(String.IsNullOrWhiteSpace(ANDROID_API_SDKS))
{
AndroidSdk()
.ApiLevel((AndroidApiLevel)21)
.ApiLevel((AndroidApiLevel)22)
.ApiLevel((AndroidApiLevel)23)
.ApiLevel((AndroidApiLevel)24)
.ApiLevel((AndroidApiLevel)28)
.ApiLevel((AndroidApiLevel)29)
.ApiLevel((AndroidApiLevel)30)
.ApiLevel((AndroidApiLevel)31)
.VirtualDevice(
"Android_API30",
AndroidApiLevel.R,
AndroidSystemImageApi.GooglePlayStore,
AndroidSystemImageAbi.x86,
.VirtualDevice(
"Android_API23",
(AndroidApiLevel)23,
AndroidSystemImageApi.Google,
AndroidSystemImageAbi.x86,
AndroidVirtualDevice.NEXUS_5X)
.VirtualDevice(
"Android_API30",
AndroidApiLevel.R,
AndroidSystemImageApi.GooglePlayStore,
AndroidSystemImageAbi.x86,
AndroidVirtualDevice.NEXUS_5X)
.SdkManagerPackage ("build-tools;29.0.3");
}

Просмотреть файл

@ -64,7 +64,7 @@ namespace Microsoft.Maui.Controls.Handlers.Items
{
return;
}
if (PlatformVersion.IsAtLeast(Android.OS.BuildVersionCodes.M))
if (OperatingSystem.IsAndroidVersionAtLeast(23))
{
// We're looking for the foreground ripple effect, which is not available on older APIs
// Limiting this to Marshmallow and newer, because View.setForeground() is not available on lower APIs

Просмотреть файл

@ -321,7 +321,7 @@ namespace Microsoft.Maui.Controls.Platform
customLocalStateData.SourcePlatformView = v;
customLocalStateData.SourceElement = element;
if (PlatformVersion.IsAtLeast(24))
if (OperatingSystem.IsAndroidVersionAtLeast(24))
v.StartDragAndDrop(data, dragShadowBuilder, customLocalStateData, (int)ADragFlags.Global | (int)ADragFlags.GlobalUriRead);
else
#pragma warning disable CS0618 // Type or member is obsolete

Просмотреть файл

@ -175,7 +175,7 @@ namespace Microsoft.Maui.Controls.Platform
public static bool UseGradients(this GradientDrawable gradientDrawable)
{
if (!PlatformVersion.IsAtLeast(24))
if (!OperatingSystem.IsAndroidVersionAtLeast(24))
return false;
var colors = gradientDrawable.GetColors();

Просмотреть файл

@ -319,7 +319,7 @@ namespace Microsoft.Maui.Controls.Platform
menuitem.SetOnMenuItemClickListener(new GenericMenuClickListener(((IMenuItemController)item).Activate));
if (item.Order != ToolbarItemOrder.Secondary && !PlatformVersion.IsAtLeast(26) && (tintColor != null && tintColor != null))
if (item.Order != ToolbarItemOrder.Secondary && !OperatingSystem.IsAndroidVersionAtLeast(26) && (tintColor != null && tintColor != null))
{
var view = toolbar.FindViewById(menuitem.ItemId);
if (view is ATextView textView)

Просмотреть файл

@ -158,7 +158,7 @@ namespace Microsoft.Maui.Controls.Platform
{
platformView.ImportantForAccessibility = ImportantForAccessibility.Auto;
if (PlatformVersion.IsAtLeast(26))
if (OperatingSystem.IsAndroidVersionAtLeast(26))
platformView.SetFocusable(ViewFocusability.FocusableAuto);
if (platformView is ViewGroup vg)
@ -169,7 +169,7 @@ namespace Microsoft.Maui.Controls.Platform
{
platformView.ImportantForAccessibility = ImportantForAccessibility.NoHideDescendants;
if (PlatformVersion.IsAtLeast(26))
if (OperatingSystem.IsAndroidVersionAtLeast(26))
platformView.SetFocusable(ViewFocusability.NotFocusable);
// Without setting this the keyboard will still navigate to components behind the modal page

Просмотреть файл

@ -135,7 +135,7 @@ namespace Microsoft.Maui
result = Typeface.Create(fontFamily, style);
}
if (PlatformVersion.IsAtLeast(28))
if (OperatingSystem.IsAndroidVersionAtLeast(28))
result = Typeface.Create(result, (int)weight, italic);
else
result = Typeface.Create(result, style);

Просмотреть файл

@ -21,7 +21,7 @@ namespace Microsoft.Maui.Platform
var intent = pm.GetLaunchIntentForPackage(platformApplication.PackageName!)!;
intent.AddFlags(ActivityFlags.NewTask);
intent.AddFlags(ActivityFlags.MultipleTask);
if (PlatformVersion.Supports(PlatformApis.LaunchAdjacent))
if (OperatingSystem.IsAndroidVersionAtLeast(24))
intent.AddFlags(ActivityFlags.LaunchAdjacent);
intent.PutExtras(bundle);

Просмотреть файл

@ -73,7 +73,7 @@ namespace Microsoft.Maui.Platform
if (drawable == null)
return;
if (PlatformVersion.Supports(PlatformApis.BlendModeColorFilter))
if (OperatingSystem.IsAndroidVersionAtLeast(29))
{
BlendMode? filterMode29 = GetFilterMode(mode);

Просмотреть файл

@ -1,4 +1,5 @@
using Android.Views;
using System;
using Android.Views;
using Android.Widget;
using AndroidX.Core.View;
using AndroidX.Core.View.Accessibility;
@ -36,7 +37,7 @@ namespace Microsoft.Maui.Platform
if (!string.IsNullOrEmpty(hint))
{
// info HintText won't read anything back when using TalkBack pre API 26
if (PlatformVersion.IsAtLeast(26))
if (OperatingSystem.IsAndroidVersionAtLeast(26))
{
info.HintText = hint;

Просмотреть файл

@ -21,7 +21,7 @@ namespace Microsoft.Maui.Platform
{
var newText = label.Text ?? string.Empty;
if (PlatformVersion.IsAtLeast(24))
if (OperatingSystem.IsAndroidVersionAtLeast(24))
textView.SetText(Html.FromHtml(newText, FromHtmlOptions.ModeCompact), BufferType.Spannable);
else
#pragma warning disable CS0618 // Type or member is obsolete

Просмотреть файл

@ -207,7 +207,7 @@ namespace Microsoft.Maui.DeviceTests
// AccessibilityHeading is only available on API 28+
// With lower Apis you use ViewCompat.SetAccessibilityHeading
// but there exists no ViewCompat.GetAccessibilityHeading
if (PlatformVersion.IsAtLeast(28))
if (OperatingSystem.IsAndroidVersionAtLeast(28))
return ((View)viewHandler.PlatformView).AccessibilityHeading
? SemanticHeadingLevel.Level1 : SemanticHeadingLevel.None;

Просмотреть файл

@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using Android.Widget;
using Microsoft.Maui.DeviceTests.Stubs;
@ -33,7 +34,7 @@ namespace Microsoft.Maui.DeviceTests
double GetNativeMinimum(SliderHandler sliderHandler)
{
if (PlatformVersion.Supports(PlatformApis.SeekBarSetMin))
if (OperatingSystem.IsAndroidVersionAtLeast(26))
{
return GetNativeSlider(sliderHandler).Min;
}

Просмотреть файл

@ -1,6 +1,6 @@
using Android.App;
using System;
using Android.App;
using Android.Graphics;
using Java.Interop;
using Xunit;
namespace Microsoft.Maui.DeviceTests;
@ -20,25 +20,63 @@ public partial class FontManagerTests : TestBase
[InlineData("insubfolder.ttf#insubfolder", "Fonts/insubfolder.ttf")]
public void CanLoadFonts(string fontName, string assetName)
{
// skip on older androids for now
// https://github.com/dotnet/maui/issues/5903
if (!OperatingSystem.IsAndroidVersionAtLeast(28))
return;
var fontWeight = FontWeight.Regular;
var fontStyle = TypefaceStyle.Normal;
var fontSlant = false;
Typeface expected;
var expectedTypeface = Typeface.CreateFromAsset(Application.Context.Assets, assetName);
if (OperatingSystem.IsAndroidVersionAtLeast(28))
expected = Typeface.Create(expectedTypeface, (int)fontWeight, fontSlant);
else
expected = Typeface.Create(expectedTypeface, fontStyle);
Assert.NotEqual(Typeface.Default, expected);
var registrar = new FontRegistrar(fontLoader: null);
registrar.Register("dokdo_regular.ttf", "myalias");
var manager = new FontManager(registrar);
var actual = manager.GetTypeface(Font.OfSize(fontName, 12, fontWeight));
var expected = Typeface.Create(Typeface.CreateFromAsset(Application.Context.Assets, assetName), (int)fontWeight, italic: false);
Assert.NotEqual(Typeface.Default, actual);
Assert.True(expected.Equals(actual));
}
[Fact]
public void CanLoadEmbeddedFont()
{
// skip on older androids for now
// https://github.com/dotnet/maui/issues/5903
if (!OperatingSystem.IsAndroidVersionAtLeast(28))
return;
var fontName = "FooBarFont";
var fontWeight = FontWeight.Regular;
var registrar = new FontRegistrar(new EmbeddedFontLoader ());
var fontStyle = TypefaceStyle.Normal;
var fontSlant = false;
var registrar = new FontRegistrar(new EmbeddedFontLoader());
registrar.Register("dokdo_regular.ttf", fontName, GetType().Assembly);
var manager = new FontManager(registrar);
var actual = manager.GetTypeface(Font.OfSize(fontName, 12, fontWeight));
var defaultFont = Typeface.Create(Typeface.Create(fontName, TypefaceStyle.Normal), (int)fontWeight, italic: false);
Assert.False(defaultFont.Equals(actual));
Assert.NotEqual(Typeface.Default, actual);
Typeface expected;
var expectedTypeface = Typeface.Create(fontName, TypefaceStyle.Normal);
if (OperatingSystem.IsAndroidVersionAtLeast(28))
expected = Typeface.Create(expectedTypeface, (int)fontWeight, italic: fontSlant);
else
expected = Typeface.Create(expectedTypeface, fontStyle);
Assert.NotEqual(Typeface.Default, expected);
Assert.False(expected.Equals(actual));
}
}