#include "common/scope_exit.h"
#include "systeminfo/systeminfo-utils.h"
#include "common/filesystem/filesystem_provider.h"
+#include "common/GDBus/connection.h"
namespace extension {
namespace systeminfo {
//Battery
const double kRemainingBatteryChargeMax = 100.0;
const int kVconfErrorNone = 0;
+const char *kBatteryTarget = "org.tizen.resourced";
+const char *kBatteryObject = "/Org/Tizen/ResourceD/Logging";
+const char *kBatteryInterface = "org.tizen.resourced.logging";
+const char *kBatteryGetBatteryChargingTime = "GetBatteryChargingTime";
+const char *kBatteryGetBatteryRemainingTime = "GetBatteryRemainingTime";
//Display
const double kDisplayBrightnessDivideValue = 100;
//Device Orientation
ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret)),
("vconf_get_int error: %d (%s)", ret, get_error_message(ret)));
}
- out->insert(std::make_pair("isCharging", picojson::value(0 != value)));
+ bool isCharging = (0 != value);
+ out->insert(std::make_pair("isCharging", picojson::value(isCharging)));
+
+ if (nullptr == common::dbus::Connection::getInstance().getDBus()) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "dbus wasn't initialized");
+ }
+
+ GError* error = nullptr;
+ GVariant *variant = nullptr;
+ if (isCharging) {
+ variant = g_dbus_connection_call_sync(common::dbus::Connection::getInstance().getDBus(),
+ kBatteryTarget,
+ kBatteryObject,
+ kBatteryInterface,
+ kBatteryGetBatteryChargingTime,
+ g_variant_new("()"),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ } else {
+ variant = g_dbus_connection_call_sync(common::dbus::Connection::getInstance().getDBus(),
+ kBatteryTarget,
+ kBatteryObject,
+ kBatteryInterface,
+ kBatteryGetBatteryRemainingTime,
+ g_variant_new("(i)", 0), // 0 - POWER_NORMAL_MODE
+ NULL, // 1 - POWER_SAVING_MODE
+ G_DBUS_CALL_FLAGS_NONE, // 2 - ULTRA_SAVING_MODE
+ -1, // for now, only 0 is supported
+ NULL,
+ &error);
+ }
+
+ if (!variant || error) {
+ std::string message = error ? error->message : "";
+ g_error_free(error);
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR,
+ "DBus returned error",
+ ("Failed to call %s method - %s",
+ isCharging ? "GetBatteryChargingTime" : "GetBatteryRemainingTime", message.c_str()));
+ } else {
+ int time = 0;
+ g_variant_get(variant, "(i)", &time);
+ g_variant_unref(variant);
+ if (isCharging) {
+ out->insert(std::make_pair("timeToFullCharge", picojson::value(static_cast<double>(time))));
+ out->insert(std::make_pair("timeToDischarge", picojson::value()));
+ } else {
+ out->insert(std::make_pair("timeToFullCharge", picojson::value()));
+ out->insert(std::make_pair("timeToDischarge", picojson::value(static_cast<double>(time))));
+ }
+ }
+
return PlatformResult(ErrorCode::NO_ERROR);
}