private static void MultipleRequestHandler(Interop.PrivacyPrivilegeManager.CallCause cause, Interop.PrivacyPrivilegeManager.RequestResult[] results, string[] requestedPrivileges, uint privilegesCount, IntPtr userData) { int requestId = (int)userData; if (!s_multipleRequestMap.ContainsKey(requestId)) { return; } var tcs = s_multipleRequestMap[requestId]; 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); } tcs.SetResult(requestResponse); s_multipleRequestMap.Remove(requestId); }
/// <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<string> privilegesWithAskStatus = new List<string>(); /// for (int iterator = 0; iterator < 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<PermissionRequestResponse> 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); } }