Add AppControl.SetAutoRestart method (#4280)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Tue, 24 May 2022 04:20:23 +0000 (13:20 +0900)
committerGitHub <noreply@github.com>
Tue, 24 May 2022 04:20:23 +0000 (13:20 +0900)
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.AppControl.cs
src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs

index 6360dd9..ee60e6e 100755 (executable)
@@ -151,5 +151,8 @@ internal static partial class Interop
 
         [DllImport(Libraries.AppControl, EntryPoint = "app_control_get_component_id")]
         internal static extern ErrorCode GetComponentId(SafeAppControlHandle handle, out string componentId);
+
+        [DllImport(Libraries.AppControl, EntryPoint = "app_control_set_auto_restart")]
+        internal static extern ErrorCode SetAutoRestart(SafeAppControlHandle handle);
     }
 }
index 6c951fa..20ead07 100755 (executable)
@@ -16,6 +16,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Runtime.InteropServices;
 using System.Threading.Tasks;
@@ -769,6 +770,45 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Sets the auto restart.
+        /// </summary>
+        /// <remarks>
+        /// The functionality of this method only applies to the caller application.
+        /// The auto restart cannot be applied to other applications. The application ID set in the AppControl is ignored.
+        /// This method is only available for platform level signed applications.
+        /// </remarks>
+        /// <param name="appControl">The AppControl.</param>
+        /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
+        /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception>
+        /// <exception cref="Exceptions.PermissionDeniedException">Thrown when the permission is denied.</exception>
+        /// <exception cref="Exceptions.OutOfMemoryException">Thrown when the memory is insufficient.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the memory is insufficient.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetAutoRestart(AppControl appControl)
+        {
+            if (appControl == null)
+            {
+                throw new ArgumentNullException(nameof(appControl));
+            }
+
+            Interop.AppControl.ErrorCode err = Interop.AppControl.SetAutoRestart(appControl.SafeAppControlHandle);
+            if (err != Interop.AppControl.ErrorCode.None)
+            {
+                switch (err)
+                {
+                    case Interop.AppControl.ErrorCode.InvalidParameter:
+                        throw new ArgumentException("Invalid arguments");
+                    case Interop.AppControl.ErrorCode.PermissionDenied:
+                        throw new Exceptions.PermissionDeniedException("Permission denied");
+                    case Interop.AppControl.ErrorCode.OutOfMemory:
+                        throw new Exceptions.OutOfMemoryException("Out of memory");
+                    default:
+                        throw new InvalidOperationException("err = " + err);
+                }
+            }
+        }
+
+        /// <summary>
         /// Class for extra data.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>