[WidgetControl] Add get widget count API for internal (#1760)
authorsukhyungkang <35091460+sukhyungkang@users.noreply.github.com>
Fri, 26 Jun 2020 04:13:44 +0000 (13:13 +0900)
committerGitHub <noreply@github.com>
Fri, 26 Jun 2020 04:13:44 +0000 (13:13 +0900)
* Add get widget count API for internal

Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
* Update WidgetControl.cs

* Update Interop.WidgetService.cs

src/Tizen.Applications.WidgetControl/Interop/Interop.WidgetService.cs
src/Tizen.Applications.WidgetControl/Tizen.Applications/WidgetControl.cs

index 10536d0..74608b1 100755 (executable)
@@ -109,6 +109,12 @@ internal static partial class Interop
         [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_package_id")]
         internal static extern string GetWidgetPackageId(string widgetId);
 
+        [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_widget_max_count")]
+        internal static extern int GetWidgetMaxCount(string widgetId);
+
+        [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_instance_count")]
+        internal static extern int GetWidgetInstanceCount(string widgetId, string cluster, string category);
+
         [DllImport(Libraries.WidgetService, EntryPoint = "widget_service_get_app_id_of_setup_app")]
         internal static extern string GetSetupAppId(string widgetId);
     }
index 423a787..c6eb9ab 100755 (executable)
@@ -18,6 +18,7 @@ using System;
 using System.Collections.Generic;
 using Tizen.Applications;
 using System.Runtime.InteropServices;
+using System.ComponentModel;
 
 namespace Tizen.Applications
 {
@@ -475,6 +476,47 @@ namespace Tizen.Applications
                 return str;
             }
         }
+        
+        /// <summary>
+        /// Gets widget max count
+        /// </summary>
+        /// <since_tizen> 8 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int MaxCount
+        {
+            get
+            {
+                int ret = Interop.WidgetService.GetWidgetMaxCount(Id);
+
+                switch ((Interop.WidgetService.ErrorCode)ret)
+                {
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException();
+
+                    case Interop.WidgetService.ErrorCode.PermissionDenied:
+                        throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.InvalidParameter:
+                        throw new InvalidOperationException("Invalid parameter");
+
+                    case Interop.WidgetService.ErrorCode.IoError:
+                        throw new InvalidOperationException("Failed to access DB");
+
+                    case Interop.WidgetService.ErrorCode.Fault:
+                        throw new InvalidOperationException("Failed to get information from DB");
+
+                    case Interop.WidgetService.ErrorCode.NotExist:
+                        throw new InvalidOperationException("The data does not exist");
+                }
+
+                return ret;
+            }
+        }
 
         /// <summary>
         ///  The event handler for a created widget instance.
@@ -769,6 +811,36 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets widget instance count
+        /// </summary>
+        /// <since_tizen> 8 </since_tizen>
+        /// <returns>The widget instance count.</returns>
+        /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int GetInstanceCount()
+        {
+            int ret = Interop.WidgetService.GetWidgetInstanceCount(Id, null, null);
+
+            switch ((Interop.WidgetService.ErrorCode)ret)
+            {
+                case Interop.WidgetService.ErrorCode.NotSupported:
+                    throw new NotSupportedException();
+
+                case Interop.WidgetService.ErrorCode.InvalidParameter:
+                    throw new InvalidOperationException("Invalid parameter");
+
+                case Interop.WidgetService.ErrorCode.PermissionDenied:
+                    throw new UnauthorizedAccessException();
+            }
+
+            return ret;
+        }
+
+        /// <summary>
         /// Releases all the resources used by the WidgetControl class.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>