-
Notifications
You must be signed in to change notification settings - Fork 75
Using Remapper in Android #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using activedirectoryxamarinintune; | ||
using Android.Runtime; | ||
using Android.Util; | ||
using Microsoft.Intune.Mam.Client.Notification; | ||
using Microsoft.Intune.Mam.Policy; | ||
using Microsoft.Intune.Mam.Policy.Notification; | ||
|
@@ -28,16 +30,34 @@ class EnrollmentNotificationReceiver : Java.Lang.Object, IMAMNotificationReceive | |
/// </returns> | ||
public bool OnReceive(IMAMNotification notification) | ||
{ | ||
Debug.WriteLine("***Begin EnrollmentNotificationReceiver -> OnReceive"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the remapper needed? Is it only for CITI scenario? If so, since this is a public sample, can we put these changes into a dev app to not clutter the sample? Otherwise, I would clarify what the remapper does. |
||
if (notification.Type == MAMNotificationType.MamEnrollmentResult) | ||
{ | ||
Debug.WriteLine("***Begin EnrollmentNotificationReceiver -> OnReceive (notification.Type == MAMNotificationType.MamEnrollmentResult)"); | ||
IMAMEnrollmentNotification enrollmentNotification = notification.JavaCast<IMAMEnrollmentNotification>(); | ||
MAMEnrollmentManagerResult result = enrollmentNotification.EnrollmentResult; | ||
|
||
if (result.Equals(MAMEnrollmentManagerResult.EnrollmentSucceeded)) | ||
{ | ||
Debug.WriteLine($"***Begin OnReceive-> Enrollment = {result} Code = {result.Code}"); | ||
} | ||
else if (notification.Type == MAMNotificationType.ComplianceStatus) | ||
{ | ||
Debug.WriteLine("***Begin EnrollmentNotificationReceiver -> OnReceive (notification.Type == MAMNotificationType.ComplianceStatus)"); | ||
IMAMComplianceNotification complianceNotification = notification.JavaCast<IMAMComplianceNotification>(); | ||
MAMCAComplianceStatus result = complianceNotification.ComplianceStatus; | ||
Debug.WriteLine($"***Begin OnReceive-> Compliance = {result} Code = {result.Code}"); | ||
if (result.Equals(MAMCAComplianceStatus.Compliant)) | ||
{ | ||
Log.Info(GetType().Name, "remediateCompliance succeeded; status = " + result); | ||
Debug.WriteLine("***Begin OnReceive-> Compliant"); | ||
// this signals that MAM registration is complete and the app can proceed | ||
PCAWrapper.MAMRegsiteredEvent.Set(); | ||
} | ||
else | ||
{ | ||
Log.Info(GetType().Name, "remediateCompliance failed; status = " + result); | ||
Log.Info(GetType().Name, complianceNotification.ComplianceErrorTitle); | ||
Log.Info(GetType().Name, complianceNotification.ComplianceErrorMessage); | ||
} | ||
|
||
} | ||
|
||
return true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,15 @@ | |
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using activedirectoryxamarinintune; | ||
using Android.Util; | ||
using Microsoft.Identity.Client; | ||
using Microsoft.Intune.Mam.Client.App; | ||
using Microsoft.Intune.Mam.Policy; | ||
|
||
[assembly: Xamarin.Forms.Dependency(typeof(active_directory_xamarin_intune.Droid.IntuneMAMConnector))] | ||
namespace active_directory_xamarin_intune.Droid | ||
{ | ||
public class IntuneMAMConnector : IIntuneMAMConnector | ||
|
@@ -19,26 +22,34 @@ public class IntuneMAMConnector : IIntuneMAMConnector | |
/// <returns></returns> | ||
public async Task DoMAMRegisterAsync(IntuneAppProtectionPolicyRequiredException exProtection) | ||
{ | ||
Log.Info(GetType().Name, "***Begin DoMAMRegisterAsync"); | ||
Debug.WriteLine("***Begin DoMAMRegisterAsync"); | ||
// reset the registered event | ||
PCAWrapper.MAMRegsiteredEvent.Reset(); | ||
|
||
// Invoke compliance API on a different thread | ||
await Task.Run(() => | ||
{ | ||
IMAMComplianceManager mgr = MAMComponents.Get<IMAMComplianceManager>(); | ||
mgr.RemediateCompliance(exProtection.Upn, exProtection.AccountUserId, exProtection.TenantId, exProtection.AuthorityUrl, false); | ||
}).ConfigureAwait(false); | ||
await Task.Run(() => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment explaining why you do this on a background thread. |
||
{ | ||
Log.Info(GetType().Name, "Attempting to remediateCompliance."); | ||
Debug.WriteLine("***DoMAMRegisterAsync->RemediateCompliance"); | ||
IMAMComplianceManager mgr = MAMComponents.Get<IMAMComplianceManager>(); | ||
mgr.RemediateCompliance(exProtection.Upn, exProtection.AccountUserId, exProtection.TenantId, exProtection.AuthorityUrl, true); | ||
}).ConfigureAwait(false); | ||
|
||
|
||
// wait till the registration completes | ||
// Note: This is a sample app for MSAL.NET. Scenarios such as what if enrollment fails or user chooses not to enroll will be as | ||
// per the business requirements of the app and not considered in the sample app. | ||
Debug.WriteLine("***DoMAMRegisterAsync->Pre-Wait"); | ||
Log.Info(GetType().Name, "***DoMAMRegisterAsync->Pre-Wait"); | ||
PCAWrapper.MAMRegsiteredEvent.WaitOne(); | ||
Debug.WriteLine("***DoMAMRegisterAsync->Post-Wait"); | ||
Log.Info(GetType().Name, "***DoMAMRegisterAsync->Post-Wait"); | ||
} | ||
|
||
public void Unenroll() | ||
{ | ||
// Not implpemented on Android. | ||
{ | ||
// Not implpemented on Android by Broker. Known issue. | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe log the notification type from the start.