Skip to content

Commit b815a7c

Browse files
committed
basic MDM implementation for all platforms
1 parent edf038c commit b815a7c

37 files changed

+995
-0
lines changed

Diff for: gitignore renamed to .gitignore

File renamed without changes.

Diff for: XAM-MDM/MauiApp1/App.xaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:MauiApp1"
5+
x:Class="MauiApp1.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

Diff for: XAM-MDM/MauiApp1/App.xaml.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace MauiApp1;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}

Diff for: XAM-MDM/MauiApp1/AppShell.xaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="MauiApp1.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:MauiApp1"
7+
Shell.FlyoutBehavior="Disabled">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>

Diff for: XAM-MDM/MauiApp1/AppShell.xaml.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MauiApp1;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}

Diff for: XAM-MDM/MauiApp1/MainPage.xaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="MauiApp1.MainPage">
5+
6+
<ScrollView>
7+
<VerticalStackLayout
8+
Spacing="25"
9+
Padding="30,0"
10+
VerticalOptions="Center">
11+
12+
<Image
13+
Source="intune.png"
14+
HeightRequest="100"
15+
HorizontalOptions="Center" />
16+
17+
<Label
18+
Text="ManagedConfiguration key 'MyMDMConfigKey' value"
19+
FontSize="20"
20+
HorizontalOptions="Center" />
21+
22+
<Label
23+
x:Name="lblConfig"
24+
Text=""
25+
FontSize="32"
26+
HorizontalOptions="Center" />
27+
28+
<Button
29+
x:Name="btnRefresh"
30+
Text="Refresh Managed Configuration"
31+
Clicked="OnBtnRefreshClicked"
32+
HorizontalOptions="Center" />
33+
34+
</VerticalStackLayout>
35+
</ScrollView>
36+
37+
</ContentPage>

Diff for: XAM-MDM/MauiApp1/MainPage.xaml.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace MauiApp1;
2+
3+
public partial class MainPage : ContentPage
4+
{
5+
public const string MyMDMConfigKey = "MyMDMConfigKey";
6+
7+
private readonly ManagedConfigurationProvider managedConfigurationProvider;
8+
9+
public MainPage()
10+
{
11+
InitializeComponent();
12+
13+
this.managedConfigurationProvider = new ManagedConfigurationProvider();
14+
}
15+
16+
protected override void OnAppearing()
17+
{
18+
base.OnAppearing();
19+
20+
lblConfig.Text = managedConfigurationProvider.GetStringValue(MyMDMConfigKey);
21+
}
22+
23+
private void OnBtnRefreshClicked(object sender, EventArgs e)
24+
{
25+
lblConfig.Text = managedConfigurationProvider.GetStringValue(MyMDMConfigKey);
26+
}
27+
}
28+

Diff for: XAM-MDM/MauiApp1/ManagedConfigurationProvider.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MauiApp1
2+
{
3+
public partial class ManagedConfigurationProvider
4+
{
5+
public partial string GetStringValue(string key);
6+
}
7+
}

Diff for: XAM-MDM/MauiApp1/MauiProgram.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace MauiApp1;
4+
5+
public static class MauiProgram
6+
{
7+
public static MauiApp CreateMauiApp()
8+
{
9+
var builder = MauiApp.CreateBuilder();
10+
builder
11+
.UseMauiApp<App>()
12+
.ConfigureFonts(fonts =>
13+
{
14+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
15+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
16+
});
17+
18+
#if DEBUG
19+
builder.Logging.AddDebug();
20+
#endif
21+
22+
return builder.Build();
23+
}
24+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
4+
<meta-data android:name="android.content.APP_RESTRICTIONS" android:resource="@xml/app_restrictions" />
5+
</application>
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
<uses-permission android:name="android.permission.INTERNET" />
8+
</manifest>

Diff for: XAM-MDM/MauiApp1/Platforms/Android/MainActivity.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace MauiApp1;
6+
7+
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8+
public class MainActivity : MauiAppCompatActivity
9+
{
10+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Android.App;
2+
using Android.Runtime;
3+
4+
namespace MauiApp1;
5+
6+
[Application]
7+
public class MainApplication : MauiApplication
8+
{
9+
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10+
: base(handle, ownership)
11+
{
12+
}
13+
14+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Android.Content;
2+
3+
namespace MauiApp1
4+
{
5+
public partial class ManagedConfigurationProvider
6+
{
7+
public partial string GetStringValue(string key)
8+
{
9+
var manager = (RestrictionsManager)Platform.AppContext.GetSystemService(Context.RestrictionsService);
10+
var bundle = manager.ApplicationRestrictions;
11+
12+
if (bundle != null)
13+
{
14+
if (bundle.ContainsKey(key))
15+
return bundle.GetString(key);
16+
else
17+
return null;
18+
}
19+
20+
return null;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#512BD4</color>
4+
<color name="colorPrimaryDark">#2B0B98</color>
5+
<color name="colorAccent">#2B0B98</color>
6+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<resources>
3+
<string name="MyMDMConfigKey">MyMDMConfigKey</string>
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
3+
<restriction
4+
android:title="@string/MyMDMConfigKey"
5+
android:key="MyMDMConfigKey"
6+
android:restrictionType="string"
7+
android:defaultValue=""/>
8+
</restrictions>

Diff for: XAM-MDM/MauiApp1/Platforms/Windows/App.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<maui:MauiWinUIApplication
2+
x:Class="MauiApp1.WinUI.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:maui="using:Microsoft.Maui"
6+
xmlns:local="using:MauiApp1.WinUI">
7+
8+
</maui:MauiWinUIApplication>

Diff for: XAM-MDM/MauiApp1/Platforms/Windows/App.xaml.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.UI.Xaml;
2+
3+
// To learn more about WinUI, the WinUI project structure,
4+
// and more about our project templates, see: http://aka.ms/winui-project-info.
5+
6+
namespace MauiApp1.WinUI;
7+
8+
/// <summary>
9+
/// Provides application-specific behavior to supplement the default Application class.
10+
/// </summary>
11+
public partial class App : MauiWinUIApplication
12+
{
13+
/// <summary>
14+
/// Initializes the singleton application object. This is the first line of authored code
15+
/// executed, and as such is the logical equivalent of main() or WinMain().
16+
/// </summary>
17+
public App()
18+
{
19+
this.InitializeComponent();
20+
}
21+
22+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Windows.Storage;
2+
3+
namespace MauiApp1
4+
{
5+
public partial class ManagedConfigurationProvider
6+
{
7+
public const string MangedConfigurationKey = "Managed.App.Settings";
8+
9+
public partial string GetStringValue(string key)
10+
{
11+
ApplicationDataContainer container = null;
12+
if (ApplicationData.Current.LocalSettings.Containers.TryGetValue(MangedConfigurationKey, out container))
13+
{
14+
object value = null;
15+
if (container.Values.TryGetValue(key, out value) && value != null)
16+
return value.ToString();
17+
}
18+
19+
return null;
20+
}
21+
}
22+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Package
3+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
4+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
5+
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
6+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7+
IgnorableNamespaces="uap rescap">
8+
9+
<Identity Name="maui-package-name-placeholder" Publisher="CN=User Name" Version="0.0.0.0" />
10+
11+
<mp:PhoneIdentity PhoneProductId="022F5989-BFC0-46E5-9FC7-281232C29806" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
12+
13+
<Properties>
14+
<DisplayName>$placeholder$</DisplayName>
15+
<PublisherDisplayName>User Name</PublisherDisplayName>
16+
<Logo>$placeholder$.png</Logo>
17+
</Properties>
18+
19+
<Dependencies>
20+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
21+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
22+
</Dependencies>
23+
24+
<Resources>
25+
<Resource Language="x-generate" />
26+
</Resources>
27+
28+
<Applications>
29+
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
30+
<uap:VisualElements
31+
DisplayName="$placeholder$"
32+
Description="$placeholder$"
33+
Square150x150Logo="$placeholder$.png"
34+
Square44x44Logo="$placeholder$.png"
35+
BackgroundColor="transparent">
36+
<uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />
37+
<uap:SplashScreen Image="$placeholder$.png" />
38+
</uap:VisualElements>
39+
</Application>
40+
</Applications>
41+
42+
<Capabilities>
43+
<rescap:Capability Name="runFullTrust" />
44+
</Capabilities>
45+
46+
</Package>

Diff for: XAM-MDM/MauiApp1/Platforms/Windows/app.manifest

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="MauiApp1.WinUI.app"/>
4+
5+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
6+
<windowsSettings>
7+
<!-- The combination of below two tags have the following effect:
8+
1) Per-Monitor for >= Windows 10 Anniversary Update
9+
2) System < Windows 10 Anniversary Update
10+
-->
11+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
12+
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
13+
</windowsSettings>
14+
</application>
15+
</assembly>

Diff for: XAM-MDM/MauiApp1/Platforms/iOS/AppDelegate.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Foundation;
2+
3+
namespace MauiApp1;
4+
5+
[Register("AppDelegate")]
6+
public class AppDelegate : MauiUIApplicationDelegate
7+
{
8+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9+
}

Diff for: XAM-MDM/MauiApp1/Platforms/iOS/Info.plist

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>LSRequiresIPhoneOS</key>
6+
<true/>
7+
<key>UIDeviceFamily</key>
8+
<array>
9+
<integer>1</integer>
10+
<integer>2</integer>
11+
</array>
12+
<key>UIRequiredDeviceCapabilities</key>
13+
<array>
14+
<string>arm64</string>
15+
</array>
16+
<key>UISupportedInterfaceOrientations</key>
17+
<array>
18+
<string>UIInterfaceOrientationPortrait</string>
19+
<string>UIInterfaceOrientationLandscapeLeft</string>
20+
<string>UIInterfaceOrientationLandscapeRight</string>
21+
</array>
22+
<key>UISupportedInterfaceOrientations~ipad</key>
23+
<array>
24+
<string>UIInterfaceOrientationPortrait</string>
25+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
26+
<string>UIInterfaceOrientationLandscapeLeft</string>
27+
<string>UIInterfaceOrientationLandscapeRight</string>
28+
</array>
29+
<key>XSAppIconAssets</key>
30+
<string>Assets.xcassets/appicon.appiconset</string>
31+
</dict>
32+
</plist>

0 commit comments

Comments
 (0)