2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSysPowerManager.cpp
20 * @brief This is the implementation file for PowerManager class.
23 #include <FSysIBatteryEventListener.h>
24 #include <FSysPowerManager.h>
26 #include <FBaseSysLog.h>
27 #include <FBase_NativeError.h>
28 #include <FSys_PowerManagerImpl.h>
29 #include <FSec_AccessController.h>
31 using namespace Tizen::Security;
33 namespace Tizen { namespace System
36 PowerManager::PowerManager(void)
37 :__pPowerManagerImpl(null)
41 PowerManager::~PowerManager(void)
46 PowerManager::KeepScreenOnState(bool keepOn, bool dimming)
49 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
50 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."));
52 return _PowerManagerImpl::KeepScreenOnState(keepOn, dimming);
56 PowerManager::KeepCpuAwake(bool enable)
59 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
60 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."));
62 return _PowerManagerImpl::KeepCpuAwake(enable);
66 PowerManager::SetScreenEventListener(IScreenEventListener& listener)
68 _PowerManagerImpl::SetScreenEventListener(listener);
72 PowerManager::SetChargingEventListener(IChargingEventListener& listener)
74 _PowerManagerImpl::SetChargingEventListener(listener);
78 PowerManager::RestoreScreenBrightness(void)
80 return _PowerManagerImpl::RestoreScreenBrightness();
83 PowerManager::SetScreenBrightness(int brightness)
86 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
87 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."));
89 return _PowerManagerImpl::SetScreenBrightness(brightness);
93 PowerManager::GetScreenBrightness(void)
95 return _PowerManagerImpl::GetScreenBrightness();
99 PowerManager::IsScreenOn(void)
101 result r = E_SUCCESS;
102 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
103 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."));
105 return _PowerManagerImpl::IsScreenOn();
109 PowerManager::TurnScreenOn(void)
111 result r = E_SUCCESS;
112 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
113 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."));
115 return _PowerManagerImpl::TurnScreenOn();
119 PowerManager::TurnScreenOff(void)
121 result r = E_SUCCESS;
122 r = _AccessController::CheckUserPrivilege(_PRV_POWER);
123 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."));
125 return _PowerManagerImpl::TurnScreenOff();
129 PowerManager::GetCurrentBatteryLevelInPercentage(void)
131 return _PowerManagerImpl::GetCurrentBatteryLevelInPercentage();
135 PowerManager::GetCurrentBatteryLevel(void)
137 return _PowerManagerImpl::GetCurrentBatteryLevel();
141 PowerManager::IsCharging(void)
143 return _PowerManagerImpl::IsCharging();
147 PowerManager::SetBatteryEventListener(IBatteryEventListener* pListener)
149 return _PowerManagerImpl::SetBatteryEventListener(pListener);