示例#1
0
        /// <summary>
        /// Checks a selected privilege. Requests a privilege if not set.
        /// </summary>
        /// <param name="privilege">The privilege to check.</param>
        private static void CheckPrivilege(string privilege)
        {
            switch (PrivacyPrivilegeManager.CheckPermission(privilege))
            {
            case CheckResult.Allow:
                SetPermission(privilege, true);
                break;

            case CheckResult.Deny:
                SetPermission(privilege, false);
                break;

            case CheckResult.Ask:
                PrivacyPrivilegeManager.RequestPermission(privilege);
                PrivacyPrivilegeManager.GetResponseContext(privilege)
                .TryGetTarget(out PrivacyPrivilegeManager.ResponseContext context);

                if (context != null)
                {
                    context.ResponseFetched += PrivilegeRequestResponse;
                }

                break;
            }

            AllPrivilegesChecked();
        }
示例#2
0
        internal static async Task <bool> RequestAsync(string privilege)
        {
            EnsureDeclared(privilege);

            var checkResult = PrivacyPrivilegeManager.CheckPermission(privilege);

            if (checkResult == CheckResult.Ask)
            {
                var completionSource = new TaskCompletionSource <bool>();
                if (PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out var context))
                {
                    void OnResponseFetched(object sender, RequestResponseEventArgs e)
                    {
                        completionSource.TrySetResult(e.result == RequestResult.AllowForever);
                    }

                    context.ResponseFetched += OnResponseFetched;
                    PrivacyPrivilegeManager.RequestPermission(privilege);
                    var result = await completionSource.Task;
                    context.ResponseFetched -= OnResponseFetched;
                    return(result);
                }
                return(false);
            }
            else if (checkResult == CheckResult.Deny)
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Returns true if all required privileges are granted, false otherwise.
        /// </summary>
        /// <returns>Task with check result.</returns>
        public async Task <bool> CheckPrivileges()
        {
            CheckResult result = PrivacyPrivilegeManager.CheckPermission(HEALTHINFO_PRIVILEGE);

            switch (result)
            {
            case CheckResult.Allow:
                return(true);

            case CheckResult.Deny:
                return(false);

            case CheckResult.Ask:
                PrivacyPrivilegeManager.ResponseContext context = null;
                PrivacyPrivilegeManager.GetResponseContext(HEALTHINFO_PRIVILEGE)
                .TryGetTarget(out context);

                if (context == null)
                {
                    Log.Error("STT", "Unable to get privilege response context");
                    return(false);
                }

                _checkPrivilegesTask = new TaskCompletionSource <bool>();

                context.ResponseFetched += PrivilegeManagerOnResponseFetched;

                PrivacyPrivilegeManager.RequestPermission(HEALTHINFO_PRIVILEGE);
                return(await _checkPrivilegesTask.Task);

            default:
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// Checks location privilege. Request location privilege if not set.
        /// Starts application when privilege check is complete.
        /// </summary>
        private void LocationPrivilegeCheck()
        {
            CheckResult result = PrivacyPrivilegeManager.CheckPermission(Config.LocationPrivilege);

            switch (result)
            {
            case CheckResult.Allow:
                ViewModels.ViewModelLocator.ViewModel.IsGPSAvailable = true;
                StartApplication();

                break;

            case CheckResult.Deny:
                ViewModels.ViewModelLocator.ViewModel.IsGPSAvailable = false;
                StartApplication();

                break;

            case CheckResult.Ask:
                PrivacyPrivilegeManager.GetResponseContext(Config.LocationPrivilege)
                .TryGetTarget(out PrivacyPrivilegeManager.ResponseContext context);

                if (context != null)
                {
                    context.ResponseFetched += PPM_RequestResponse;
                }

                PrivacyPrivilegeManager.RequestPermission(Config.LocationPrivilege);
                break;
            }
        }
        private void CheckPrivileges()
        {
            // Check permission status (allow, deny, ask) to determinate action which has to be taken
            string      privilege = "http://tizen.org.privilege/healthinfo";
            CheckResult result    = PrivacyPrivilegeManager.CheckPermission(privilege);

            if (result == CheckResult.Allow)
            {
                OnPrivilegesGranted();
            }
            else if (result == CheckResult.Deny)
            {
                OnPrivilegesDenied();
            }
            else // the user must be asked about granting the privilege
            {
                PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out var context);

                if (context != null)
                {
                    context.ResponseFetched += (sender, e) =>
                    {
                        if (e.cause == CallCause.Answer && e.result == RequestResult.AllowForever)
                        {
                            OnPrivilegesGranted();
                        }
                        else
                        {
                            OnPrivilegesDenied();
                        }
                    };
                }
            }
        }
示例#6
0
 private void SetupPrivilegeHandler()
 {
     PrivacyPrivilegeManager.ResponseContext context = null;
     if (PrivacyPrivilegeManager.GetResponseContext(hrmPrivilege).TryGetTarget(out context))
     {
         context.ResponseFetched += PrivilegeResponseHandler;
     }
 }
示例#7
0
 private static void SetupPPMHandler(string privilege)
 {
     PrivacyPrivilegeManager.ResponseContext context = null;
     if (PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context))
     {
         context.ResponseFetched += PPMResponseHandler;
     }
 }
示例#8
0
        /// <summary>
        /// Used to set privilege event listener and request the privilege.
        /// </summary>
        void AskPrivacyPrivilege(string privilege)
        {
            // Set event listener for privilege
            PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context);
            if (context != null)
            {
                context.ResponseFetched += PPM_RequestResponse;
            }

            // Request pop-up message for privileges
            PrivacyPrivilegeManager.RequestPermission(privilege);
        }
        /// <summary>
        /// Request user permission for privacy privileges
        /// </summary>
        /// <param name="service">privacy privilege</param>
        /// <returns>true if user consent is gained</returns>
        public async Task <bool> GetPermission(string service)
        {
            try
            {
                GrantedPermission = -1;
                // Gets the status of a privacy privilege permission.
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(service);
                switch (result)
                {
                case CheckResult.Allow:
                    // user consent for privacy privilege is already gained
                    Console.WriteLine("\n\n\nuser consent for privacy privilege is already gained\n\n");
                    return(true);

                case CheckResult.Deny:
                case CheckResult.Ask:
                    // User permission request should be required
                    tcs = new TaskCompletionSource <bool>();
                    // Gets the response context for a given privilege.
                    var reponseContext = PrivacyPrivilegeManager.GetResponseContext(service);
                    PrivacyPrivilegeManager.ResponseContext context = null;
                    if (reponseContext.TryGetTarget(out context))
                    {
                        if (context != null)
                        {
                            context.ResponseFetched += Context_ResponseFetched;
                        }
                    }
                    // Try to get the permission for service from a user.
                    PrivacyPrivilegeManager.RequestPermission(service);

                    // Check if permission is granted or not every second
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Device.StartTimer(new TimeSpan(0, 0, 0, 1, 0), CheckPermission);
                    });

                    return(await tcs.Task);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[UserPermission] (" + service + ") Error :" + e.Message + ", " + e.StackTrace + ", " + e.InnerException);
                return(false);
            }
        }
示例#10
0
        private Task RequestPermission()
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            var response = PrivacyPrivilegeManager.GetResponseContext(MEDIASTORAGE_PRIVILEGE);

            PrivacyPrivilegeManager.ResponseContext target;
            response.TryGetTarget(out target);
            target.ResponseFetched += (s, e) =>
            {
                tcs.SetResult(true);
                _mainPage.RestartScan();
            };
            PrivacyPrivilegeManager.RequestPermission(MEDIASTORAGE_PRIVILEGE);

            return(tcs.Task);
        }
        /// <summary>
        /// Check privacy privilege and if need to ask for user, send request for PPM.
        /// </summary>
        public bool CheckPrivilege()
        {
            // Make array list for requesting privacy privilege
            // Contacts need 2 privilege, contact read and account write.
            ArrayList PrivilegeList = new ArrayList();

            PrivilegeList.Add("http://tizen.org/privilege/contact.read");
            PrivilegeList.Add("http://tizen.org/privilege/contact.write");
            int privilageAcceptedCount = 0;

            // Check and request privacy privilege if app is needed
            foreach (string list in PrivilegeList)
            {
                PrivacyPrivilegeManager.GetResponseContext(list).TryGetTarget(out context);
                if (context != null)
                {
                    ++CBCount;
                    context.ResponseFetched += PPM_RequestResponse;
                }

                CheckResult result = PrivacyPrivilegeManager.CheckPermission(list);
                switch (result)
                {
                case CheckResult.Allow:
                    /// Privilege can be used
                    privilageAcceptedCount++;
                    break;

                case CheckResult.Deny:
                    /// Privilege can't be used
                    break;

                case CheckResult.Ask:
                    /// Request permission to user
                    PrivacyPrivilegeManager.RequestPermission(list);
                    break;
                }
            }
            if (privilageAcceptedCount == PrivilegeList.Count)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Check if a permission is granted and request a permission if it's not granted
        /// </summary>
        /// <param name="privilege">privilege name</param>
        /// <returns>bool</returns>
        public async Task <bool> CheckAndRequestPermission(string privilege)
        {
            try
            {
                // Gets the status of a privacy privilege permission.
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);
                Log.Debug(Utility.LOG_TAG, "State: " + result.ToString());
                switch (result)
                {
                case CheckResult.Allow:
                    // Permission has already been granted
                    // Privilege can be used
                    return(true);

                case CheckResult.Deny:
                    // Privilege can't be used
                    Log.Debug(Utility.LOG_TAG, "In this case, " + privilege + " privilege is not available until the user changes the permission state from the Settings application.");
                    return(false);

                case CheckResult.Ask:
                    // Permission is not granted so we need to request the permission
                    PrivacyPrivilegeManager.ResponseContext context;
                    PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context);
                    if (context == null)
                    {
                        return(false);
                    }

                    tcs = new TaskCompletionSource <bool>();
                    context.ResponseFetched += PPMResponseHandler;
                    // Request a permission
                    // Calling it brings up a system dialog that an app user can decide to approve or deny it.
                    PrivacyPrivilegeManager.RequestPermission(privilege);
                    return(await tcs.Task);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                // Handle exception
                Log.Error(Utility.LOG_TAG, "An error occurred. : " + e.Message);
                return(false);
            }
        }
示例#13
0
            async Task <PermissionStatus> CheckPrivilegeAsync(bool ask)
            {
                if (RequiredPrivileges == null || !RequiredPrivileges.Any())
                {
                    return(PermissionStatus.Granted);
                }

                EnsureDeclared();

                var tizenPrivileges = RequiredPrivileges.Where(p => p.isRuntime);

                foreach (var(tizenPrivilege, isRuntime) in tizenPrivileges)
                {
                    var checkResult = PrivacyPrivilegeManager.CheckPermission(tizenPrivilege);
                    if (checkResult == CheckResult.Ask)
                    {
                        if (ask)
                        {
                            var tcs = new TaskCompletionSource <bool>();
                            PrivacyPrivilegeManager.GetResponseContext(tizenPrivilege)
                            .TryGetTarget(out var context);
                            void OnResponseFetched(object sender, RequestResponseEventArgs e)
                            {
                                tcs.TrySetResult(e.result == RequestResult.AllowForever);
                            }

                            context.ResponseFetched += OnResponseFetched;
                            PrivacyPrivilegeManager.RequestPermission(tizenPrivilege);
                            var result = await tcs.Task;
                            context.ResponseFetched -= OnResponseFetched;
                            if (result)
                            {
                                continue;
                            }
                        }
                        return(PermissionStatus.Denied);
                    }
                    else if (checkResult == CheckResult.Deny)
                    {
                        return(PermissionStatus.Denied);
                    }
                }
                return(PermissionStatus.Granted);
            }
示例#14
0
        private void initDataSourcesWithPrivileges()
        {
            PrivacyPrivilegeManager.ResponseContext context = null;
            if (PrivacyPrivilegeManager.GetResponseContext(Tools.HEALTHINFO_PRIVILEGE).TryGetTarget(out context))
            {
                context.ResponseFetched += (s, e) =>
                {
                    if (e.result != RequestResult.AllowForever)
                    {
                        Toast.DisplayText("Please provide the necessary privileges for the application to run!");
                        Environment.Exit(1);
                    }
                    else
                    {
                        initCampaignDataSources();
                    }
                }
            }
            ;
            else
            {
                Toast.DisplayText("Please provide the necessary privileges for the application to run!");
                Environment.Exit(1);
            }

            switch (PrivacyPrivilegeManager.CheckPermission(Tools.HEALTHINFO_PRIVILEGE))
            {
            case CheckResult.Allow:
                initCampaignDataSources();
                break;

            case CheckResult.Deny:
                Toast.DisplayText("Please provide the necessary privileges for the application to run!");
                Environment.Exit(1);
                break;

            case CheckResult.Ask:
                PrivacyPrivilegeManager.RequestPermission(Tools.HEALTHINFO_PRIVILEGE);
                break;

            default:
                break;
            }
        }
示例#15
0
        static async Task <AccessState> RequestPermission(string priv)
        {
            var result  = AccessState.Unknown;
            var tcs     = new TaskCompletionSource <AccessState>();
            var handler = new EventHandler <RequestResponseEventArgs>((sender, args) =>
            {
                switch (args.result)
                {
                case RequestResult.AllowForever:
                    tcs.TrySetResult(AccessState.Available);
                    break;

                default:
                    tcs.TrySetResult(AccessState.Denied);
                    break;
                }
            });

            PrivacyPrivilegeManager.ResponseContext context = null;

            try
            {
                PrivacyPrivilegeManager.GetResponseContext(priv).TryGetTarget(out context);

                if (context == null)
                {
                    tcs.SetResult(AccessState.NotSupported);
                }
                else
                {
                    context.ResponseFetched += handler;
                    PrivacyPrivilegeManager.RequestPermission(priv);
                }
                result = await tcs.Task.ConfigureAwait(false);
            }
            finally
            {
                if (context != null)
                {
                    context.ResponseFetched -= handler;
                }
            }
            return(result);
        }
        /// <summary>
        /// Check privacy privilege and if need to ask for user, send request for PPM.
        /// </summary>
        public async Task <bool> CheckPrivilege()
        {
            // Make array list for requesting privacy privilege
            // Contacts need 2 privilege, contact read and account write.
            var privileges = new List <string>
            {
                "http://tizen.org/privilege/contact.read",
                "http://tizen.org/privilege/contact.write"
            };

            // Check and request privacy privilege if app is needed
            foreach (string privilege in privileges)
            {
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);
                switch (result)
                {
                case CheckResult.Allow:
                    break;

                case CheckResult.Deny:
                    return(false);

                case CheckResult.Ask:
                    /// Request permission to user
                    if (PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out PrivacyPrivilegeManager.ResponseContext context))
                    {
                        TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
                        context.ResponseFetched += (s, e) =>
                        {
                            tcs.SetResult(e.result == RequestResult.AllowForever);
                        };
                        PrivacyPrivilegeManager.RequestPermission(privilege);
                        if (!(await tcs.Task))
                        {
                            return(false);
                        }
                    }
                    break;
                }
            }

            return(true);
        }
        static Task <bool> RequestPermission(string privilege)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            var response = PrivacyPrivilegeManager.GetResponseContext(privilege);

            PrivacyPrivilegeManager.ResponseContext target;
            response.TryGetTarget(out target);
            target.ResponseFetched += (s, e) =>
            {
                if (e.cause == CallCause.Error)
                {
                    /// Handle errors
                    Tizen.Log.Error(Constants.logTag, "An error occurred while requesting an user permission");
                    tcs.SetResult(false);
                    return;
                }

                // Now, we can check if the permission is granted or not
                switch (e.result)
                {
                case RequestResult.AllowForever:
                    // Permission is granted.
                    // We can do this permission-related task we want to do.
                    Tizen.Log.Info(Constants.logTag, "Response : RequestResult.AllowForever");
                    tcs.SetResult(true);
                    break;

                case RequestResult.DenyForever:
                case RequestResult.DenyOnce:
                    // Functionality that depends on this permission will not be available
                    Tizen.Log.Info(Constants.logTag, "Response: RequestResult." + e.result.ToString());
                    tcs.SetResult(false);
                    break;
                }
            };

            PrivacyPrivilegeManager.RequestPermission(privilege);

            return(tcs.Task);
        }
        /// <summary>
        /// Request user permission for privacy privileges
        /// </summary>
        /// <param name="service">privacy privilege</param>
        /// <returns>true if user consent is gained</returns>
        public async Task <bool> GetPermission(string service)
        {
            try
            {
                // Gets the status of a privacy privilege permission.
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(service);
                switch (result)
                {
                case CheckResult.Allow:
                    // user consent for privacy privilege is already gained
                    return(true);

                case CheckResult.Deny:
                case CheckResult.Ask:
                    // User permission request should be required
                    tcs = new TaskCompletionSource <bool>();
                    // Gets the response context for a given privilege.
                    var reponseContext = PrivacyPrivilegeManager.GetResponseContext(service);
                    PrivacyPrivilegeManager.ResponseContext context = null;
                    if (reponseContext.TryGetTarget(out context))
                    {
                        if (context != null)
                        {
                            context.ResponseFetched += Context_ResponseFetched;
                        }
                    }
                    // Try to get the permission for service from a user.
                    PrivacyPrivilegeManager.RequestPermission(service);

                    return(await tcs.Task);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[UserPermission] (" + service + ") Error :" + e.Message);
                return(false);
            }
        }
        /// <summary>
        /// Check privacy privilege and if need to ask for user,
        /// send request for Privacy Privilege Manager.
        /// </summary>
        public void CheckAccountPrivilege()
        {
            // Make array list for requesting privacy privilege
            // Account sample need 2 privilege, account read and account write
            ArrayList privilegeList = new ArrayList
            {
                "http://tizen.org/privilege/account.read",

                // Account.read and account.write is same ppm. So if we use both, appear same pop up 2 times. So security team guide use just one.
                // "http://tizen.org/privilege/account.write"
            };

            // Check and request privacy privilege if app is needed
            foreach (string list in privilegeList)
            {
                PrivacyPrivilegeManager.GetResponseContext(list).TryGetTarget(out context);
                if (context != null)
                {
                    ++callbackCount;
                    context.ResponseFetched += PpmRequestResponse;
                }

                CheckResult result = PrivacyPrivilegeManager.CheckPermission(list);
                switch (result)
                {
                case CheckResult.Allow:
                    // Privilege can be used
                    break;

                case CheckResult.Deny:
                    // Privilege can't be used
                    break;

                case CheckResult.Ask:
                    // User permission request required
                    PrivacyPrivilegeManager.RequestPermission(list);
                    break;
                }
            }
        }
示例#20
0
        protected static void Check(string permission, Action <bool> callback)
        {
            var initPermission = PrivacyPrivilegeManager.CheckPermission(permission);

            if (initPermission == CheckResult.Allow)
            {
                callback(true);
                return;
            }
            if (initPermission == CheckResult.Deny)
            {
                callback(false);
                return;
            }
            if (!PrivacyPrivilegeManager.GetResponseContext(permission).TryGetTarget(out var context))
            {
                callback(false);
                return;
            }
            context.ResponseFetched += (sender, e) => callback(e.result == RequestResult.AllowForever);
            PrivacyPrivilegeManager.RequestPermission(permission);
        }
示例#21
0
        public async Task <bool> CheckAndRequestPermission(string privilege)
        {
            try
            {
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);
                Log.Debug(Utility.LOG_TAG, "State: " + result.ToString());
                switch (result)
                {
                case CheckResult.Allow:
                    return(true);

                case CheckResult.Deny:
                    Log.Debug(Utility.LOG_TAG, "In this case, health data is not available until the user changes the permission state from the Settings application.");
                    return(false);

                case CheckResult.Ask:
                    // Request permission to User
                    PrivacyPrivilegeManager.ResponseContext context;
                    PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context);
                    if (context == null)
                    {
                        return(false);
                    }
                    tcs = new TaskCompletionSource <bool>();
                    context.ResponseFetched += PPMResponseHandler;
                    PrivacyPrivilegeManager.RequestPermission(privilege);
                    return(await tcs.Task);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                // Handle exception
                Log.Error(Utility.LOG_TAG, "An error occurred. : " + e.Message);
                return(false);
            }
        }
示例#22
0
        /// <summary>
        /// Used to set privilege event listener and request the privilege.
        /// </summary>
        private static void PPM_RequestResponse(object sender, RequestResponseEventArgs e)
        {
            if (e.cause == CallCause.Answer)
            {
                switch (e.result)
                {
                // Allow clicked case
                case RequestResult.AllowForever:
                    if (e.privilege == "http://tizen.org/privilege/calendar.read")
                    {
                        pEvent.AllowCalendarReadPrivilege();
                    }
                    else if (e.privilege == "http://tizen.org/privilege/contact.read")
                    {
                        pEvent.AllowContactReadPrivilege();
                    }
                    break;

                case RequestResult.DenyForever:
                    break;

                case RequestResult.DenyOnce:
                    break;
                }
                ;

                // Unset event listener for privilege
                PrivacyPrivilegeManager.GetResponseContext(e.privilege).TryGetTarget(out context);
                if (context != null)
                {
                    context.ResponseFetched -= PPM_RequestResponse;
                }
            }
            else
            {
                Console.WriteLine("Error occurs during requesting permission for {0}", e.privilege);
            }
        }
示例#23
0
        internal static async Task <PermissionStatus> CheckPrivacyPermission(PermissionType permission, bool askUser)
        {
            EnsureDeclared(permission);
            var tizenPrivileges = permission.ToTizenPrivileges(onlyRuntimePermissions: true);

            foreach (var priv in tizenPrivileges)
            {
                if (PrivacyPrivilegeManager.CheckPermission(priv) == CheckResult.Ask)
                {
                    if (askUser)
                    {
                        var tcs = new TaskCompletionSource <bool>();
                        PrivacyPrivilegeManager.ResponseContext context = null;
                        PrivacyPrivilegeManager.GetResponseContext(priv).TryGetTarget(out context);
                        void OnResponseFetched(object sender, RequestResponseEventArgs e)
                        {
                            tcs.TrySetResult(e.result == RequestResult.AllowForever);
                        }

                        context.ResponseFetched += OnResponseFetched;
                        PrivacyPrivilegeManager.RequestPermission(priv);
                        var result = await tcs.Task;
                        context.ResponseFetched -= OnResponseFetched;
                        if (result)
                        {
                            continue;
                        }
                    }
                    return(PermissionStatus.Denied);
                }
                else if (PrivacyPrivilegeManager.CheckPermission(priv) == CheckResult.Deny)
                {
                    return(PermissionStatus.Denied);
                }
            }
            return(PermissionStatus.Granted);
        }
        /// <summary>
        /// Asks the user to grant the permission at runtime
        /// </summary>
        /// <param name="privilege">The privilege name to check for</param>
        /// <returns>A status that indicates whether the permission has been granted or not</returns>
        public static async Task <PrivacyPermissionStatus> RequestAsync(string privilege)
        {
            switch (PrivacyPrivilegeManager.CheckPermission(privilege))
            {
            case CheckResult.Allow:
                return(PrivacyPermissionStatus.Granted);

            case CheckResult.Deny:
            case CheckResult.Ask:
                var tcs      = new TaskCompletionSource <PrivacyPermissionStatus>();
                var response = PrivacyPrivilegeManager.GetResponseContext(privilege);
                PrivacyPrivilegeManager.ResponseContext context = null;

                if (response.TryGetTarget(out context))
                {
                    context.ResponseFetched += (s, e) =>
                    {
                        PrivacyPermissionStatus result = PrivacyPermissionStatus.Denied;

                        if (e.result == RequestResult.AllowForever)
                        {
                            result = PrivacyPermissionStatus.Granted;
                        }

                        tcs.SetResult(result);
                    };
                }

                PrivacyPrivilegeManager.RequestPermission(privilege);

                return(await tcs.Task);

            default:
                return(PrivacyPermissionStatus.Denied);
            }
        }