/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.ComponentModel; namespace Tizen.System { /// /// Enumeration for power lock type. /// /// /// DisplayDim may be ignored if the DIM state is disabled on the platform. /// /// 5 public enum PowerLock { /// /// CPU lock. /// /// 5 Cpu = Interop.Device.PowerLock.Cpu, /// /// Display the normal lock. /// /// 5 DisplayNormal = Interop.Device.PowerLock.DisplayNormal, /// /// Display the dim lock. /// /// 5 DisplayDim = Interop.Device.PowerLock.DisplayDim, } /// /// The Power class provides methods to control the power service. /// /// /// The Power API provides the way to control the power service. /// It can be made to hold the specific state to avoid the CPU state internally. /// /// /// http://tizen.org/privilege/display /// /// 3 public static class Power { /// /// [Obsolete("Please do not use! this will be deprecated")] /// /// /// If the process dies, then every lock will be removed. /// /// 3 /// /// The positive number in milliseconds or 0 for the permanent lock. /// So you must release the permanent lock of the power state with ReleaseCpuLock() if timeout_ms is zero. /// /// When an invalid parameter value is set. /// If the privilege is not set. /// In case of any system error. /// Please do not use! This will be deprecated! /// Please use RequestLock instead! [Obsolete("Please do not use! This will be deprecated! Please use RequestLock instead!")] public static void RequestCpuLock(int timeout) { DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock(Interop.Device.PowerLock.Cpu, timeout); if (res != DeviceError.None) { throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock."); } } /// /// [Obsolete("Please do not use! this will be deprecated")] /// /// 3 /// If the privilege is not set. /// In case of any system error. /// Please do not use! This will be deprecated! /// Please use ReleaseLock instead! [Obsolete("Please do not use! This will be deprecated! Please use ReleaseLock instead!")] public static void ReleaseCpuLock() { DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock(Interop.Device.PowerLock.Cpu); if (res != DeviceError.None) { throw DeviceExceptionFactory.CreateException(res, "unable to release power lock."); } } /// /// Locks the given lock state for a specified time. /// After the given timeout (in milliseconds), unlock the given lock state automatically. /// /// /// If the process dies, then every lock will be removed. /// /// 5 /// /// The power type to request lock. /// /// /// The positive number in milliseconds or 0 for the permanent lock. /// So you must release the permanent lock of the power state with ReleaseLock() if timeout_ms is zero. /// /// When an invalid parameter value is set. /// If the privilege is not set. /// In case of any system error. /// /// /// Tizen.System.Power.RequestLock(Tizen.System.Power.PowerLock.Cpu, 2000); /// /// public static void RequestLock(PowerLock type, int timeout) { DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock((Interop.Device.PowerLock)type, timeout); if (res != DeviceError.None) { throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock."); } } /// /// Releases the lock state. /// /// 5 /// /// The power type to request lock. /// /// When an invalid parameter value is set. /// If the privilege is not set. /// In case of any system error. /// /// /// Tizen.System.Power.ReleaseLock(Tizen.System.Power.PowerLock.Cpu); /// /// public static void ReleaseLock(PowerLock type) { DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock((Interop.Device.PowerLock)type); if (res != DeviceError.None) { throw DeviceExceptionFactory.CreateException(res, "unable to release power lock."); } } /// /// Power off the device. /// /// http://tizen.org/privilege/reboot /// platform /// If the privilege is not set. /// In case of any system error. /// /// /// Tizen.System.Power.PowerOff(); /// /// [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."); } } /// /// Reboot the device. /// /// http://tizen.org/privilege/reboot /// platform /// If the privilege is not set. /// In case of any system error. /// /// /// Tizen.System.Power.Reboot(null); /// /// [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."); } } } }