2 // Tizen Web Device API
3 // Copyright (c) 2013 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.
20 #include <PlatformException.h>
23 #include "SystemInfoBattery.h"
24 #include "SystemInfoUtil.h"
27 namespace SystemInfo {
30 const double REMANING_BATTERY_CHARGE_MAX = 100.0;
33 SystemInfoBattery::SystemInfoBattery()
37 m_level = fetchLevel();
38 m_is_charging = fetchIsCharging();
41 SystemInfoBattery::~SystemInfoBattery()
46 double SystemInfoBattery::getLevel() const
51 bool SystemInfoBattery::isCharging() const
56 double SystemInfoBattery::fetchLevel()
61 int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value);
62 if (ret != VCONF_OK) {
63 std::string log_msg = "Failed to get battery capacity";
64 LOGE("%s", log_msg.c_str());
65 SystemInfoUtil::throwSystemInfoException(0, log_msg);
68 return static_cast<double>(value) / REMANING_BATTERY_CHARGE_MAX;
71 bool SystemInfoBattery::fetchIsCharging()
76 int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value);
77 if (ret != VCONF_OK) {
78 std::string log_msg = "Failed to get battery change";
79 LOGE("%s", log_msg.c_str());
80 SystemInfoUtil::throwSystemInfoException(0, log_msg);