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 FSys_BatteryImpl.cpp
19 * @brief This is the implementation file for _BatteryImpl class.
23 #include <runtime_info.h>
25 #include <FSysDeviceManager.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_NativeError.h>
29 #include <FSys_BatteryImpl.h>
30 #include <FSys_Types.h>
32 #include "FSys_SystemInfoImpl.h"
34 using namespace Tizen::Base;
36 namespace Tizen { namespace System
39 _BatteryImpl::_BatteryImpl(void)
43 _BatteryImpl::~_BatteryImpl(void)
48 _BatteryImpl::IsCharging(bool& charging)
50 bool chargeState = false;
52 ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, &chargeState);
53 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] runtime_info_get_value_bool returns %d.", ret);
54 charging = chargeState;
59 _BatteryImpl::GetCurrentLevelInPercentage(int& level)
64 ret = device_battery_get_percent(&batteryLevel);
65 SysTryReturnResult(NID_SYS, ret == DEVICE_ERROR_NONE, E_SYSTEM, "Failed to get the device battery percentage");
73 _BatteryImpl::GetCurrentLevel(BatteryLevel& level)
77 device_battery_warn_e batteryStatus;
79 result r = device_battery_get_percent(&batteryLevel);
80 SysTryReturnResult(NID_SYS, !IsFailed(r), r, "Failed to get the device battery percentage");
82 if (batteryLevel == _BATTERY_LEVEL_FULL)
88 ret = device_battery_get_warning_status(&batteryStatus);
90 switch (batteryStatus)
92 case DEVICE_BATTERY_WARN_NORMAL:
95 case DEVICE_BATTERY_WARN_LOW:
98 case DEVICE_BATTERY_WARN_CRITICAL:
99 level = BATTERY_CRITICAL;
101 case DEVICE_BATTERY_WARN_EMPTY:
102 level = BATTERY_EMPTY;
105 SysLogException(NID_SYS, E_SYSTEM, "There is a system error occured.");