From a821faa8e08e31ce41bb89180a771ad6f2a91b94 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 28 Mar 2023 15:36:29 -0500 Subject: [PATCH 1/4] [tests] add test for Microsoft.Intune Context: https://www.nuget.org/packages/Microsoft.Intune.Maui.Essentials.android/9.5.2-beta The `Microsoft.Intune.Maui.Essentials.android` makes use of specific MSBuild targets and "remapping" features. We should add a test verifying that it stays working over time. --- .../Android/KnownPackages.cs | 4 +++ .../Tests/InstallAndRunTests.cs | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs index 5caf109940b..baac0375292 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs @@ -592,6 +592,10 @@ public static class KnownPackages Id = "SkiaSharp.Views", Version = "2.88.3", }; + public static Package Microsoft_Intune_Maui_Essentials_android = new Package { + Id = "Microsoft.Intune.Maui.Essentials.android", + Version = "10.0.0-beta", + }; } } diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 084db3dfc4c..6c60bbbf221 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -1130,5 +1130,32 @@ public void FixLegacyResourceDesignerStep ([Values (true, false)] bool isRelease Assert.IsTrue (didLaunch, "Activity should have started."); } } + + [Test] + public void MicrosoftIntune ([Values (false, true)] bool isRelease) + { + if (!Builder.UseDotNet) + Assert.Ignore ("Test is only valid in .NET 7+"); + proj = new XamarinAndroidApplicationProject { + IsRelease = isRelease, + PackageReferences = { + KnownPackages.AndroidXAppCompat, + KnownPackages.Microsoft_Intune_Maui_Essentials_android, + }, + }; + proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity"); + var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" }; + proj.SetAndroidSupportedAbis (abis); + builder = CreateApkBuilder (); + builder.BuildLogFile = "install.log"; + Assert.IsTrue (builder.Install (proj), "Install should have succeeded."); + + RunProjectAndAssert (proj, builder); + + var timeoutInSeconds = 120; + var didStart = WaitForActivityToStart (proj.PackageName, "MainActivity", + Path.Combine (Root, builder.ProjectDirectory, "startup-logcat.log"), timeoutInSeconds); + Assert.IsTrue (didStart, "Activity should have started."); + } } } From d9f1cd07b945d13059e594e04748926683d768db Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 27 Oct 2023 09:21:19 -0500 Subject: [PATCH 2/4] Use `@style/Theme.AppCompat.Light.DarkActionBar` Have to use a valid AppCompat theme. --- .../Tests/InstallAndRunTests.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 6c60bbbf221..05eb8407bda 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -1135,7 +1135,7 @@ public void FixLegacyResourceDesignerStep ([Values (true, false)] bool isRelease public void MicrosoftIntune ([Values (false, true)] bool isRelease) { if (!Builder.UseDotNet) - Assert.Ignore ("Test is only valid in .NET 7+"); + Assert.Ignore ("Test is only valid in .NET 8+"); proj = new XamarinAndroidApplicationProject { IsRelease = isRelease, PackageReferences = { @@ -1143,7 +1143,9 @@ public void MicrosoftIntune ([Values (false, true)] bool isRelease) KnownPackages.Microsoft_Intune_Maui_Essentials_android, }, }; - proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity"); + proj.MainActivity = proj.DefaultMainActivity + .Replace ("Icon = \"@drawable/icon\")]", "Icon = \"@drawable/icon\", Theme = \"@style/Theme.AppCompat.Light.DarkActionBar\")]") + .Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity"); var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" }; proj.SetAndroidSupportedAbis (abis); builder = CreateApkBuilder (); @@ -1152,10 +1154,10 @@ public void MicrosoftIntune ([Values (false, true)] bool isRelease) RunProjectAndAssert (proj, builder); - var timeoutInSeconds = 120; - var didStart = WaitForActivityToStart (proj.PackageName, "MainActivity", - Path.Combine (Root, builder.ProjectDirectory, "startup-logcat.log"), timeoutInSeconds); - Assert.IsTrue (didStart, "Activity should have started."); + WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log")); + bool didLaunch = WaitForActivityToStart (proj.PackageName, "MainActivity", + Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30); + Assert.IsTrue (didLaunch, "Activity should have started."); } } } From 9335f42f43bf0e1abe9cb3f76251a44b08882385 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 27 Oct 2023 11:47:24 -0500 Subject: [PATCH 3/4] Assert `MainActivity.onMAMCreate` exists in `classes.dex` --- tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 05eb8407bda..1b36d4cfd45 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -1152,6 +1152,13 @@ public void MicrosoftIntune ([Values (false, true)] bool isRelease) builder.BuildLogFile = "install.log"; Assert.IsTrue (builder.Install (proj), "Install should have succeeded."); + var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath); + var dexFile = Path.Combine (intermediate, "android", "bin", "classes.dex"); + FileAssert.Exists (dexFile); + var className = "Lcom/xamarin/microsoftintune/MainActivity;"; + var methodName = "onMAMCreate"; + Assert.IsTrue (DexUtils.ContainsClassWithMethod (className, methodName, "(Landroid/os/Bundle;)V", dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}` and `{methodName}!"); + RunProjectAndAssert (proj, builder); WaitForPermissionActivity (Path.Combine (Root, builder.ProjectDirectory, "permission-logcat.log")); From 55c9690193f9b98542f61e34aabad7afa4cff5c9 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 27 Oct 2023 12:30:53 -0500 Subject: [PATCH 4/4] Update InstallAndRunTests.cs --- tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 1b36d4cfd45..ea9f5da4c7c 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -1134,8 +1134,6 @@ public void FixLegacyResourceDesignerStep ([Values (true, false)] bool isRelease [Test] public void MicrosoftIntune ([Values (false, true)] bool isRelease) { - if (!Builder.UseDotNet) - Assert.Ignore ("Test is only valid in .NET 8+"); proj = new XamarinAndroidApplicationProject { IsRelease = isRelease, PackageReferences = {