/// <summary>
        /// Handles the incoming notification.
        /// </summary>
        /// <param name="notification">Incoming notification.</param>
        /// <returns>True.</returns>
        public bool OnReceive(IMAMNotification notification)
        {
            Handler handler = new Handler(context.MainLooper);

            handler.Post(() => { Toast.MakeText(context, "Received MAMNotification of type " + notification.Type, ToastLength.Short).Show(); });
            return(true);
        }
        /// <summary>
        /// When using the MAM-WE APIs found in IMAMEnrollManager, your app wil receive
        /// IMAMEnrollmentNotifications back to signal the result of your calls.
        ///
        /// More information can be found here: https://docs.microsoft.com/en-us/intune/app-sdk-android#result-and-status-codes
        /// </summary>
        public bool OnReceive(IMAMNotification notification)
        {
            if (notification.Type != MAMNotificationType.MamEnrollmentResult)
            {
                return(true);
            }

            IMAMEnrollmentNotification enrollmentNotification = notification.JavaCast <IMAMEnrollmentNotification>();
            MAMEnrollmentManagerResult result = enrollmentNotification.EnrollmentResult;
            string upn = enrollmentNotification.UserIdentity;

            string message = string.Format(
                "Received MAM Enrollment result {0} for user {1}.", result.Name(), upn);

            Log.Info(GetType().Name, message);

            Handler handler = new Handler(context.MainLooper);

            handler.Post(() => { Toast.MakeText(context, message, ToastLength.Long).Show(); });

            if (result.Equals(MAMEnrollmentManagerResult.EnrollmentSucceeded) ||
                result.Equals(MAMEnrollmentManagerResult.NotLicensed) ||
                result.Equals(MAMEnrollmentManagerResult.Pending) ||
                result.Equals(MAMEnrollmentManagerResult.UnenrollmentFailed) ||
                result.Equals(MAMEnrollmentManagerResult.UnenrollmentSucceeded))
            {
                // You are not required to do anything here, these are primarily informational callbacks
                // so you can know the state of the enrollment attempt.
            }
            else if (result.Equals(MAMEnrollmentManagerResult.AuthorizationNeeded))
            {
                // Attempt to re-authorize.
                Authenticator.GetAuthenticator().UpdateAccessTokenForMAM();
            }
            else if (result.Equals(MAMEnrollmentManagerResult.CompanyPortalRequired))
            {
                // Intune blocks the user until the Company Portal is installed on the device.
                // An app can override OnMAMCompanyPortalRequired in a MAMActivity to add custom handling to this behavior.
            }
            else if (result.Equals(MAMEnrollmentManagerResult.EnrollmentFailed) ||
                     result.Equals(MAMEnrollmentManagerResult.WrongUser))
            {
                string blockMessage = Application.Context.GetString(Resource.String.err_blocked, result.Name());
                BlockUser(handler, blockMessage);
            }
            else
            {
                throw new NotSupportedException(string.Format("Unknown result code: {0}", result.Name()));
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// When using the MAM-WE APIs found in IMAMEnrollManager, your app wil receive
        /// IMAMEnrollmentNotifications back to signal the result of your calls.
        /// When enrollment is successful, this will signal that app has been registered and it can proceed ahead.
        /// </summary>
        /// <param name="notification">The notification that was received.</param>
        /// <returns>
        /// The receiver should return true if it handled the notification without error(or if it decided to ignore the notification).
        /// If the receiver tried to take some action in response to the notification but failed to complete that action it should return false.
        /// </returns>
        public bool OnReceive(IMAMNotification notification)
        {
            if (notification.Type == MAMNotificationType.MamEnrollmentResult)
            {
                IMAMEnrollmentNotification enrollmentNotification = notification.JavaCast <IMAMEnrollmentNotification>();
                MAMEnrollmentManagerResult result = enrollmentNotification.EnrollmentResult;

                if (result.Equals(MAMEnrollmentManagerResult.EnrollmentSucceeded))
                {
                    // this signals that MAM registration is complete and the app can proceed
                    IntuneSampleApp.MAMRegsiteredEvent.Set();
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the incoming wipe notification.
        /// </summary>
        /// <param name="notification">Incoming notification.</param>
        /// <returns>
        /// The receiver should return true if it handled the notification without error(or if it decided to ignore the notification).
        /// If the receiver tried to take some action in response to the notification but failed to complete that action it should return false.
        /// </returns>
        public bool OnReceive(IMAMNotification notification)
        {
            Log.Info(GetType().Name, "Performing application wipe and clearing the app database.");

            bool success = TaskManager.CloseConnection();

            if (success)
            {
                Log.Info(GetType().Name, "Application wipe completed successfully.");
            }
            else
            {
                Log.Warn(GetType().Name, "Application wipe did not complete successfully.");
            }

            return(success);
        }
Exemplo n.º 5
0
        public bool OnReceive(IMAMNotification notification)
        {
            var status = new Status();

            if (notification.Type == MAMNotificationType.MamEnrollmentResult)
            {
                var en     = notification.JavaCast <IMAMEnrollmentNotification>();
                var result = en.EnrollmentResult;

                if (EnrollmentRequestStatus != null)
                {
                    if (result == MAMEnrollmentManagerResult.AuthorizationNeeded)
                    {
                        status.StatusCode = StatusCode.AuthRequired;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.CompanyPortalRequired)
                    {
                        status.StatusCode = StatusCode.CompanyPortalRequired;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.EnrollmentFailed)
                    {
                        status.StatusCode = StatusCode.AppNotEnrolled;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.EnrollmentSucceeded)
                    {
                        status.StatusCode = StatusCode.EnrollmentSuccess;
                        status.DidSucceed = true;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.MdmEnrolled)
                    {
                        status.StatusCode = StatusCode.MdmEnrolled;
                        status.DidSucceed = true;
                        status.Error      = null;
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.NotLicensed)
                    {
                        status.StatusCode = StatusCode.AccountNotLicensed;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.WrongUser)
                    {
                        status.StatusCode = StatusCode.MdmEnrolledDifferentUser;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }

                    InTuneLoggingService.Instance.AddMessage(new LoggingMessage {
                        LogDate = DateTime.Now, Message = $"Did Succeed: {status.DidSucceed} Status Code: { status.StatusCode}, Error: {status.Error}", Module = SDKModule.Enrollment
                    });

                    EnrollmentRequestStatus(status);
                }
                else if (UnenrollmentRequestStatus != null)
                {
                    if (result == MAMEnrollmentManagerResult.UnenrollmentFailed)
                    {
                        status.StatusCode = StatusCode.UnenrollmentFailed;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.UnenrollmentSucceeded)
                    {
                        status.StatusCode = StatusCode.UnenrollmentSuccess;
                        status.DidSucceed = true;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }

                    InTuneLoggingService.Instance.AddMessage(new LoggingMessage {
                        LogDate = DateTime.Now, Message = $"Did Succeed: {status.DidSucceed} Status Code: { status.StatusCode}, Error: {status.Error}", Module = SDKModule.Unenrollment
                    });
                    UnenrollmentRequestStatus(status);
                }
            }
            else if (notification.Type == MAMNotificationType.RefreshPolicy)
            {
                status.StatusCode = StatusCode.RefreshPolicy;
                status.DidSucceed = true;
                status.Error      = null;

                InTuneLoggingService.Instance.AddMessage(new LoggingMessage {
                    LogDate = DateTime.Now, Message = "Refresh Policy", Module = SDKModule.Policies
                });

                PolicyRequestStatus(status);
            }
            return(true);
        }
Exemplo n.º 6
0
 public bool OnReceive(IMAMNotification notification)
 {
     Android.Util.Log.Debug("IntuneRepro", $"Notification: {notification.Type}");
     return(true);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Handles the incoming wipe notification.
        /// </summary>
        /// <param name="notification">Incoming notification.</param>
        /// <returns>
        /// The receiver should return true if it handled the notification without error(or if it decided to ignore the notification).
        /// If the receiver tried to take some action in response to the notification but failed to complete that action it should return false.
        /// </returns>
        public bool OnReceive(IMAMNotification notification)
        {
            Log.Info(GetType().Name, "Performing application wipe and clearing the app database.");

            return(true);
        }
Exemplo n.º 8
0
        public bool OnReceive(IMAMNotification notification)
        {
            var status = new Status();

            if (notification.Type == MAMNotificationType.MamEnrollmentResult)
            {
                var en     = notification.JavaCast <IMAMEnrollmentNotification>();
                var result = en.EnrollmentResult;

                if (EnrollmentRequestStatus != null)
                {
                    if (result == MAMEnrollmentManagerResult.AuthorizationNeeded)
                    {
                        status.StatusCode = StatusCode.AuthRequired;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.CompanyPortalRequired)
                    {
                        status.StatusCode = StatusCode.CompanyPortalRequired;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.EnrollmentFailed)
                    {
                        status.StatusCode = StatusCode.AppNotEnrolled;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.EnrollmentSucceeded)
                    {
                        status.StatusCode = StatusCode.EnrollmentSuccess;
                        status.DidSucceed = true;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.MdmEnrolled)
                    {
                        status.StatusCode = StatusCode.MdmEnrolled;
                        status.DidSucceed = true;
                        status.Error      = null;
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.NotLicensed)
                    {
                        status.StatusCode = StatusCode.AccountNotLicensed;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.WrongUser)
                    {
                        status.StatusCode = StatusCode.MdmEnrolledDifferentUser;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }

                    EnrollmentRequestStatus(status, _authenticationResult);
                }
                else if (UnenrollmentRequestStatus != null)
                {
                    if (result == MAMEnrollmentManagerResult.UnenrollmentFailed)
                    {
                        status.StatusCode = StatusCode.UnenrollmentFailed;
                        status.DidSucceed = false;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }
                    else if (result == MAMEnrollmentManagerResult.UnenrollmentSucceeded)
                    {
                        status.StatusCode = StatusCode.UnenrollmentSuccess;
                        status.DidSucceed = true;
                        status.Error      = _registerError?.ToString();
                        _registerError    = null;
                    }

                    UnenrollmentRequestStatus(status);
                }
            }
            else if (notification.Type == MAMNotificationType.RefreshPolicy)
            {
                status.StatusCode = StatusCode.RefreshPolicy;
                status.DidSucceed = true;
                status.Error      = null;
                PolicyRequestStatus(status);
            }
            return(true);
        }