[Tizen.Applications] Fix static analysis issues (#5389)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.WidgetControl / Tizen.Applications / WidgetControl.cs
index ff6906a..0daff7d 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
 {
@@ -28,6 +29,7 @@ namespace Tizen.Applications
     public class WidgetControl : IDisposable
     {
         private const string LogTag = "Tizen.Applications.WidgetControl";
+        private static Interop.WidgetService.LifecycleCallback _onLifecycleCallback;
         /// <summary>
         /// Class for the widget instance.
         /// </summary>
@@ -50,8 +52,11 @@ namespace Tizen.Applications
             /// <summary>
             /// Gets the widget content.
             /// </summary>
+            /// <returns>The bundle containing widget content.</returns>
             /// <since_tizen> 3 </since_tizen>
+            /// <feature>http://tizen.org/feature/shell.appwidget</feature>
             /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
+            /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
             public Bundle GetContent()
             {
                 IntPtr h;
@@ -62,9 +67,10 @@ namespace Tizen.Applications
                 {
                     case Interop.WidgetService.ErrorCode.InvalidParameter:
                         throw new InvalidOperationException("Invalid parameter at unmanaged code");
-
                     case Interop.WidgetService.ErrorCode.IoError:
                         throw new InvalidOperationException("Failed to access DB");
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
                 }
 
                 return new Bundle(new SafeBundleHandle(h, true));
@@ -76,9 +82,11 @@ namespace Tizen.Applications
             /// <since_tizen> 3 </since_tizen>
             /// <param name="content">Content to be changed.</param>
             /// <param name="force"> True if you want to update your widget even if the provider is paused, otherwise false.</param>
+            /// <feature>http://tizen.org/feature/shell.appwidget</feature>
             /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
             /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-            /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+            /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+            /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
             public void ChangeContent(Bundle content, bool force)
             {
                 Interop.WidgetService.ErrorCode err = Interop.WidgetService.UpdateContent(_widgetId, Id, content.SafeBundleHandle, force ? 1 : 0);
@@ -99,6 +107,9 @@ namespace Tizen.Applications
 
                     case Interop.WidgetService.ErrorCode.PermissionDenied:
                         throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
                 }
             }
 
@@ -106,9 +117,12 @@ namespace Tizen.Applications
             /// Changes the update period for the widget instance.
             /// </summary>
             /// <since_tizen> 3 </since_tizen>
+            /// <param name="period">The period to be changed.</param>
+            /// <feature>http://tizen.org/feature/shell.appwidget</feature>
             /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
             /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-            /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+            /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+            /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
             public void ChangePeriod(double period)
             {
                 Interop.WidgetService.ErrorCode err = Interop.WidgetService.ChangePeriod(_widgetId, Id, period);
@@ -126,6 +140,9 @@ namespace Tizen.Applications
 
                     case Interop.WidgetService.ErrorCode.PermissionDenied:
                         throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
                 }
             }
         }
@@ -253,10 +270,13 @@ namespace Tizen.Applications
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <param name="pkgId">Package ID.</param>
+        /// <returns>The widget control array.</returns>
         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public static WidgetControl[] CreateAll(string pkgId)
         {
             List<WidgetControl> list = new List<WidgetControl>();
@@ -264,6 +284,8 @@ namespace Tizen.Applications
             Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetWidgetListByPkgId(pkgId, (widgetId, isPrime, userData) =>
             {
                 list.Add(new WidgetControl(widgetId));
+
+                return (int)Interop.WidgetService.ErrorCode.None;
             }, IntPtr.Zero);
 
             switch (err)
@@ -276,6 +298,9 @@ namespace Tizen.Applications
 
                 case Interop.WidgetService.ErrorCode.PermissionDenied:
                     throw new UnauthorizedAccessException();
+
+                case Interop.WidgetService.ErrorCode.NotSupported:
+                    throw new NotSupportedException("Not supported");
             }
 
             return list.ToArray();
@@ -285,10 +310,14 @@ namespace Tizen.Applications
         /// Gets all the widget IDs by the package ID.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        /// <param name="pkgId">Package ID.</param>
+        /// <returns>The widget id array.</returns>
         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public static string[] GetWidgetIds(string pkgId)
         {
             List<string> list = new List<string>();
@@ -296,6 +325,8 @@ namespace Tizen.Applications
             Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetWidgetListByPkgId(pkgId, (widgetId, isPrime, userData) =>
             {
                 list.Add(widgetId);
+
+                return (int)Interop.WidgetService.ErrorCode.None;
             }, IntPtr.Zero);
 
             switch (err)
@@ -308,12 +339,71 @@ namespace Tizen.Applications
 
                 case Interop.WidgetService.ErrorCode.PermissionDenied:
                     throw new UnauthorizedAccessException();
+
+                case Interop.WidgetService.ErrorCode.NotSupported:
+                    throw new NotSupportedException("Not supported");
             }
 
             return list.ToArray();
         }
 
         /// <summary>
+        /// Gets main appid of the widget.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
+        public string MainAppId
+        {
+            get
+            {
+                string str = Interop.WidgetService.GetWidgetMainAppId(Id);
+                Interop.WidgetService.ErrorCode err =
+                    (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
+                switch (err)
+                {
+                    case Interop.WidgetService.ErrorCode.PermissionDenied:
+                        throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
+                }
+
+                return str;
+            }
+        }
+
+        /// <summary>
+        /// Gets package ID of the widget.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
+        public string PackageId
+        {
+            get
+            {
+                string str = Interop.WidgetService.GetWidgetPackageId(Id);
+                Interop.WidgetService.ErrorCode err =
+                    (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
+                switch (err)
+                {
+                    case Interop.WidgetService.ErrorCode.PermissionDenied:
+                        throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
+                }
+
+                return str;
+            }
+        }
+
+        /// <summary>
         /// The widget ID.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -324,11 +414,26 @@ namespace Tizen.Applications
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public bool IsNoDisplay
         {
             get
             {
-                if (Interop.WidgetService.GetNoDisplay(Id) != 0)
+                int ret = Interop.WidgetService.GetNoDisplay(Id);
+                Interop.WidgetService.ErrorCode err =
+                    (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
+                switch (err)
+                {
+                    case Interop.WidgetService.ErrorCode.PermissionDenied:
+                        throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
+                }
+
+                if (ret != 0)
                     return true;
 
                 return false;
@@ -336,11 +441,95 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets setup app ID of the widget.
+        /// </summary>
+        /// <since_tizen> 8 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
+        public string SetupAppId
+        {
+            get
+            {
+                string str = Interop.WidgetService.GetSetupAppId(Id);
+                Interop.WidgetService.ErrorCode err =
+                    (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
+                switch (err)
+                {
+                    case Interop.WidgetService.ErrorCode.PermissionDenied:
+                        throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException("Not supported");
+
+                    case Interop.WidgetService.ErrorCode.InvalidParameter:
+                        throw new InvalidOperationException("Invalid parameter at unmanaged code");
+
+                    case Interop.WidgetService.ErrorCode.IoError:
+                        throw new InvalidOperationException("Failed to access DB");
+
+                    case Interop.WidgetService.ErrorCode.Fault:
+                        throw new InvalidOperationException("Failed to access DB");
+
+                    case Interop.WidgetService.ErrorCode.NotExist:
+                        throw new InvalidOperationException("Not exist in DB");
+                }
+
+                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.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public event EventHandler<WidgetLifecycleEventArgs> Created
         {
             add
@@ -359,8 +548,10 @@ namespace Tizen.Applications
         /// The event handler for a resumed widget instance.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public event EventHandler<WidgetLifecycleEventArgs> Resumed
         {
             add
@@ -379,8 +570,10 @@ namespace Tizen.Applications
         /// The event handler for a paused widget instance.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public event EventHandler<WidgetLifecycleEventArgs> Paused
         {
             add
@@ -399,8 +592,10 @@ namespace Tizen.Applications
         /// The event handler for a destroyed widget instance.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public event EventHandler<WidgetLifecycleEventArgs> Destroyed
         {
             add
@@ -436,16 +631,20 @@ namespace Tizen.Applications
         /// <summary>
         /// Gets the objects for widget instance information.
         /// </summary>
+        /// <returns>The instances list.</returns>
         /// <since_tizen> 3 </since_tizen>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
         /// <exception cref="NotSupportedException">Thrown when the API is not supported in this device.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
         public IEnumerable<Instance> GetInstances()
         {
             IList<Instance> instances = new List<Instance>();
             Interop.WidgetService.ErrorCode err = Interop.WidgetService.GetInstances(Id, (widgetId, instanceId, userData) =>
             {
                 instances.Add(new Instance(widgetId) { Id = instanceId });
+
+                return (int)Interop.WidgetService.ErrorCode.None;
             }, IntPtr.Zero);
 
             switch (err)
@@ -466,10 +665,13 @@ namespace Tizen.Applications
         /// <summary>
         /// Gets the objects for widget scale information.
         /// </summary>
+        /// <returns>The scales list.</returns>
         /// <since_tizen> 3 </since_tizen>
         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
-        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public IEnumerable<Scale> GetScales()
         {
             IntPtr wPtr;
@@ -499,6 +701,9 @@ namespace Tizen.Applications
 
                 case Interop.WidgetService.ErrorCode.PermissionDenied:
                     throw new UnauthorizedAccessException();
+
+                case Interop.WidgetService.ErrorCode.NotSupported:
+                    throw new NotSupportedException();
             }
             w = new int[cnt1];
             Marshal.Copy(wPtr, w, 0, cnt1);
@@ -551,14 +756,31 @@ namespace Tizen.Applications
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <param name="lang">Language.</param>
+        /// <returns>The widget name.</returns>
         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public string GetName(string lang)
         {
             if (lang == null)
                 throw new ArgumentNullException();
 
-            return Interop.WidgetService.GetName(Id, lang);
+            string str = Interop.WidgetService.GetName(Id, lang);
+            Interop.WidgetService.ErrorCode err =
+                    (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
+
+            switch (err)
+            {
+                case Interop.WidgetService.ErrorCode.PermissionDenied:
+                    throw new UnauthorizedAccessException();
+
+                case Interop.WidgetService.ErrorCode.NotSupported:
+                    throw new NotSupportedException();
+            }
+
+            return str;
         }
 
         /// <summary>
@@ -566,22 +788,72 @@ namespace Tizen.Applications
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <param name="lang">Language.</param>
+        /// <returns>The widget icon path.</returns>
         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
         /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public string GetIconPath(string lang)
         {
             if (lang == null)
                 throw new ArgumentNullException();
 
             string pkgId = Interop.WidgetService.GetPkgId(Id);
+            string str = Interop.WidgetService.GetIcon(pkgId, lang);
+            Interop.WidgetService.ErrorCode err =
+                    (Interop.WidgetService.ErrorCode)Internals.Errors.ErrorFacts.GetLastResult();
+
+            switch (err)
+            {
+                case Interop.WidgetService.ErrorCode.PermissionDenied:
+                    throw new UnauthorizedAccessException();
 
-            return Interop.WidgetService.GetIcon(pkgId, lang);
+                case Interop.WidgetService.ErrorCode.NotSupported:
+                    throw new NotSupportedException();
+            }
+
+            return str;
+        }
+
+        /// <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>
+        /// <feature>http://tizen.org/feature/shell.appwidget</feature>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the required privileges to access this method.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the required features are not supported.</exception>
         public void Dispose()
         {
             Dispose(true);
@@ -616,8 +888,10 @@ namespace Tizen.Applications
 
             if (s_lifecycleEventRefCnt[Id] == 0)
             {
-                Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, OnLifecycleEvent, IntPtr.Zero);
+                if (_onLifecycleCallback == null)
+                    _onLifecycleCallback = new Interop.WidgetService.LifecycleCallback(OnLifecycleEvent);
 
+                Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, _onLifecycleCallback, IntPtr.Zero);
                 switch (err)
                 {
                     case Interop.WidgetService.ErrorCode.InvalidParameter:
@@ -625,11 +899,15 @@ namespace Tizen.Applications
 
                     case Interop.WidgetService.ErrorCode.PermissionDenied:
                         throw new UnauthorizedAccessException();
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException();
                 }
             }
 
             s_lifecycleEventRefCnt[Id]++;
             s_eventObjects.Add(this);
+            Log.Debug(LogTag, "register lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]");
         }
 
         private void UnregisterLifecycleEvent()
@@ -657,15 +935,21 @@ namespace Tizen.Applications
 
                     case Interop.WidgetService.ErrorCode.NotExist:
                         throw new InvalidOperationException("Event handler is not exist");
+
+                    case Interop.WidgetService.ErrorCode.NotSupported:
+                        throw new NotSupportedException();
                 }
+                _onLifecycleCallback = null;
             }
 
             s_eventObjects.Remove(this);
             s_lifecycleEventRefCnt[Id]--;
+            Log.Debug(LogTag, "unregister lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]");
         }
 
-        private static void OnLifecycleEvent(string widgetId, Interop.WidgetService.LifecycleEvent e, string instanceId, IntPtr userData)
+        private static int OnLifecycleEvent(string widgetId, Interop.WidgetService.LifecycleEvent e, string instanceId, IntPtr userData)
         {
+            Log.Debug(LogTag, "Lifecycle event : " + instanceId + " [" + e + "]");
             switch (e)
             {
                 case Interop.WidgetService.LifecycleEvent.Created:
@@ -727,7 +1011,11 @@ namespace Tizen.Applications
                         }
                     }
                     break;
+
+                default:
+                    break;
             }
+            return 0;
 
         }
     }