[ThemeManager] Add new internal API for ThemeManager (#2610)
authorjeremy-jang <35089715+jeremy-jang@users.noreply.github.com>
Wed, 3 Feb 2021 23:17:51 +0000 (08:17 +0900)
committerGitHub <noreply@github.com>
Wed, 3 Feb 2021 23:17:51 +0000 (08:17 +0900)
* [ThemeManager] Add new internal API for ThemeManager

A new API added:
 - Tizen.Applications.Theme.HasKey(string key)

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
* [ThemeManager] Fix ThemeManager native library name

Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
internals/src/Tizen.Applications.ThemeManager/Interop/Interop.Libraries.cs
internals/src/Tizen.Applications.ThemeManager/Interop/Interop.ThemeManager.cs
internals/src/Tizen.Applications.ThemeManager/Tizen.Applications.ThemeManager/Theme.cs

index c5b50fbc82ef1a14b1fdb5057f0179fb541f44d4..a117eb7bdd51e5b4ae32aee9321b8b337a742155 100755 (executable)
@@ -18,6 +18,6 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
-        public const string ThemeManager = "libcapi-appfw-tizen-theme.so";
+        public const string ThemeManager = "libcapi-appfw-tizen-theme.so.1";
     }
 }
index f5f472828d5ec58fe1551e520d7917e4fe97d0b2..2b5d756cab75cfc946b040f71fbd3b7dad660a20 100755 (executable)
@@ -15,6 +15,8 @@
  */
 
 using System;
+using System.Collections.Generic;
+using System.IO;
 using System.Runtime.InteropServices;
 using Tizen;
 using Tizen.Applications;
@@ -31,6 +33,8 @@ internal static partial class Interop
             InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
             PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
             IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+            NoSuchTheme = Tizen.Internals.Errors.ErrorCode.NoSuchFile,
+            KeyNotAvailable = Tizen.Internals.Errors.ErrorCode.KeyNotAvailable,
         }
 
         internal static class ThemeManagerErrorFactory
@@ -45,6 +49,10 @@ internal static partial class Interop
                         return new ArgumentException(errMessage);
                     case Interop.ThemeManager.ErrorCode.PermissionDenied:
                         return new UnauthorizedAccessException(errMessage);
+                    case Interop.ThemeManager.ErrorCode.NoSuchTheme:
+                        return new FileNotFoundException(errMessage);
+                    case Interop.ThemeManager.ErrorCode.KeyNotAvailable:
+                        return new KeyNotFoundException(errMessage);
                     case Interop.ThemeManager.ErrorCode.IoError:
                     default:
                         return new InvalidOperationException(errMessage);
@@ -97,6 +105,9 @@ internal static partial class Interop
         [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_bool")]
         internal static extern ErrorCode GetBool(IntPtr handle, string key, out bool val);
 
+        [DllImport(Libraries.ThemeManager, EntryPoint = "theme_is_key_exist")]
+        internal static extern ErrorCode IsKeyExist(IntPtr handle, string key, out bool val);
+
         [DllImport(Libraries.ThemeManager, EntryPoint = "theme_clone")]
         internal static extern ErrorCode ThemeClone(IntPtr handle, out IntPtr cloned);
 
index d33372fc7cf3c33255fb04cfc4d5a444639cf2fb..0e52b0ee164577bed29e823b1050787e7be324ab 100755 (executable)
@@ -306,6 +306,25 @@ namespace Tizen.Applications.ThemeManager
                 managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
             }
         }
+
+        /// <summary>
+        /// Check the given key is exist or not.
+        /// </summary>
+        /// <param name="key">The string key to find information.</param>
+        /// <since_tizen> 9 </since_tizen>
+        /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+        public bool HasKey(string key)
+        {
+            bool val;
+            var err = Interop.ThemeManager.IsKeyExist(_handle, key, out val);
+            if (err != Interop.ThemeManager.ErrorCode.None)
+            {
+                throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to check existence of the key");
+            }
+
+            return val;
+        }
+
         /// <summary>
         /// Releases all resources used by the Theme class.
         /// </summary>