2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
20 namespace Tizen.System
23 /// Enumeration for power lock type.
26 /// DisplayDim may be ignored if the DIM state is disabled on the platform.
28 /// <since_tizen> 5 </since_tizen>
34 /// <since_tizen> 5 </since_tizen>
35 Cpu = Interop.Device.PowerLock.Cpu,
37 /// Display the normal lock.
39 /// <since_tizen> 5 </since_tizen>
40 DisplayNormal = Interop.Device.PowerLock.DisplayNormal,
42 /// Display the dim lock.
44 /// <since_tizen> 5 </since_tizen>
45 DisplayDim = Interop.Device.PowerLock.DisplayDim,
49 /// The Power class provides methods to control the power service.
52 /// The Power API provides the way to control the power service.
53 /// It can be made to hold the specific state to avoid the CPU state internally.
56 /// http://tizen.org/privilege/display
58 /// <since_tizen> 3 </since_tizen>
59 public static class Power
62 /// [Obsolete("Please do not use! this will be deprecated")]
65 /// If the process dies, then every lock will be removed.
67 /// <since_tizen> 3 </since_tizen>
68 /// <param name="timeout">
69 /// The positive number in milliseconds or 0 for the permanent lock.
70 /// So you must release the permanent lock of the power state with ReleaseCpuLock() if timeout_ms is zero.
72 /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
73 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
74 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
75 /// Please do not use! This will be deprecated!
76 /// Please use RequestLock instead!
77 [Obsolete("Please do not use! This will be deprecated! Please use RequestLock instead!")]
78 public static void RequestCpuLock(int timeout)
80 DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock(Interop.Device.PowerLock.Cpu, timeout);
81 if (res != DeviceError.None)
83 throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock.");
87 /// [Obsolete("Please do not use! this will be deprecated")]
89 /// <since_tizen> 3 </since_tizen>
90 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
91 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
92 /// Please do not use! This will be deprecated!
93 /// Please use ReleaseLock instead!
94 [Obsolete("Please do not use! This will be deprecated! Please use ReleaseLock instead!")]
95 public static void ReleaseCpuLock()
97 DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock(Interop.Device.PowerLock.Cpu);
98 if (res != DeviceError.None)
100 throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
105 /// Locks the given lock state for a specified time.
106 /// After the given timeout (in milliseconds), unlock the given lock state automatically.
109 /// If the process dies, then every lock will be removed.
111 /// <since_tizen> 5 </since_tizen>
112 /// <param name="type">
113 /// The power type to request lock.
115 /// <param name="timeout">
116 /// The positive number in milliseconds or 0 for the permanent lock.
117 /// So you must release the permanent lock of the power state with ReleaseLock() if timeout_ms is zero.
119 /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
120 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
121 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
124 /// Tizen.System.Power.RequestLock(Tizen.System.Power.PowerLock.Cpu, 2000);
127 public static void RequestLock(PowerLock type, int timeout)
129 DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock((Interop.Device.PowerLock)type, timeout);
130 if (res != DeviceError.None)
132 throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock.");
136 /// Releases the lock state.
138 /// <since_tizen> 5 </since_tizen>
139 /// <param name="type">
140 /// The power type to request lock.
142 /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
143 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
144 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
147 /// Tizen.System.Power.ReleaseLock(Tizen.System.Power.PowerLock.Cpu);
150 public static void ReleaseLock(PowerLock type)
152 DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock((Interop.Device.PowerLock)type);
153 if (res != DeviceError.None)
155 throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
159 /// Power off the device.
161 /// <privilege>http://tizen.org/privilege/reboot</privilege>
162 /// <privlevel>platform</privlevel>
163 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
164 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
167 /// Tizen.System.Power.PowerOff();
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public static void PowerOff()
173 DeviceError res = (DeviceError)Interop.Device.DevicePowerPowerOff();
174 if (res != DeviceError.None)
176 throw DeviceExceptionFactory.CreateException(res, "unable to power off the device.");
180 /// Reboot the device.
182 /// <privilege>http://tizen.org/privilege/reboot</privilege>
183 /// <privlevel>platform</privlevel>
184 /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
185 /// <exception cref="InvalidOperationException">In case of any system error.</exception>
188 /// Tizen.System.Power.Reboot(null);
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 public static void Reboot(string reason)
194 DeviceError res = (DeviceError)Interop.Device.DevicePowerReboot(reason);
195 if (res != DeviceError.None)
197 throw DeviceExceptionFactory.CreateException(res, "unable to reboot the device.");