2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 * @file FSysPowerManager.cpp
19 * @brief This is the implementation file for PowerManager class.
22 #include <FSysIBatteryEventListener.h>
23 #include <FSysPowerManager.h>
25 #include <FBaseSysLog.h>
26 #include <FBase_NativeError.h>
27 #include <FSys_PowerManagerImpl.h>
28 #include <FSec_AccessController.h>
30 using namespace Tizen::Security;
32 namespace Tizen { namespace System
35 PowerManager::PowerManager(void)
36 :__pPowerManagerImpl(null)
40 PowerManager::~PowerManager(void)
45 PowerManager::KeepScreenOnState(bool keepOn, bool dimming)
48 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
49 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
51 return _PowerManagerImpl::KeepScreenOnState(keepOn, dimming);
55 PowerManager::KeepCpuAwake(bool enable)
58 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
59 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
61 return _PowerManagerImpl::KeepCpuAwake(enable);
65 PowerManager::SetScreenEventListener(IScreenEventListener& listener)
67 _PowerManagerImpl::AddScreenEventListener(listener, true);
71 PowerManager::AddScreenEventListener(IScreenEventListener& listener)
73 return _PowerManagerImpl::AddScreenEventListener(listener);
77 PowerManager::RemoveScreenEventListener(IScreenEventListener& listener)
79 return _PowerManagerImpl::RemoveScreenEventListener(listener);
83 PowerManager::SetChargingEventListener(IChargingEventListener& listener)
85 _PowerManagerImpl::AddChargingEventListener(listener, true);
89 PowerManager::AddChargingEventListener(IChargingEventListener& listener)
91 return _PowerManagerImpl::AddChargingEventListener(listener);
95 PowerManager::RemoveChargingEventListener(IChargingEventListener& listener)
97 return _PowerManagerImpl::RemoveChargingEventListener(listener);
101 PowerManager::RestoreScreenBrightness(void)
103 return _PowerManagerImpl::RestoreScreenBrightness();
106 PowerManager::SetScreenBrightness(int brightness)
108 result r = E_SUCCESS;
109 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
110 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
112 return _PowerManagerImpl::SetScreenBrightness(brightness);
116 PowerManager::GetScreenBrightness(void)
118 return _PowerManagerImpl::GetScreenBrightness();
122 PowerManager::IsScreenOn(void)
124 return _PowerManagerImpl::IsScreenOn();
128 PowerManager::TurnScreenOn(void)
130 result r = E_SUCCESS;
131 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
132 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
134 return _PowerManagerImpl::TurnScreenOn();
138 PowerManager::TurnScreenOff(void)
140 result r = E_SUCCESS;
141 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
142 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
144 return _PowerManagerImpl::TurnScreenOff();
148 PowerManager::GetCurrentBatteryLevelInPercentage(void)
150 return _PowerManagerImpl::GetCurrentBatteryLevelInPercentage();
154 PowerManager::GetCurrentBatteryLevel(void)
156 return _PowerManagerImpl::GetCurrentBatteryLevel();
160 PowerManager::IsCharging(void)
162 return _PowerManagerImpl::IsCharging();
166 PowerManager::SetBatteryEventListener(IBatteryEventListener* pListener)
168 return _PowerManagerImpl::SetBatteryEventListener(pListener);
172 PowerManager::AddBootEventListener(IBootEventListener& listener)
174 return _PowerManagerImpl::AddBootEventListener(listener);
178 PowerManager::RemoveBootEventListener(IBootEventListener& listener)
180 return _PowerManagerImpl::RemoveBootEventListener(listener);