Add internal APIs for power off and reboot (#2475)
authorLee Chang Joo <changjoo.lee@samsung.com>
Tue, 29 Dec 2020 09:00:50 +0000 (18:00 +0900)
committerGitHub <noreply@github.com>
Tue, 29 Dec 2020 09:00:50 +0000 (18:00 +0900)
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/Tizen.System/Device/Power.cs
src/Tizen.System/Interop/Interop.Device.cs

index 29f4d3e..b398f1a 100644 (file)
@@ -15,6 +15,7 @@
 */
 
 using System;
+using System.ComponentModel;
 
 namespace Tizen.System
 {
@@ -154,5 +155,47 @@ namespace Tizen.System
                 throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
             }
         }
+        /// <summary>
+        /// Power off the device.
+        /// </summary>
+        /// <privilege>http://tizen.org/privilege/reboot</privilege>
+        /// <privlevel>platform</privlevel>
+        /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
+        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
+        /// <example>
+        /// <code>
+        /// Tizen.System.Power.PowerOff();
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void PowerOff()
+        {
+            DeviceError res = (DeviceError)Interop.Device.DevicePowerPowerOff();
+            if (res != DeviceError.None)
+            {
+                throw DeviceExceptionFactory.CreateException(res, "unable to power off the device.");
+            }
+        }
+        /// <summary>
+        /// Reboot the device.
+        /// </summary>
+        /// <privilege>http://tizen.org/privilege/reboot</privilege>
+        /// <privlevel>platform</privlevel>
+        /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
+        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
+        /// <example>
+        /// <code>
+        /// Tizen.System.Power.Reboot(null);
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void Reboot(string reason)
+        {
+            DeviceError res = (DeviceError)Interop.Device.DevicePowerReboot(reason);
+            if (res != DeviceError.None)
+            {
+                throw DeviceExceptionFactory.CreateException(res, "unable to reboot the device.");
+            }
+        }
     }
 }
index 236a547..a8f9850 100644 (file)
@@ -99,6 +99,10 @@ internal static partial class Interop
         internal static extern int DevicePowerRequestLock(PowerLock type, int timeout_ms);
         [DllImport(Libraries.Device, EntryPoint = "device_power_release_lock", CallingConvention = CallingConvention.Cdecl)]
         internal static extern int DevicePowerReleaseLock(PowerLock type);
+        [DllImport(Libraries.Device, EntryPoint = "device_power_poweroff", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern int DevicePowerPowerOff();
+        [DllImport(Libraries.Device, EntryPoint = "device_power_reboot", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern int DevicePowerReboot(string reason);
 
         //IR
         [DllImport(Libraries.Device, EntryPoint = "device_ir_is_available", CallingConvention = CallingConvention.Cdecl)]