[Security] Return error when the given privilege not exist (#1561)
authoryl33 <31228316+yl33@users.noreply.github.com>
Thu, 2 Jul 2020 04:25:06 +0000 (13:25 +0900)
committerGitHub <noreply@github.com>
Thu, 2 Jul 2020 04:25:06 +0000 (13:25 +0900)
* [ACR] Return error when the given privilege not exist

Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
* Merge separated remarks tags into 1 and revert API comment changes on deprecated API

Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
* Merge separated remarks tags

Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
src/Tizen.Security/Interop/Interop.Privilege.cs
src/Tizen.Security/Tizen.Security/Privilege.cs

index 4c92cc3..02f09f5 100755 (executable)
@@ -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
+        }
     }
 }
index 00268c1..fda3d00 100755 (executable)
@@ -50,12 +50,12 @@ namespace Tizen.Security
         /// Gets the display name of the given privilege.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <remarks>If there's no matching privilege, then it returns last token of the given privilege.</remarks>
+        /// <remarks>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. </remarks>
         /// <param name="apiVersion">The API version.</param>
         /// <param name="privilege">The privilege.</param>
         /// <returns>The display name of the given privilege at the given API version.</returns>
         /// <exception cref="System.ArgumentNullException">Thrown when there is a null parameter.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter such as a non-existing privilege.</exception>
         /// <exception cref="System.OutOfMemoryException">Thrown when out of memory occurs.</exception>
         /// <exception cref="System.InvalidOperationException">Thrown when an internal error occurs.</exception>
         public static string GetDisplayName(string apiVersion, string privilege)
@@ -73,13 +73,13 @@ namespace Tizen.Security
         /// Gets the display name of the given privilege.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <remarks>If there's no matching privilege, then it returns last token of the given privilege.</remarks>
+        /// <remarks>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.</remarks>
         /// <param name="apiVersion">The API version.</param>
         /// <param name="privilege">The privilege.</param>
         /// <param name="packageType">The type of application package.</param>
         /// <returns>The display name of the given privilege at the given API version and the package type.</returns>
         /// <exception cref="System.ArgumentNullException">Thrown when there is a null parameter.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter such as a non-existing privilege.</exception>
         /// <exception cref="System.OutOfMemoryException">Thrown when out of memory occurs.</exception>
         /// <exception cref="System.InvalidOperationException">Thrown when an internal error occurs.</exception>
         public static string GetDisplayName(string apiVersion, string privilege, PackageType packageType)
@@ -97,12 +97,12 @@ namespace Tizen.Security
         /// Gets the description of the given privilege.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <remarks>If there's no matching privilege, then it returns description string for undefined privilege.</remarks>
+        /// <remarks>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. </remarks>
         /// <param name="apiVersion">The API version.</param>
         /// <param name="privilege">The privilege.</param>
         /// <returns>The description of given privilege at the given API version</returns>
         /// <exception cref="System.ArgumentNullException">Thrown when there is a null parameter.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter such as a non-existing privilege.</exception>
         /// <exception cref="System.OutOfMemoryException">Thrown when out of memory occurs.</exception>
         /// <exception cref="System.InvalidOperationException">Thrown when an internal error occurs.</exception>
         public static string GetDescription(string apiVersion, string privilege)
@@ -120,13 +120,13 @@ namespace Tizen.Security
         /// Gets the description of the given privilege.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <remarks>If there's no matching privilege, then it returns description string for undefined privilege.</remarks>
+        /// <remarks>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. </remarks>
         /// <param name="apiVersion">The API version.</param>
         /// <param name="privilege">The privilege.</param>
         /// <param name="packageType">The type of application package.</param>
         /// <returns>The description of given privilege at the given API version and the package type.</returns>
         /// <exception cref="System.ArgumentNullException">Thrown when there is a null parameter.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter such as a non-existing privilege.</exception>
         /// <exception cref="System.OutOfMemoryException">Thrown when out of memory occurs.</exception>
         /// <exception cref="System.InvalidOperationException">Thrown when an internal error occurs.</exception>
         public static string GetDescription(string apiVersion, string privilege, PackageType packageType)
@@ -149,7 +149,7 @@ namespace Tizen.Security
         /// <remarks>The privilege must be privacy related.</remarks>
         /// <returns>The privacy group's display name that the given privilege is included in.</returns>
         /// <exception cref="System.ArgumentNullException">Thrown when there is a null parameter.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter such as a non-existing privilege.</exception>
         /// <exception cref="System.OutOfMemoryException">Thrown when out of memory occurs.</exception>
         /// <exception cref="System.InvalidOperationException">Thrown when an internal error occurs.</exception>
         /// <exception cref="System.NotSupportedException">The required feature is not supported.</exception>
@@ -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: