From 3db784a18f6fb276d07bdfa1f4f398df83fce3f2 Mon Sep 17 00:00:00 2001 From: yl33 <31228316+yl33@users.noreply.github.com> Date: Thu, 2 Jul 2020 13:25:06 +0900 Subject: [PATCH] [Security] Return error when the given privilege not exist (#1561) * [ACR] Return error when the given privilege not exist Signed-off-by: Yunjin Lee * Merge separated remarks tags into 1 and revert API comment changes on deprecated API Signed-off-by: Yunjin Lee * Merge separated remarks tags Signed-off-by: Yunjin Lee --- src/Tizen.Security/Interop/Interop.Privilege.cs | 5 +++++ src/Tizen.Security/Tizen.Security/Privilege.cs | 24 ++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Tizen.Security/Interop/Interop.Privilege.cs b/src/Tizen.Security/Interop/Interop.Privilege.cs index 4c92cc3..02f09f5 100755 --- a/src/Tizen.Security/Interop/Interop.Privilege.cs +++ b/src/Tizen.Security/Interop/Interop.Privilege.cs @@ -39,5 +39,10 @@ internal static partial class Interop [DllImport(Libraries.Privilege, EntryPoint = "privilege_info_get_privacy_display_name")] internal static extern int GetPrivacyDisplayName(string privilege, out string displayName); + + internal enum ErrorCode + { + NoMatchingPrivilege = -0x01E20000 | 0x01 + } } } diff --git a/src/Tizen.Security/Tizen.Security/Privilege.cs b/src/Tizen.Security/Tizen.Security/Privilege.cs index 00268c1..fda3d00 100755 --- a/src/Tizen.Security/Tizen.Security/Privilege.cs +++ b/src/Tizen.Security/Tizen.Security/Privilege.cs @@ -50,12 +50,12 @@ namespace Tizen.Security /// Gets the display name of the given privilege. /// /// 3 - /// If there's no matching privilege, then it returns last token of the given privilege. + /// If there's no matching privilege, then it returns last token of the given privilege. Since Tizen 6.0, if there's no matching privilege then it returns ArgumentException. /// The API version. /// The privilege. /// The display name of the given privilege at the given API version. /// Thrown when there is a null parameter. - /// Thrown when there is an invalid parameter. + /// Thrown when there is an invalid parameter such as a non-existing privilege. /// Thrown when out of memory occurs. /// Thrown when an internal error occurs. public static string GetDisplayName(string apiVersion, string privilege) @@ -73,13 +73,13 @@ namespace Tizen.Security /// Gets the display name of the given privilege. /// /// 3 - /// If there's no matching privilege, then it returns last token of the given privilege. + /// If there's no matching privilege, then it returns last token of the given privilege. Since Tizen 6.0, if there's no matching privilege then it returns ArgumentException. /// The API version. /// The privilege. /// The type of application package. /// The display name of the given privilege at the given API version and the package type. /// Thrown when there is a null parameter. - /// Thrown when there is an invalid parameter. + /// Thrown when there is an invalid parameter such as a non-existing privilege. /// Thrown when out of memory occurs. /// Thrown when an internal error occurs. public static string GetDisplayName(string apiVersion, string privilege, PackageType packageType) @@ -97,12 +97,12 @@ namespace Tizen.Security /// Gets the description of the given privilege. /// /// 3 - /// If there's no matching privilege, then it returns description string for undefined privilege. + /// If there's no matching privilege, then it returns description string for undefined privilege. Since Tizen 6.0, if there's no matching privilege then it returns ArgumentException. /// The API version. /// The privilege. /// The description of given privilege at the given API version /// Thrown when there is a null parameter. - /// Thrown when there is an invalid parameter. + /// Thrown when there is an invalid parameter such as a non-existing privilege. /// Thrown when out of memory occurs. /// Thrown when an internal error occurs. public static string GetDescription(string apiVersion, string privilege) @@ -120,13 +120,13 @@ namespace Tizen.Security /// Gets the description of the given privilege. /// /// 3 - /// If there's no matching privilege, then it returns description string for undefined privilege. + /// If there's no matching privilege, then it returns description string for undefined privilege. Since Tizen 6.0, if there's no matching privilege then it returns ArgumentException. /// The API version. /// The privilege. /// The type of application package. /// The description of given privilege at the given API version and the package type. /// Thrown when there is a null parameter. - /// Thrown when there is an invalid parameter. + /// Thrown when there is an invalid parameter such as a non-existing privilege. /// Thrown when out of memory occurs. /// Thrown when an internal error occurs. public static string GetDescription(string apiVersion, string privilege, PackageType packageType) @@ -149,7 +149,7 @@ namespace Tizen.Security /// The privilege must be privacy related. /// The privacy group's display name that the given privilege is included in. /// Thrown when there is a null parameter. - /// Thrown when there is an invalid parameter. + /// Thrown when there is an invalid parameter such as a non-existing privilege. /// Thrown when out of memory occurs. /// Thrown when an internal error occurs. /// The required feature is not supported. @@ -176,11 +176,15 @@ namespace Tizen.Security { if (err == (int)ErrorCode.None) return; - Tizen.Log.Error(Interop.Privilege.LogTag, "[" + ErrorFacts.GetErrorMessage(err) + "] " + msg); + if (err == (int)Interop.Privilege.ErrorCode.NoMatchingPrivilege) + Tizen.Log.Error(Interop.Privilege.LogTag, "[System.ArgumentException] No such a privilege. " + msg); + else + Tizen.Log.Error(Interop.Privilege.LogTag, "[" + ErrorFacts.GetErrorMessage(err) + "] " + msg); switch (err) { case (int)ErrorCode.NotSupported: throw new NotSupportedException(); + case (int)Interop.Privilege.ErrorCode.NoMatchingPrivilege: case (int)ErrorCode.InvalidParameter: throw new ArgumentException(); case (int)ErrorCode.OutOfMemory: -- 2.7.4