Example #1
0
        /// <summary>
        /// Permission check
        /// </summary>
        private void PrivilegeCheck()
        {
            try
            {
                /// Check location permission
                CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location");

                switch (result)
                {
                case CheckResult.Allow:
                    break;

                case CheckResult.Deny:
                    break;

                case CheckResult.Ask:
                    /// Request to privacy popup
                    PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/location");
                    break;
                }
            }
            catch (Exception ex)
            {
                /// Exception handling
                InfoLabelList[1].Text = "[Status] Privilege : " + ex.Message;
            }
        }
Example #2
0
        public static void CheckAndRequestPermission(String permission)
        {
            SetupPPMHandler(permission);
            try
            {
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(permission);
                switch (result)
                {
                case CheckResult.Allow:
                    /// Update UI and start accessing protected functionality
                    break;

                case CheckResult.Deny:
                    PrivacyPrivilegeManager.RequestPermission(permission);
                    break;

                case CheckResult.Ask:
                    PrivacyPrivilegeManager.RequestPermission(permission);
                    break;
                }
            }
            catch (Exception)
            {
                /// Handle exception
            }
        }
Example #3
0
        public bool Dial(string number)
        {
            _number = number;
            try
            {
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(_callPrivilege);
                switch (result)
                {
                case CheckResult.Allow:
                    Call();
                    return(true);

                case CheckResult.Deny:
                    return(false);

                case CheckResult.Ask:
                    PrivacyPrivilegeManager.RequestPermission(_callPrivilege);
                    // Dial() method is synchronous, return true
                    return(true);

                default:
                    return(false);
                }
            }
            catch (Exception exc)
            {
                Tizen.Log.Error(Tag, "Dialing failed: " + exc.Message);
                return(false);
            }
        }
        /// <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);
            }
        }
            /// <summary>
            /// Permission check
            /// </summary>
            public void PrivilegeCheck()
            {
                try
                {
                    /// Check location permission
                    CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location");

                    switch (result)
                    {
                    case CheckResult.Allow:
                        break;

                    case CheckResult.Deny:
                        break;

                    case CheckResult.Ask:
                        /// Request to privacy popup
                        PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/location");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    /// Exception handling
                    textMessage.Text = "[Pravacy] Exception \n" + ex.Message;
                }
            }
Example #6
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;
            }
        }
Example #7
0
        /// <summary>
        /// Check whether the application has the specific permission or not.
        /// </summary>
        /// <param name="privilege">Privilege</param>
        public static void CheckPermission(string privilege)
        {
            try
            {
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);

                switch (result)
                {
                case CheckResult.Allow:
                    break;

                case CheckResult.Deny:
                    break;

                case CheckResult.Ask:
                    // Request permission to user
                    PrivacyPrivilegeManager.RequestPermission(privilege);
                    break;
                }
            }
            catch (Exception e)
            {
                global::Tizen.Log.Error(Log.LogTag, e.Message);
            }
        }
        /// <summary>
        /// Used to check calendar.read privilege.
        /// </summary>
        public void CheckCalendarReadPrivileges()
        {
            CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/calendar.read");

            switch (result)
            {
            case CheckResult.Allow:
                // Privilege can be used
                pEvent.AllowCalendarReadPrivilege();
                break;

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

            case CheckResult.Ask:
                // User permission request required
                AskPrivacyPrivilege("http://tizen.org/privilege/calendar.read");
                PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/contact.read");
                break;

            default:
                break;
            }
        }
Example #9
0
        public HRMPage()
        {
            Model = new HRMModel
            {
                IsSupported = HeartRateMonitor.IsSupported,
                SensorCount = HeartRateMonitor.Count
            };

            InitializeComponent();

            SetupPrivilegeHandler();
            CheckResult result = PrivacyPrivilegeManager.CheckPermission(hrmPrivilege);

            switch (result)
            {
            case CheckResult.Allow:
                CreateHRM();
                break;

            case CheckResult.Deny:
                break;

            case CheckResult.Ask:
                PrivacyPrivilegeManager.RequestPermission(hrmPrivilege);
                break;
            }
        }
Example #10
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);
        }
Example #11
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();
        }
Example #12
0
        /// <summary>
        /// Permission check
        /// </summary>
        public void PrivilegeCheck()
        {
            try
            {
                /// Check location permission
                CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location");

                switch (result)
                {
                case CheckResult.Allow:
                    break;

                case CheckResult.Deny:
                    break;

                case CheckResult.Ask:
                    /// Request to privacy popup
                    PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/location");
                    break;
                }
            }
            catch (Exception ex)
            {
                /// Exception handling
                positionLabel.Text      = ex.Message;
                positionLabel.IsVisible = true;
                Tizen.Log.Error("CircularUI", $"[Pravacy]Exception {ex.Message}");
            }
        }
Example #13
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);
            }
        }
Example #15
0
        public static void PrivilegeCheck(string permission)
        {
            var result = PrivacyPrivilegeManager.CheckPermission(permission);

            switch (result)
            {
            case CheckResult.Allow:
                break;

            case CheckResult.Deny:
            case CheckResult.Ask:
                PrivacyPrivilegeManager.RequestPermission(permission);
                break;
            }
        }
Example #16
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);
            }
        }
Example #19
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);
            }
Example #20
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);
        }
Example #21
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;
            }
        }
        /// <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);
        }
Example #23
0
        /// <summary>
        /// Used to check privilege.
        /// </summary>
        public void CheckPrivilege(string privilege)
        {
            CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);

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

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

            case CheckResult.Ask:
                /// Request permission to user
                PrivacyPrivilegeManager.RequestPermission(privilege);
                break;
            }
        }
        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;
                }
            }
        }
        /// <summary>
        /// Check privilege.
        /// </summary>
        /// <param name="privilege">The string for privilege.</param>
        public void CheckPrivilege(string privilege)
        {
            CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);

            switch (result)
            {
            case CheckResult.Allow:
                Log.Info("AudioIOSample", $"Privilege \"{privilege}\" : allowed.");
                /// Privilege can be used
                break;

            case CheckResult.Deny:
                Log.Info("AudioIOSample", $"Privilege \"{privilege}\" : denied.");
                /// Privilege can't be used
                break;

            case CheckResult.Ask:
                /// Request permission to user
                PrivacyPrivilegeManager.RequestPermission(privilege);
                break;
            }
        }
Example #28
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);
            }
        }
Example #29
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);
        }
        public bool writeRec(String desc, String tagPic, double amount)
        {
            String write;

            if (amount > 0)
            {
                write = "+" + amount.ToString();
            }
            else
            {
                write = amount.ToString();
            }
            String curr     = DateTime.Now.ToString("yyyy-MM-dd");
            String x        = "";//Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            String currTime = DateTime.Now.ToLongTimeString().ToString();

            String[] ap = new String[4];
            ap[0] = currTime;
            ap[1] = tagPic;
            ap[2] = desc;
            ap[3] = write;
            try
            {
                String      priv = "http://tizen.org/privilege/externalstorage.appdata";
                CheckResult cr   = PrivacyPrivilegeManager.CheckPermission(priv);
                Toast.DisplayText(Environment.CurrentDirectory);
                if (cr == CheckResult.Deny)
                {
                    PrivacyPrivilegeManager.RequestPermission(priv);
                }
                File.AppendAllLines(x + curr + ".txt", ap);
            }
            catch (Exception e)
            {
                Toast.DisplayText(e.Message);
                return(false);
            }
            return(true);
        }