Class PrivacyPrivilegeManager
Definition
- Assembly:
- Tizen.Security.PrivacyPrivilegeManager.dll
The PrivacyPrivilegeManager provides the properties or methods to check and request a permission for privacy privilege.
public static class PrivacyPrivilegeManager
- Inheritance
-
objectPrivacyPrivilegeManager
Methods
View SourceCheckPermission(string)
Gets the status of a privacy privilege permission.
Declaration
public static CheckResult CheckPermission(string privilege)
Parameters
Type | Name | Description |
---|---|---|
string | privilege | The privacy privilege to be checked. |
Returns
Type | Description |
---|---|
CheckResult | The permission setting for a respective privilege. |
Examples
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;
}
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when an invalid parameter is passed. |
System.OutOfMemoryException | Thrown when a memory error occurred. |
System.IO.IOException | Thrown when the method failed due to an internal I/O error. |
CheckPermissions(IEnumerable<string>)
Gets the status of a privacy privileges permission.
Declaration
public static IEnumerable<CheckResult> CheckPermissions(IEnumerable<string> privileges)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><string> | privileges | The privacy privileges to be checked. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><CheckResult> | The permission setting for a respective privileges. |
Examples
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;
}
}
PrivacyPrivilegeManager.RequestPermissions(privilegesWithAskStatus);
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when an invalid parameter is passed. |
System.OutOfMemoryException | Thrown when a memory error occurred. |
System.IO.IOException | Thrown when the method failed due to an internal I/O error. |
GetResponseContext(string)
Gets the response context for a given privilege.
Declaration
public static WeakReference<PrivacyPrivilegeManager.ResponseContext> GetResponseContext(string privilege)
Parameters
Type | Name | Description |
---|---|---|
string | privilege | The privilege. |
Returns
Type | Description |
---|---|
System.WeakReference<T><PrivacyPrivilegeManager.ResponseContext> | The response context of a respective privilege. |
Examples
private static void PPM_RequestResponse(object sender, RequestResponseEventArgs e)
{
if (e.cause == CallCause.Answer)
{
switch(e.result)
{
case RequestResult.AllowForever:
Console.WriteLine("User allowed usage of privilege {0} definitely", e.privilege);
break;
case RequestResult.DenyForever:
Console.WriteLine("User denied usage of privilege {0} definitely", e.privilege);
break;
case RequestResult.DenyOnce:
Console.WriteLine("User denied usage of privilege {0} this time", e.privilege);
break;
};
}
else
{
Console.WriteLine("Error occured during requesting permission for {0}", e.privilege);
}
}
PrivacyPrivilegeManager.ResponseContext context = null;
PrivacyPrivilegeManager.GetResponseContext("http://tizen.org/privilege/account.read").TryGetTarget(out context);
if(context != null)
{
context.ResponseFetched += PPM_RequestResponse;
}
PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/account.read");
PrivacyPrivilegeManager.GetResponseContext("http://tizen.org/privilege/account.read").TryGetTarget(out context);
if(context != null)
{
context.ResponseFetched -= PPM_RequestResponse;
}
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if the key is an invalid parameter. |
See Also
View SourceRequestPermission(string)
Triggers the permission request for a user.
Declaration
public static void RequestPermission(string privilege)
Parameters
Type | Name | Description |
---|---|---|
string | privilege | The privacy privilege to be requested. |
Examples
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;
}
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when an invalid parameter is passed. |
System.OutOfMemoryException | Thrown when a memory error occurred. |
System.IO.IOException | Thrown when the method failed due to an internal I/O error. |
RequestPermissions(IEnumerable<string>)
Triggers the permissions request for a user.
Declaration
public static Task<RequestMultipleResponseEventArgs> RequestPermissions(IEnumerable<string> privileges)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><string> | privileges | The privacy privileges to be requested. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TResult><RequestMultipleResponseEventArgs> | Permission request Task |
Examples
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
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when an invalid parameter is passed. |
System.OutOfMemoryException | Thrown when a memory error occurred. |
System.IO.IOException | Thrown when the method failed due to an internal I/O error. |