Esempio n. 1
0
        /// <summary>
        /// Triggers the permission request for a user.
        /// </summary>
        /// <param name="privilege">The privacy privilege to be requested.</param>
        /// <exception cref="ArgumentException">Thrown when an invalid parameter is passed.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when a memory error occurred.</exception>
        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal I/O error.</exception>
        /// <example>
        /// <code>
        ///     CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/account.read");
        ///     switch (result)
        ///     {
        ///         case Allow:
        ///             // Privilege can be used
        ///             break;
        ///         case Deny:
        ///             // Privilege can't be used
        ///             break;
        ///         case Ask:
        ///             // User permission request required
        ///             PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/account.read");
        ///             break;
        ///     }
        /// </code>
        /// </example>
        /// <since_tizen> 4 </since_tizen>
        public static void RequestPermission(string privilege)
        {
            int ret = (int)Interop.PrivacyPrivilegeManager.RequestPermission(privilege, s_requestResponseCb, IntPtr.Zero);

            if (ret != (int)Interop.PrivacyPrivilegeManager.ErrorCode.None)
            {
                Log.Error(LogTag, "Failed to request permission");
                throw PrivacyPrivilegeManagerErrorFactory.GetException(ret);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the status of a privacy privilege permission.
        /// </summary>
        /// <param name="privilege">The privacy privilege to be checked.</param>
        /// <returns>The permission setting for a respective privilege.</returns>
        /// <exception cref="ArgumentException">Thrown when an invalid parameter is passed.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when a memory error occurred.</exception>
        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal I/O error.</exception>
        /// <example>
        /// <code>
        ///     CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/account.read");
        ///     switch (result)
        ///     {
        ///         case Allow:
        ///             // Privilege can be used
        ///             break;
        ///         case Deny:
        ///             // Privilege can't be used
        ///             break;
        ///         case Ask:
        ///             // User permission request required
        ///             PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/account.read");
        ///             break;
        ///     }
        /// </code>
        /// </example>
        /// <since_tizen> 4 </since_tizen>
        public static CheckResult CheckPermission(string privilege)
        {
            Interop.PrivacyPrivilegeManager.CheckResult result;
            int ret = (int)Interop.PrivacyPrivilegeManager.CheckPermission(privilege, out result);

            if (ret != (int)Interop.PrivacyPrivilegeManager.ErrorCode.None)
            {
                Log.Error(LogTag, "Failed to check permission");
                throw PrivacyPrivilegeManagerErrorFactory.GetException(ret);
            }
            return((CheckResult)result);
        }
Esempio n. 3
0
        /// <summary>
        /// Triggers the permissions request for a user.
        /// </summary>
        /// <param name="privileges">The privacy privileges to be requested.</param>
        /// <exception cref="ArgumentException">Thrown when an invalid parameter is passed.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when a memory error occurred.</exception>
        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal I/O error.</exception>
        /// <returns>Permission request Task</returns>
        /// <example>
        /// <code>
        ///     string[] privileges = new [] {"http://tizen.org/privilege/account.read",
        ///                                   "http://tizen.org/privilege/alarm"};
        ///     CheckResult[] results = PrivacyPrivilegeManager.CheckPermissions(privileges).ToArray();
        ///     List&lt;string&gt; privilegesWithAskStatus = new List&lt;string&gt;();
        ///     for (int iterator = 0; iterator &lt; results.Length; ++iterator)
        ///     {
        ///         switch (results[iterator])
        ///         {
        ///             case CheckResult.Allow:
        ///                 // Privilege can be used
        ///                 break;
        ///             case CheckResult.Deny:
        ///                 // Privilege can't be used
        ///                 break;
        ///             case CheckResult.Ask:
        ///                 // User permission request required
        ///                 privilegesWithAskStatus.Add(privileges[iterator]);
        ///                 break;
        ///         }
        ///     }
        ///     IEnumerable&lt;PermissionRequestResponse&gt; responses = PrivacyPrivilegeManager.RequestPermissions(privilegesWithAskStatus).Result;
        ///     //handle responses
        /// </code>
        /// </example>
        /// <since_tizen> 6 </since_tizen>
        public static Task <RequestMultipleResponseEventArgs> RequestPermissions(IEnumerable <string> privileges)
        {
            string[] privilegesArray = CheckPrivilegesArgument(privileges, "RequestPermissions");

            for (int iterator = 0; iterator < privilegesArray.Length; ++iterator)
            {
                if (!s_PrivilegesInProgress.Add(privilegesArray[iterator]))
                {
                    Log.Error(LogTag, "Request for this privilege: " + privilegesArray[iterator] + " is already in progress.");

                    for (int removeIterator = iterator - 1; removeIterator >= 0; --removeIterator)
                    {
                        s_PrivilegesInProgress.Remove(privilegesArray[removeIterator]);
                    }
                    Log.Error(LogTag, "Request for this privilege: " + privilegesArray[iterator] + " is already in progress.");
                    throw new ArgumentException("Request for this privilege: " + privilegesArray[iterator] + " is already in progress.");
                }
            }

            Log.Info(LogTag, "Sending request for permissions: " + string.Join(" ", privilegesArray));

            int requestId = 0;

            lock (s_multipleRequestMap)
            {
                requestId = s_requestId++;
            }
            TaskCompletionSource <RequestMultipleResponseEventArgs> permissionResponsesTask = new TaskCompletionSource <RequestMultipleResponseEventArgs>();

            s_multipleRequestMap[requestId] = permissionResponsesTask;
            int ret = (int)Interop.PrivacyPrivilegeManager.RequestPermissions(privilegesArray, (uint)privilegesArray.Length, s_multipleCallback, (IntPtr)requestId);

            if (ret != (int)Interop.PrivacyPrivilegeManager.ErrorCode.None)
            {
                Log.Error(LogTag, "Failed to request permissions.");
                foreach (string privilege in privileges)
                {
                    s_PrivilegesInProgress.Remove(privilege);
                }
                s_multipleRequestMap.Remove(requestId);
                throw PrivacyPrivilegeManagerErrorFactory.GetException(ret);
            }
            else
            {
                Log.Info(LogTag, "Requesting permissions successfull.");
                return(permissionResponsesTask.Task);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Triggers the permission request for a user.
        /// </summary>
        /// <param name="privilege">The privacy privilege to be requested.</param>
        /// <exception cref="ArgumentException">Thrown when an invalid parameter is passed.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when a memory error occurred.</exception>
        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal I/O error.</exception>
        /// <example>
        /// <code>
        ///     CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/account.read");
        ///     switch (result)
        ///     {
        ///         case Allow:
        ///             // Privilege can be used
        ///             break;
        ///         case Deny:
        ///             // Privilege can't be used
        ///             break;
        ///         case Ask:
        ///             // User permission request required
        ///             PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/account.read");
        ///             break;
        ///     }
        /// </code>
        /// </example>
        /// <since_tizen> 4 </since_tizen>
        public static void RequestPermission(string privilege)
        {
            if (!s_PrivilegesInProgress.Add(privilege))
            {
                Log.Error(LogTag, "Request for this privilege: " + privilege + " is already in progress.");
                throw new ArgumentException("Request for this privilege: " + privilege + " is already in progress.");
            }

            int ret = (int)Interop.PrivacyPrivilegeManager.RequestPermission(privilege, s_requestResponseCb, IntPtr.Zero);

            if (ret != (int)Interop.PrivacyPrivilegeManager.ErrorCode.None)
            {
                Log.Error(LogTag, "Failed to request permission");
                s_PrivilegesInProgress.Remove(privilege);
                throw PrivacyPrivilegeManagerErrorFactory.GetException(ret);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the status of a privacy privileges permission.
        /// </summary>
        /// <param name="privileges">The privacy privileges to be checked.</param>
        /// <returns>The permission setting for a respective privileges.</returns>
        /// <exception cref="ArgumentException">Thrown when an invalid parameter is passed.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when a memory error occurred.</exception>
        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal I/O error.</exception>
        /// <example>
        /// <code>
        ///     string[] privileges = new [] {"http://tizen.org/privilege/account.read",
        ///                                   "http://tizen.org/privilege/alarm"};
        ///     CheckResult[] results = PrivacyPrivilegeManager.CheckPermissions(privileges).ToArray();
        ///     List&lt;string&gt; privilegesWithAskStatus = new List&lt;string&gt;();
        ///     for (int iterator = 0; iterator &lt; results.Length; ++iterator)
        ///     {
        ///         switch (results[iterator])
        ///         {
        ///             case CheckResult.Allow:
        ///                 // Privilege can be used
        ///                 break;
        ///             case CheckResult.Deny:
        ///                 // Privilege can't be used
        ///                 break;
        ///             case CheckResult.Ask:
        ///                 // User permission request required
        ///                 privilegesWithAskStatus.Add(privileges[iterator]);
        ///                 break;
        ///         }
        ///     }
        ///     PrivacyPrivilegeManager.RequestPermissions(privilegesWithAskStatus);
        /// </code>
        /// </example>
        /// <since_tizen> 6 </since_tizen>
        public static IEnumerable <CheckResult> CheckPermissions(IEnumerable <string> privileges)
        {
            string[] privilegesArray = CheckPrivilegesArgument(privileges, "CheckPermissions");

            Interop.PrivacyPrivilegeManager.CheckResult[] results = new Interop.PrivacyPrivilegeManager.CheckResult[privilegesArray.Length];
            int ret = (int)Interop.PrivacyPrivilegeManager.CheckPermissions(privilegesArray, (uint)privilegesArray.Length, results);

            if (ret != (int)Interop.PrivacyPrivilegeManager.ErrorCode.None)
            {
                Log.Error(LogTag, "Failed to check permission");
                throw PrivacyPrivilegeManagerErrorFactory.GetException(ret);
            }

            CheckResult[] checkResults = new CheckResult[results.Length];
            for (int iterator = 0; iterator < results.Length; ++iterator)
            {
                checkResults[iterator] = (CheckResult)results[iterator];
            }
            return(checkResults);
        }
Esempio n. 6
0
        /// <summary>
        /// Triggers the permissions request for a user.
        /// </summary>
        /// <param name="privileges">The privacy privileges to be requested.</param>
        /// <exception cref="ArgumentException">Thrown when an invalid parameter is passed.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when a memory error occurred.</exception>
        /// <exception cref="System.IO.IOException">Thrown when the method failed due to an internal I/O error.</exception>
        /// <returns>Permission request Task</returns>
        /// <example>
        /// <code>
        ///     string[] privileges = new [] {"http://tizen.org/privilege/account.read",
        ///                                   "http://tizen.org/privilege/alarm"};
        ///     CheckResult[] results = PrivacyPrivilegeManager.CheckPermissions(privileges).ToArray();
        ///     List&lt;string&gt; privilegesWithAskStatus = new List&lt;string&gt;();
        ///     for (int iterator = 0; iterator &lt; results.Length; ++iterator)
        ///     {
        ///         switch (results[iterator])
        ///         {
        ///             case CheckResult.Allow:
        ///                 // Privilege can be used
        ///                 break;
        ///             case CheckResult.Deny:
        ///                 // Privilege can't be used
        ///                 break;
        ///             case CheckResult.Ask:
        ///                 // User permission request required
        ///                 privilegesWithAskStatus.Add(privileges[iterator]);
        ///                 break;
        ///         }
        ///     }
        ///     IEnumerable&lt;PermissionRequestResponse&gt; responses = PrivacyPrivilegeManager.RequestPermissions(privilegesWithAskStatus).Result;
        ///     //handle responses
        /// </code>
        /// </example>
        /// <since_tizen> 6 </since_tizen>
        public static Task <RequestMultipleResponseEventArgs> RequestPermissions(IEnumerable <string> privileges)
        {
            string[] privilegesArray = CheckPrivilegesArgument(privileges, "RequestPermissions");

            for (int iterator = 0; iterator < privilegesArray.Length; ++iterator)
            {
                if (!s_PrivilegesInProgress.Add(privilegesArray[iterator]))
                {
                    Log.Error(LogTag, "Request for this privilege: " + privilegesArray[iterator] + " is already in progress.");

                    for (int removeIterator = iterator - 1; removeIterator >= 0; --removeIterator)
                    {
                        s_PrivilegesInProgress.Remove(privilegesArray[removeIterator]);
                    }
                    Log.Error(LogTag, "Request for this privilege: " + privilegesArray[iterator] + " is already in progress.");
                    throw new ArgumentException("Request for this privilege: " + privilegesArray[iterator] + " is already in progress.");
                }
            }

            Log.Info(LogTag, "Sending request for permissions: " + string.Join(" ", privilegesArray));

            TaskCompletionSource <RequestMultipleResponseEventArgs> permissionResponsesTask = new TaskCompletionSource <RequestMultipleResponseEventArgs>();
            int ret = (int)Interop.PrivacyPrivilegeManager.RequestPermissions(privilegesArray, (uint)privilegesArray.Length,
                                                                              (Interop.PrivacyPrivilegeManager.CallCause cause, Interop.PrivacyPrivilegeManager.RequestResult[] results,
                                                                               string[] requestedPrivileges, uint privilegesCount, IntPtr userData) =>
            {
                Log.Info(LogTag, "Sending request for permissions: ");
                RequestMultipleResponseEventArgs requestResponse = new RequestMultipleResponseEventArgs();
                PermissionRequestResponse[] permissionResponses  = new PermissionRequestResponse[privilegesCount];

                for (int iterator = 0; iterator < privilegesCount; ++iterator)
                {
                    permissionResponses[iterator] = new PermissionRequestResponse
                    {
                        Privilege = requestedPrivileges[iterator],
                        Result    = (RequestResult)results[iterator]
                    };
                }
                requestResponse.Cause     = (CallCause)cause;
                requestResponse.Responses = permissionResponses;

                foreach (string privilege in requestedPrivileges)
                {
                    s_PrivilegesInProgress.Remove(privilege);
                }
                permissionResponsesTask.SetResult(requestResponse);
            }, IntPtr.Zero);

            if (ret != (int)Interop.PrivacyPrivilegeManager.ErrorCode.None)
            {
                Log.Error(LogTag, "Failed to request permissions.");
                foreach (string privilege in privileges)
                {
                    s_PrivilegesInProgress.Remove(privilege);
                }
                throw PrivacyPrivilegeManagerErrorFactory.GetException(ret);
            }
            else
            {
                Log.Info(LogTag, "Requesting permissions successfull.");
                return(permissionResponsesTask.Task);
            }
        }