Skip to content

Commit

Permalink
basic MDM implementation for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
JTOne123 committed Feb 22, 2023
1 parent edf038c commit b815a7c
Show file tree
Hide file tree
Showing 37 changed files with 995 additions and 0 deletions.
File renamed without changes.
14 changes: 14 additions & 0 deletions XAM-MDM/MauiApp1/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
x:Class="MauiApp1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions XAM-MDM/MauiApp1/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace MauiApp1;

public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}
14 changes: 14 additions & 0 deletions XAM-MDM/MauiApp1/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiApp1.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
Shell.FlyoutBehavior="Disabled">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
9 changes: 9 additions & 0 deletions XAM-MDM/MauiApp1/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MauiApp1;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
37 changes: 37 additions & 0 deletions XAM-MDM/MauiApp1/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.MainPage">

<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">

<Image
Source="intune.png"
HeightRequest="100"
HorizontalOptions="Center" />

<Label
Text="ManagedConfiguration key 'MyMDMConfigKey' value"
FontSize="20"
HorizontalOptions="Center" />

<Label
x:Name="lblConfig"
Text=""
FontSize="32"
HorizontalOptions="Center" />

<Button
x:Name="btnRefresh"
Text="Refresh Managed Configuration"
Clicked="OnBtnRefreshClicked"
HorizontalOptions="Center" />

</VerticalStackLayout>
</ScrollView>

</ContentPage>
28 changes: 28 additions & 0 deletions XAM-MDM/MauiApp1/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace MauiApp1;

public partial class MainPage : ContentPage
{
public const string MyMDMConfigKey = "MyMDMConfigKey";

private readonly ManagedConfigurationProvider managedConfigurationProvider;

public MainPage()
{
InitializeComponent();

this.managedConfigurationProvider = new ManagedConfigurationProvider();
}

protected override void OnAppearing()
{
base.OnAppearing();

lblConfig.Text = managedConfigurationProvider.GetStringValue(MyMDMConfigKey);
}

private void OnBtnRefreshClicked(object sender, EventArgs e)
{
lblConfig.Text = managedConfigurationProvider.GetStringValue(MyMDMConfigKey);
}
}

7 changes: 7 additions & 0 deletions XAM-MDM/MauiApp1/ManagedConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MauiApp1
{
public partial class ManagedConfigurationProvider
{
public partial string GetStringValue(string key);
}
}
24 changes: 24 additions & 0 deletions XAM-MDM/MauiApp1/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.Extensions.Logging;

namespace MauiApp1;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
8 changes: 8 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
<meta-data android:name="android.content.APP_RESTRICTIONS" android:resource="@xml/app_restrictions" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
10 changes: 10 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace MauiApp1;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
15 changes: 15 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Android.App;
using Android.Runtime;

namespace MauiApp1;

[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
23 changes: 23 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Android/ManagedConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Android.Content;

namespace MauiApp1
{
public partial class ManagedConfigurationProvider
{
public partial string GetStringValue(string key)
{
var manager = (RestrictionsManager)Platform.AppContext.GetSystemService(Context.RestrictionsService);
var bundle = manager.ApplicationRestrictions;

if (bundle != null)
{
if (bundle.ContainsKey(key))
return bundle.GetString(key);
else
return null;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="MyMDMConfigKey">MyMDMConfigKey</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:title="@string/MyMDMConfigKey"
android:key="MyMDMConfigKey"
android:restrictionType="string"
android:defaultValue=""/>
</restrictions>
8 changes: 8 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<maui:MauiWinUIApplication
x:Class="MauiApp1.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:MauiApp1.WinUI">

</maui:MauiWinUIApplication>
24 changes: 24 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace MauiApp1.WinUI;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : MauiWinUIApplication
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

22 changes: 22 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Windows/ManagedConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Windows.Storage;

namespace MauiApp1
{
public partial class ManagedConfigurationProvider
{
public const string MangedConfigurationKey = "Managed.App.Settings";

public partial string GetStringValue(string key)
{
ApplicationDataContainer container = null;
if (ApplicationData.Current.LocalSettings.Containers.TryGetValue(MangedConfigurationKey, out container))
{
object value = null;
if (container.Values.TryGetValue(key, out value) && value != null)
return value.ToString();
}

return null;
}
}
}
46 changes: 46 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Windows/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />

<mp:PhoneIdentity PhoneProductId="022F5989-BFC0-46E5-9FC7-281232C29806" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

<Properties>
<DisplayName>$placeholder$</DisplayName>
<PublisherDisplayName>User Name</PublisherDisplayName>
<Logo>$placeholder$.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate" />
</Resources>

<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="$placeholder$"
Description="$placeholder$"
Square150x150Logo="$placeholder$.png"
Square44x44Logo="$placeholder$.png"
BackgroundColor="transparent">
<uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />
<uap:SplashScreen Image="$placeholder$.png" />
</uap:VisualElements>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>

</Package>
15 changes: 15 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/Windows/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MauiApp1.WinUI.app"/>

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- The combination of below two tags have the following effect:
1) Per-Monitor for >= Windows 10 Anniversary Update
2) System < Windows 10 Anniversary Update
-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
</assembly>
9 changes: 9 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Foundation;

namespace MauiApp1;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
32 changes: 32 additions & 0 deletions XAM-MDM/MauiApp1/Platforms/iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
Loading

0 comments on commit b815a7c

Please sign in to comment.