}
};
+ApplicationManager.prototype.getBatteryUsageInfo = function() {
+ var args = AV.validateMethod(arguments, [
+ {
+ name: 'days',
+ type: AV.Types.LONG,
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'limit',
+ type: AV.Types.LONG,
+ optional: true,
+ nullable: true
+ }]);
+
+ var callArgs = {};
+
+ if (!T.isNullOrUndefined(args.days)) {
+ callArgs.days = args.days;
+ }
+
+ if (!T.isNullOrUndefined(args.limit)) {
+ callArgs.limit = args.limit;
+ }
+
+ var result = native.callSync('ApplicationManager_getBatteryUsageInfo', callArgs);
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ } else {
+ var metaData = native.getResultObject(result);
+ var data = [];
+ metaData.forEach(function(i) {
+ data.push(new ApplicationBatteryUsage(i));
+ });
+ return data;
+ }
+};
+
function ListenerManager(native, listenerName) {
this.listeners = {};
this.nextId = 1;
});
}
+//class ApplicationBatteryUsage ////////////////////////////////////////////////////
+function ApplicationBatteryUsage(data) {
+ Object.defineProperties(this, {
+ appId : {
+ value : data.appId,
+ writable : false,
+ enumerable : true
+ },
+ batteryUsage : {
+ value : data.batteryUsage,
+ writable : false,
+ enumerable : true
+ }
+ });
+}
+
// exports ////////////////////////////////////////////////////
exports = new ApplicationManager();
const std::string kPrivilegeAppManagerKill = "http://tizen.org/privilege/appmanager.kill";
const std::string kPrivilegeApplicationInfo = "http://tizen.org/privilege/application.info";
const std::string kPrivilegeApplicationLaunch = "http://tizen.org/privilege/application.launch";
+const std::string kPrivilegeAppHistoryRead = "http://tizen.org/privilege/apphistory.read";
} // namespace
using namespace common;
REGISTER_SYNC("ApplicationManager_getAppCerts", GetAppCerts);
REGISTER_SYNC("ApplicationManager_getAppSharedURI", GetAppSharedURI);
REGISTER_SYNC("ApplicationManager_getAppMetaData", GetAppMetaData);
+ REGISTER_SYNC("ApplicationManager_getBatteryUsageInfo", GetBatteryUsageInfo);
REGISTER_SYNC("ApplicationManager_addAppInfoEventListener", AddAppInfoEventListener);
REGISTER_SYNC("ApplicationManager_removeAppInfoEventListener", RemoveAppInfoEventListener);
manager_.GetAppMetaData(app_id, &out);
}
+void ApplicationInstance::GetBatteryUsageInfo(const picojson::value& args, picojson::object& out) {
+ LoggerD("Entered");
+#ifdef TIZEN_MOBILE
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeAppHistoryRead, &out);
+
+ manager_.GetBatteryUsageInfo(args, &out);
+#else
+ LogAndReportError(PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "This feature is not supported on this profile."), &out,
+ ("NOT_SUPPORTED_ERR: This feature is not supported on this profile"));
+ return;
+#endif
+}
+
void ApplicationInstance::AddAppInfoEventListener(const picojson::value& args, picojson::object& out) {
LoggerD("Entered");
LoggerW("DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. "
#include <bundle_internal.h>
#include <appsvc.h>
#include <app_control_internal.h>
+#include <context-service/context_history.h>
#include "common/current_application.h"
#include "common/logger.h"
ReportSuccess(result, *out);
}
+void ApplicationManager::GetBatteryUsageInfo(const picojson::value& args, picojson::object* out) {
+ LoggerD("Entered");
+
+ context_history_list_h list = nullptr;
+ context_history_h handle = nullptr;
+ context_history_filter_h filter = nullptr;
+
+ SCOPE_EXIT {
+ context_history_list_destroy(list);
+ context_history_destroy(handle);
+ context_history_filter_destroy(filter);
+ };
+
+ int ret = context_history_create(&handle);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to create context handle."), out,
+ ("Failed to create context handle: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ ret = context_history_filter_create(&filter);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to create filter handle."), out,
+ ("Failed to create filter handle: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ if (args.contains("limit")) {
+ const int limit = static_cast<int>(args.get("limit").get<double>());
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, limit);
+
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value."), out,
+ ("limit given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ }
+
+ context_history_data_e date_type = CONTEXT_HISTORY_RECENT_BATTERY_USAGE;
+ if (args.contains("days")) {
+ const int days = static_cast<int>(args.get("days").get<double>());
+ date_type = CONTEXT_HISTORY_BATTERY_USAGE;
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, days);
+
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_VALUES_ERR, "days given with invalid value."), out,
+ ("days given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ }
+
+ ret = context_history_get_list(handle, date_type, filter, &list);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get list."), out,
+ ("Failed to get list: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ int size = 0;
+ ret = context_history_list_get_count(list, &size);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get list size."), out,
+ ("Failed to get list size: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ double amount;
+ char* app_id;
+
+ context_history_record_h record;
+ picojson::value result_array = picojson::value(
+ picojson::array(size, picojson::value(picojson::object())));
+ picojson::array& array_obj = result_array.get<picojson::array>();
+
+ for (int i = 0; i < size; ++i) {
+ SCOPE_EXIT {
+ free(app_id);
+ context_history_record_destroy(record);
+ };
+
+ app_id = nullptr;
+ record = nullptr;
+
+ picojson::object& object = array_obj[i].get<picojson::object>();
+
+ ret = context_history_list_get_current(list, &record);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to current record."), out,
+ ("Failed to get current record: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get string."), out,
+ ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ object.insert(std::make_pair("appId", picojson::value(app_id)));
+
+ ret = context_history_record_get_double(record, CONTEXT_HISTORY_TOTAL_AMOUNT, &amount);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to get amount."), out,
+ ("Failed to get amount: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ object.insert(std::make_pair("batteryUsage", picojson::value(amount)));
+
+ ret = context_history_list_move_next(list);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret && CONTEXT_HISTORY_ERROR_NO_DATA != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed to move iterator."), out,
+ ("Failed to move iterator: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ }
+ ReportSuccess(result_array, *out);
+}
+
void ApplicationManager::GetAppMetaData(const std::string& app_id, picojson::object* out) {
LoggerD("Entered");