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 FSys_PowerManagerImpl.cpp
20 * @brief This is the implementation file for _PowerManagerImpl class.
23 #include <unique_ptr.h>
28 #include <runtime_info.h>
31 #include <FAppIActiveAppEventListener.h>
32 #include <FBaseSysLog.h>
33 #include <FBaseColArrayListT.h>
34 #include <FBaseColIMapEnumerator.h>
35 #include <FSysIBatteryEventListener.h>
36 #include <FSysIChargingEventListener.h>
37 #include <FSysIScreenEventListener.h>
38 #include <FSysIBootEventListener.h>
39 #include <FSys_IPowerManagerEventListener.h>
41 #include <FApp_AppImpl.h>
42 #include <FApp_AppInfo.h>
43 #include <FApp_AppManagerImpl.h>
44 #include <FBase_NativeError.h>
45 #include <FIo_AppServiceIpcMessages.h>
46 #include <FIo_IpcClient.h>
47 #include <FSys_Types.h>
48 #include <FSys_BatteryImpl.h>
49 #include <FSys_DeviceManagerImpl.h>
50 #include <FSys_PowerManagerImpl.h>
54 using namespace Tizen::App;
55 using namespace Tizen::Base;
56 using namespace Tizen::Base::Collection;
57 using namespace Tizen::Io;
59 namespace Tizen { namespace System
62 static const int _DEVICE_CPU = 1;
63 static const int _DEVICE_POWER_LEVEL_ON = 1;
64 static const int _DEVICE_POWER_LEVEL_OFF = 0;
65 static const int _APPID_LENGTH = 10;
66 static const int _DEACTIVATED_BRIGHTNESS_CONTROL = -1;
67 static const float _BRIGHTNESS_RESOLUTION = 10.0;
69 #ifndef VCONFKEY_SERVICE_READY
70 #define VCONFKEY_SERVICE_READY "memory/appservice/serviceready"
73 bool _activeApp = false;
74 bool _deviceCpuPowerOn = false;
75 bool _keepCpuAwake = false;
76 bool _keepScreenOnState = false;
78 IBatteryEventListener* pIBatteryEventListener = null;
80 ArrayListT<IScreenEventListener*>* __pSceenEventList = null;
81 ArrayListT<IChargingEventListener*>* __pChargingEventList = null;
82 ArrayListT<_IPowerManagerEventListener*> __powerEventList;
83 ArrayListT<IBootEventListener*>* __pBootEventList = null;
85 bool _PowerManagerImpl::_InitPowerManager = false;
88 class _ActiveEventListener
89 : public IActiveAppEventListener
92 virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
96 _ActiveEventListener::OnActiveAppChanged(const Tizen::App::AppId& appId)
99 SysLog(NID_SYS, "Active App is %ls.", appId.GetPointer());
101 if(appId == _AppInfo::GetApplicationId())
109 if (_keepScreenOnState == true) //In case of Screen power control, it has to be released automatically, when application goes deactive state.
111 ret = pm_unlock_state(LCD_NORMAL, GOTO_STATE_NOW);
112 SysTryReturnVoidResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to unlock the power state");
113 _keepScreenOnState = false;
116 if (_keepCpuAwake == true || _deviceCpuPowerOn == true) //In case of CPU power control, it has to be keep despite of deactive state.
118 ret = power_lock_state(POWER_STATE_SCREEN_OFF, 0);
119 SysTryReturnVoidResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to lock the power state");
124 _ActiveEventListener* pActiveEventListener = null;
127 BatteryLevelVConfCallback(keynode_t* node, void* userData)
129 SysLog(NID_SYS, "Battery Warn Level is changed");
130 BatteryLevel batteryLevel;
132 if (strcmp(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, vconf_keynode_get_name(node)) == 0)
135 if(vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &level) >= 0)
139 case VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY:
140 batteryLevel = BATTERY_EMPTY;
142 case VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL:
143 batteryLevel = BATTERY_CRITICAL;
145 case VCONFKEY_SYSMAN_BAT_LEVEL_LOW:
146 batteryLevel = BATTERY_EMPTY;
148 case VCONFKEY_SYSMAN_BAT_LEVEL_HIGH:
149 batteryLevel = BATTERY_EMPTY;
151 case VCONFKEY_SYSMAN_BAT_LEVEL_FULL:
152 batteryLevel = BATTERY_EMPTY;
155 SysLogException(NID_SYS, E_SYSTEM, "Unavailable battery level is required.");
158 _AppImpl* pAppImpl = _AppImpl::GetInstance();
161 SysLog(NID_SYS, "Battery Level event is forwarded");
162 pAppImpl->OnBatteryLevelChanged(batteryLevel);
169 DeviceBatteryCallback(int percent, void* userData)
171 SysLog(NID_SYS, "Battery Level is called %d", percent);
173 if (pIBatteryEventListener != null)
175 pIBatteryEventListener->OnBatteryLevelChangedInPercentage(percent);
180 RuntimeInfoChangedCallback(runtime_info_key_e key, void* userData)
184 if(_AppInfo::GetAppState() == RUNNING)
186 if (__pChargingEventList != null)
188 bool charging = false;
189 ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, &charging);
192 for(int i = 0; i < __pChargingEventList->GetCount(); i++)
194 result r = E_SUCCESS;
195 IChargingEventListener* pIChargingEventListener = null;
197 r = __pChargingEventList->GetAt(i, pIChargingEventListener);
199 if (IsFailed(r) == false)
201 pIChargingEventListener->OnChargingStateChanged(charging);
211 PowerChangedCallback(power_state_e state, void* userData)
213 std::unique_ptr< IEnumeratorT<_IPowerManagerEventListener*> > pEnumerator(__powerEventList.GetEnumeratorN());
214 _IPowerManagerEventListener* pIPowerManagerEventListener = null;
216 if (__pSceenEventList != null)
218 if (state == POWER_STATE_SCREEN_OFF)
220 for (int i = 0; i < __pSceenEventList->GetCount(); i++)
222 IScreenEventListener* pIScreenEventListener = null;
223 result r = E_SUCCESS;
224 r = __pSceenEventList->GetAt(i, pIScreenEventListener);
225 if (IsFailed(r) == false)
227 pIScreenEventListener->OnScreenOff();
231 if(pEnumerator != null)
233 while(pEnumerator->MoveNext() == E_SUCCESS)
235 pEnumerator->GetCurrent(pIPowerManagerEventListener);
236 if(pIPowerManagerEventListener != null)
238 pIPowerManagerEventListener->OnScreenStateChanged(false);
245 for (int i = 0; i < __pSceenEventList->GetCount(); i++)
247 IScreenEventListener* pIScreenEventListener = null;
248 result r = E_SUCCESS;
249 r = __pSceenEventList->GetAt(i, pIScreenEventListener);
250 if (IsFailed(r) == false)
252 pIScreenEventListener->OnScreenOn();
256 if(pEnumerator != null)
258 while(pEnumerator->MoveNext() == E_SUCCESS)
260 pEnumerator->GetCurrent(pIPowerManagerEventListener);
261 if(pIPowerManagerEventListener != null)
263 pIPowerManagerEventListener->OnScreenStateChanged(true);
272 ScreenEventVConfCallback(keynode_t* node, void* userData)
275 int sysBrightness = 0;
277 if (__pSceenEventList == null)
279 SysLogException(NID_SYS, E_SYSTEM, "SceenEventList is not initialized.");
282 errorCode = vconf_get_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, &sysBrightness);
286 SysLogException(NID_SYS, E_SYSTEM, "It failed to get Screen brightness");
290 for (int i = 0; i < __pSceenEventList->GetCount(); i++)
292 IScreenEventListener* pIScreenEventListener = null;
293 __pSceenEventList->GetAt(i, pIScreenEventListener);
294 if (pIScreenEventListener != null)
297 int maxBrightness = -1;
298 int ret = device_get_max_brightness(0, &maxBrightness);
301 SysLogException(NID_SYS, E_SYSTEM, "It failed to get the device max brightness");
304 brightness = (int)ceil(((_BRIGHTNESS_RESOLUTION / (float) maxBrightness)) * sysBrightness);
305 pIScreenEventListener->OnScreenBrightnessChanged(brightness);
310 _PowerManagerImpl::_PowerManagerImpl(void)
314 _PowerManagerImpl::~_PowerManagerImpl(void)
319 _PowerManagerImpl::Init()
321 if(_InitPowerManager == false)
323 __powerEventList.Construct();
324 pActiveEventListener = new (std::nothrow) _ActiveEventListener();
325 _AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance();
326 pAppManager->AddActiveAppEventListener(*pActiveEventListener);
327 _InitPowerManager = true;
332 _PowerManagerImpl::Term()
334 if(_InitPowerManager == true)
336 _AppManagerImpl* pAppManager = _AppManagerImpl::GetInstance();
337 pAppManager->RemoveActiveAppEventListener(*pActiveEventListener);
338 delete(pActiveEventListener);
339 pActiveEventListener = null;
341 _InitPowerManager = false;
346 _PowerManagerImpl::IsActive(void)
349 result r = E_SUCCESS;
350 _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
352 if(pAppManagerImpl == null)
358 r = pAppManagerImpl->GetActiveApp(appId);
362 SysLog(NID_SYS, "current active is:%ls, required:%ls", appId.GetPointer(), _AppInfo::GetApplicationId().GetPointer());
363 if(appId == _AppInfo::GetApplicationId())
381 _PowerManagerImpl::KeepScreenOnState(bool keepOn, bool dimming)
384 unsigned int state = LCD_DIM;
385 _PowerManagerImpl::Init();
387 if (keepOn == true && IsActive() == true)
397 ret = pm_lock_state(state, GOTO_STATE_NOW, 0);
398 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to lock the screen state");
399 _keepScreenOnState = true;
403 ret = pm_unlock_state(LCD_NORMAL, GOTO_STATE_NOW);
404 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to unlock the screen state");
405 _keepScreenOnState = false;
408 SysLog(NID_SYS, "change screen power policy: keepOn(%d) and dimming(%d)", keepOn, dimming);
414 _PowerManagerImpl::KeepCpuAwake(bool enable)
417 _PowerManagerImpl::Init();
421 ret = power_lock_state(POWER_STATE_SCREEN_OFF, 0);
422 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to lock the power state");
423 _keepCpuAwake = true;
427 if(_deviceCpuPowerOn == false)
429 ret = power_unlock_state(POWER_STATE_SCREEN_OFF);
430 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to unlock the power state");
432 _keepCpuAwake = false;
435 SysLog(NID_SYS, "change cpu power policy: keepAwake(%s)", enable ? "true" : "false");
440 _PowerManagerImpl::InitBatteryEvent(void)
442 int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, BatteryLevelVConfCallback, null);
443 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to set the battery event");
449 _PowerManagerImpl::OnForeground(void)
455 _PowerManagerImpl::OnBackground(void)
461 _PowerManagerImpl::RestoreScreenBrightness(void)
463 result r = E_SUCCESS;
465 ArrayList requestMessage;
466 ArrayList responseMessage;
468 SysTryReturn(NID_SYS, IsActive() == true, E_SUCCESS, r, "It is not active app.");
470 unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient());
471 SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
473 r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID);
474 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r));
476 requestMessage.Construct();
477 responseMessage.Construct();
479 String serviceId = _SYSTEM_SERVICE_ID;
480 String commandId = _SYSTEM_COMMAND_RESTORE_BRIGHTNESS;
482 requestMessage.Add(serviceId);
483 requestMessage.Add(commandId);
485 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
486 SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
488 r = pIpcClient->SendRequest(pMsg.get());
489 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to ipc message", GetErrorMessage(r));
491 unique_ptr<String> pResult((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA));
493 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "It is failed to receive Ipc response.");
494 SysTryReturnResult(NID_SYS, *pResult == _SYSTEM_RESULT_OK, E_SYSTEM, "It is failed to set brightness.");
500 _PowerManagerImpl::SetScreenBrightness(int brightness)
503 int maxBrightness = 0;
504 int actualBrightness = 0;
505 result r = E_SUCCESS;
507 SysTryReturn(NID_SYS, IsActive() == true, E_SUCCESS, r, "It is not active app.");
508 SysTryReturnResult(NID_SYS, (brightness > 0 && brightness < 11), E_OUT_OF_RANGE,
509 "[E_OUT_OF_RANGE] The specified brightness is out of range.");
511 SysLog(NID_SYS, "Set brightness (%d)", brightness);
513 ret = device_get_max_brightness(0, &maxBrightness);
514 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to get the device max brightness");
516 actualBrightness = maxBrightness * brightness / _BRIGHTNESS_RESOLUTION;
518 ArrayList requestMessage;
519 ArrayList responseMessage;
521 unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient());
522 SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
524 r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID);
525 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r));
527 requestMessage.Construct();
528 responseMessage.Construct();
530 String serviceId = _SYSTEM_SERVICE_ID;
531 String commandId = _SYSTEM_COMMAND_CHANGE_BRIGHTNESS;
532 String brightnessValue;
533 brightnessValue.Append(actualBrightness);
535 requestMessage.Add(serviceId);
536 requestMessage.Add(commandId);
537 requestMessage.Add(brightnessValue);
539 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
540 SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
542 r = pIpcClient->SendRequest(pMsg.get());
543 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to ipc message", GetErrorMessage(r));
545 unique_ptr<String> pResult((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA));
547 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "It is failed to receive Ipc response.");
548 SysTryReturnResult(NID_SYS, *pResult == _SYSTEM_RESULT_OK, E_SYSTEM, "It is failed to set brightness.");
554 _PowerManagerImpl::GetScreenBrightness(void)
558 int maxBrightness = -1;
562 ret = device_get_brightness(0, &brightness);
565 SysLogException(NID_SYS, E_SYSTEM, "It failed to get the device brightness");
566 SetLastResult(E_SYSTEM);
567 return _DEACTIVATED_BRIGHTNESS_CONTROL;
575 SysLog(NID_SYS, "System Brightness is %d", brightness);
576 ret = device_get_max_brightness(0, &maxBrightness);
579 SysLogException(NID_SYS, E_SYSTEM, "It failed to get the device max brightness");
580 SetLastResult(E_SYSTEM);
581 return _DEACTIVATED_BRIGHTNESS_CONTROL;
583 return ceil(((_BRIGHTNESS_RESOLUTION / (float) maxBrightness)) * brightness);
587 _PowerManagerImpl::IsScreenOn(void)
589 power_state_e powerState = power_get_state();
591 if (powerState == POWER_STATE_SCREEN_OFF)
602 _PowerManagerImpl::TurnScreenOn(void)
604 result r = E_SUCCESS;
605 int ret = power_wakeup(true);
607 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to unlock the normal screen state");
613 _PowerManagerImpl::TurnScreenOff(void)
615 result r = E_SUCCESS;
616 int ret = pm_change_state(LCD_OFF);
618 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to unlock the screen off screen state");
624 _PowerManagerImpl::SetScreenEventListener(IScreenEventListener& listener)
626 result r = E_SUCCESS;
628 r = AddScreenEventListener(listener, true);
632 SysLog(NID_SYS, "It failed to register ScreenEventListener");
635 SysLog(NID_SYS,"It successed to register ScreenEventListener");
640 _PowerManagerImpl::AddScreenEventListener(IScreenEventListener& listener, bool isSet)
642 result r = E_SUCCESS;
644 if (__pSceenEventList == null)
646 std::unique_ptr< ArrayListT<IScreenEventListener*> > pSceenEventList(new ArrayListT<IScreenEventListener*>);
647 SysTryReturnResult(NID_SYS, pSceenEventList, E_SYSTEM, "Memory allocation failed");
648 pSceenEventList->Construct();
650 errorCode = vconf_notify_key_changed(VCONFKEY_PM_CURRENT_BRIGHTNESS, ScreenEventVConfCallback, null);
651 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It failed to add ScreenEvent listener.");
653 errorCode = power_set_changed_cb(PowerChangedCallback, null);
654 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It failed to add ScreenEvent listener.");
655 __pSceenEventList = pSceenEventList.release();
656 SysLog(NID_SYS,"It successed to register power_set_changed_cb");
659 if (isSet == true && __pSceenEventList->GetCount() != 0)
661 r = __pSceenEventList->SetAt(&listener, 0);
665 r = __pSceenEventList->Add(&listener);
672 _PowerManagerImpl::RemoveScreenEventListener(IScreenEventListener& listener)
674 result r = E_SUCCESS;
676 SysTryReturnResult(NID_SYS,__pSceenEventList != null, E_OBJ_NOT_FOUND, "IScreenEventListener list is empty");
678 r = __pSceenEventList->Remove(&listener);
680 if (__pSceenEventList->GetCount() == 0)
682 delete __pSceenEventList;
683 __pSceenEventList = null;
690 _PowerManagerImpl::SetChargingEventListener(IChargingEventListener& listener)
692 result r = E_SUCCESS;
694 r = AddChargingEventListener(listener, true);
698 SysLog(NID_SYS, "It failed to register battery charging event");
705 _PowerManagerImpl::AddChargingEventListener(IChargingEventListener& listener, bool isSet)
707 result r = E_SUCCESS;
709 if (__pChargingEventList == null)
711 __pChargingEventList = new ArrayListT<IChargingEventListener*>;
712 SysTryReturnResult(NID_SYS, __pChargingEventList, E_SYSTEM, "Memory allocation failed");
713 __pChargingEventList->Construct();
715 errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, RuntimeInfoChangedCallback, null);
718 SysLog(NID_SYS, "It failed to register battery charging event");
719 delete __pChargingEventList;
720 __pChargingEventList = null;
725 if (isSet == false || __pChargingEventList->GetCount() == 0)
727 r = __pChargingEventList->Add(&listener);
731 r = __pChargingEventList->SetAt(&listener, 0);
738 _PowerManagerImpl::RemoveChargingEventListener(IChargingEventListener& listener)
740 result r = E_SUCCESS;
742 SysTryReturnResult(NID_SYS,__pChargingEventList != null, E_OBJ_NOT_FOUND, "__pChargingEventList list is empty");
744 r = __pChargingEventList->Remove(&listener);
746 if (__pChargingEventList->GetCount() == 0)
748 delete __pChargingEventList;
749 __pChargingEventList = null;
755 _PowerManagerImpl::SetBatteryEventListener(IBatteryEventListener* pListener)
759 if (pListener != null)
762 if(pIBatteryEventListener == null)
764 ret = device_battery_set_cb(DeviceBatteryCallback, null);
767 SysLog(NID_SYS, "It failed to register battery event");
770 pIBatteryEventListener = pListener;
774 pIBatteryEventListener = null;
775 ret = device_battery_unset_cb();
778 SysLog(NID_SYS, "It failed to unregister battery event");
786 _PowerManagerImpl::PowerControl(int deviceId, int level)
789 if(deviceId == _DEVICE_CPU)
791 if(level == _DEVICE_POWER_LEVEL_ON)
793 ret = power_lock_state(POWER_STATE_SCREEN_OFF, 0);
794 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to lock the power state");
795 _deviceCpuPowerOn = true;
799 else if(level == _DEVICE_POWER_LEVEL_OFF)
801 if(_keepScreenOnState == false)
803 ret = power_unlock_state(POWER_STATE_SCREEN_OFF);
804 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] It failed to unlock the power state");
806 _deviceCpuPowerOn = false;
814 _PowerManagerImpl::GetCurrentBatteryLevelInPercentage(void)
817 int batteryLevel = 0;
819 ret = device_battery_get_percent(&batteryLevel);
822 SetLastResult(E_SYSTEM);
829 _PowerManagerImpl::GetCurrentBatteryLevel(void)
831 int batteryLevel = 0;
832 BatteryLevel level = BATTERY_EMPTY;
833 int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &batteryLevel);
836 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get battery level.");
842 case VCONFKEY_SYSMAN_BAT_LEVEL_FULL:
843 level = BATTERY_LEVEL_FULL;
845 case VCONFKEY_SYSMAN_BAT_LEVEL_HIGH:
846 level = BATTERY_LEVEL_HIGH;
848 case VCONFKEY_SYSMAN_BAT_LEVEL_LOW:
849 level = BATTERY_LEVEL_LOW;
851 case VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL:
852 level = BATTERY_LEVEL_CRITICAL;
855 level = BATTERY_LEVEL_EMPTY;
863 _PowerManagerImpl::IsCharging(void)
865 bool chargeState = false;
867 ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, &chargeState);
870 SetLastResult(E_SYSTEM);
878 _PowerManagerImpl::Add_IPowerManagerEventListener(_IPowerManagerEventListener* listener)
880 _PowerManagerImpl::Init();
881 __powerEventList.Add(listener);
886 _PowerManagerImpl::Remove_IPowerManagerEventListener(_IPowerManagerEventListener* listener)
888 _PowerManagerImpl::Init();
889 __powerEventList.Remove(listener);
894 BootEventVconfCallback(keynode_t* node, void* userData)
896 if (__pBootEventList == null)
898 SysLogException(NID_SYS, E_SYSTEM, "BootEventList is not initialized.");
903 const int errorCode = vconf_get_int(VCONFKEY_SERVICE_READY, &bootReady);
907 SysLogException(NID_SYS, E_SYSTEM, "It failed to get Boot event status");
911 std::unique_ptr< IEnumeratorT<IBootEventListener*> > pEnum(__pBootEventList->GetEnumeratorN());
915 while (pEnum->MoveNext() == E_SUCCESS)
917 IBootEventListener* pListener = null;
918 pEnum->GetCurrent(pListener);
920 pListener->OnBootCompleted();
924 SysLog(NID_SYS, "Finished invoking boot complete event listener.");
928 _PowerManagerImpl::AddBootEventListener(IBootEventListener& listener)
930 if (__pBootEventList == null)
932 std::unique_ptr< ArrayListT<IBootEventListener*> > pBootEventList(new ArrayListT<IBootEventListener*>);
933 SysTryReturnResult(NID_SYS, pBootEventList, E_SYSTEM, "Memory allocation failed");
934 pBootEventList->Construct();
937 errorCode = vconf_notify_key_changed(VCONFKEY_SERVICE_READY, BootEventVconfCallback, null);
938 SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It failed to add BootEvent listener.");
940 __pBootEventList = pBootEventList.release();
941 SysLog(NID_SYS, "It successed to register boot event listener.");
944 return __pBootEventList->Add(&listener);
948 _PowerManagerImpl::RemoveBootEventListener(IBootEventListener& listener)
950 result r = E_SUCCESS;
952 SysTryReturnResult(NID_SYS,__pBootEventList != null, E_OBJ_NOT_FOUND, "IBootEventListener list is empty");
954 r = __pBootEventList->Remove(&listener);
956 if (__pBootEventList->GetCount() == 0)
958 delete __pBootEventList;
959 __pBootEventList = null;
966 _PowerManagerImpl::GetInstance(PowerManager& powerManager)
968 return powerManager.__pPowerManagerImpl;
971 const _PowerManagerImpl*
972 _PowerManagerImpl::GetInstance(const PowerManager& powerManager)
974 return powerManager.__pPowerManagerImpl;