From: Sunggyu Choi Date: Wed, 14 Jan 2015 01:26:48 +0000 (+0900) Subject: Added initial version of tizen.application X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~642^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=075f34fb8a7735a5cbcbde17ad015e60b0a48f1d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git Added initial version of tizen.application Change-Id: Ie8dec7d6f35e1056b27576bd5bdec2cd337942e9 Signed-off-by: Sunggyu Choi --- diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 99210722..9ce6b250 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -178,6 +178,7 @@ BuildRequires: pkgconfig(libpcrecpp) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-appfw-package-manager) +BuildRequires: pkgconfig(wrt-plugins-ipc-message) %if 0%{?tizen_feature_power_support} BuildRequires: pkgconfig(capi-system-power) diff --git a/src/application/application.cc b/src/application/application.cc new file mode 100644 index 00000000..f3859f3b --- /dev/null +++ b/src/application/application.cc @@ -0,0 +1,69 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "application/application.h" + +#include + +#include "common/extension.h" +#include "common/logger.h" +#include "common/picojson.h" +#include "tizen/tizen.h" + +namespace extension { +namespace application { + +Application::Application() { +} + +Application::Application(const ApplicationPtr app) { + context_id_ = app->get_context_id(); +} + +Application::~Application() { +} + +void Application::Hide() { + +} + +void Application::Exit() { + +} + +std::string Application::get_context_id() { + return context_id_; +} + +void Application::set_context_id(const std::string& context_id) { + context_id_ = context_id; +} + +ApplicationInformationPtr Application::get_app_info() const { + return app_info_; +} + +void Application::set_app_info(ApplicationInformationPtr& app_info) { + app_info_ = app_info; +} + +const picojson::value& Application::Value() { + + if (!app_info_->IsValid()) { + LoggerD("WebApiAPIErrors::UNKNOWN_ERR"); + picojson::object obj; + obj["error"] = picojson::value(static_cast(WebApiAPIErrors::UNKNOWN_ERR)); + value_ = picojson::value(obj); + } else { + picojson::object obj; + LoggerD("Value returns appInfo, contextId"); + obj["appInfo"] = app_info_->Value(); + obj["contextId"] = picojson::value(context_id_); + value_ = picojson::value(obj); + } + return value_; +} + +} // namespace application +} // namespace extension diff --git a/src/application/application.gyp b/src/application/application.gyp new file mode 100644 index 00000000..ff2b12db --- /dev/null +++ b/src/application/application.gyp @@ -0,0 +1,41 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_application', + 'type': 'loadable_module', + 'sources': [ + 'application_api.js', + 'application_extension.cc', + 'application_extension.h', + 'application_instance.cc', + 'application_instance.h', + 'application.cc', + 'application.h', + 'application_information.cc', + 'application_information.h', + 'application_context.cc', + 'application_context.h', + ], + 'includes': [ + '../common/pkg-config.gypi', + ], + 'conditions': [ + ['tizen == 1', { + 'variables': { + 'packages': [ + 'capi-appfw-app-manager', + 'capi-appfw-application', + 'capi-appfw-package-manager', + 'pkgmgr', + 'pkgmgr-info', + 'wrt-plugins-ipc-message', + ] + }, + }], + ], + }, + ], +} diff --git a/src/application/application.h b/src/application/application.h new file mode 100644 index 00000000..6fbd23ab --- /dev/null +++ b/src/application/application.h @@ -0,0 +1,48 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPLICATION_APPLICATION_H_ +#define APPLICATION_APPLICATION_H_ + +#include +#include + +#include "application/application_information.h" + +namespace extension { +namespace application { + +class Application; +typedef std::shared_ptr ApplicationPtr; + +class Application { + public: + Application(); + Application(const ApplicationPtr); + ~Application(); + + void Hide(); + void Exit(); + + const picojson::value& Value(); + bool IsValid() const; + + std::string get_context_id(); + void set_context_id(const std::string& context_id); + + ApplicationInformationPtr get_app_info() const; + void set_app_info(ApplicationInformationPtr &appInfo); + + private: + std::string context_id_; + ApplicationInformationPtr app_info_; + + picojson::object data_; + picojson::object error_; + picojson::value value_; +}; +} // namespace application +} // namespace extension + +#endif // APPLICATION_APPLICATION_H_ diff --git a/src/application/application_api.js b/src/application/application_api.js new file mode 100644 index 00000000..7c3bcc0c --- /dev/null +++ b/src/application/application_api.js @@ -0,0 +1,613 @@ +// Application +console.log("Application starts here ======================================="); + +var validator_ = xwalk.utils.validator; +var types_ = validator_.Types; + + +var callbackId = 0; +var callbacks = {}; + +extension.setMessageListener(function(json) { + var result = JSON.parse(json); + var callback = callbacks[result['callbackId']]; + callback(result); +}); + +function nextCallbackId() { + return callbackId++; +} + +var ExceptionMap = { + 'UnknownError' : tizen.WebAPIException.UNKNOWN_ERR , + 'TypeMismatchError' : tizen.WebAPIException.TYPE_MISMATCH_ERR , + 'InvalidValuesError' : tizen.WebAPIException.INVALID_VALUES_ERR , + 'IOError' : tizen.WebAPIException.IO_ERR , + 'ServiceNotAvailableError' : tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR , + 'SecurityError' : tizen.WebAPIException.SECURITY_ERR , + 'NetworkError' : tizen.WebAPIException.NETWORK_ERR , + 'NotSupportedError' : tizen.WebAPIException.NOT_SUPPORTED_ERR , + 'NotFoundError' : tizen.WebAPIException.NOT_FOUND_ERR , + 'InvalidAccessError' : tizen.WebAPIException.INVALID_ACCESS_ERR , + 'AbortError' : tizen.WebAPIException.ABORT_ERR , + 'QuotaExceededError' : tizen.WebAPIException.QUOTA_EXCEEDED_ERR , + 'InvalidState' : tizen.WebAPIException.INVALID_STATE_ERR , + 'InvalidModification' : tizen.WebAPIException.INVALID_MODIFICATION_ERR, +} + +function callNative(cmd, args) { + var json = {'cmd':cmd, 'args':args}; + var argjson = JSON.stringify(json); + var resultString = extension.internal.sendSyncMessage(argjson); + var result = JSON.parse(resultString); + + if (typeof result !== 'object') { + throw new tizen.WebAPIException(tizen.WebAPIException.UNKNOWN_ERR); + } + + if (result['status'] == 'success') { + if(result['result']) { + return result['result']; + } + return true; + } else if (result['status'] == 'error') { + var err = result['error']; + if(err) { + if(ExceptionMap[err.name]) { + throw new tizen.WebAPIException(ExceptionMap[err.name], err.message); + } else { + throw new tizen.WebAPIException(tizen.WebAPIException.UNKNOWN_ERR, err.message); + } + } + return false; + } +} + + +function callNativeWithCallback(cmd, args, callback) { + if(callback) { + var id = nextCallbackId(); + args['callbackId'] = id; + callbacks[id] = callback; + } + + return callNative(cmd, args); +} + +function SetReadOnlyProperty(obj, n, v){ + Object.defineProperty(obj, n, {value:v, writable: false}); +} + + +function ApplicationManager() { + // constructor of ApplicationManager +} + + +ApplicationManager.prototype.getCurrentApplication = function() { + var nativeParam = {}; + + try { + var syncResult = callNative('ApplicationManager_getCurrentApplication', nativeParam); + } catch(e) { + throw e; + } + + var appInfo = new ApplicationInformation(); + SetReadOnlyProperty(appInfo, 'id', syncResult.appInfo.id); + SetReadOnlyProperty(appInfo, 'name', syncResult.appInfo.name); + SetReadOnlyProperty(appInfo, 'iconPath', syncResult.appInfo.iconPath); + SetReadOnlyProperty(appInfo, 'version', syncResult.appInfo.version); + SetReadOnlyProperty(appInfo, 'show', syncResult.appInfo.show); + SetReadOnlyProperty(appInfo, 'categories', syncResult.appInfo.categories); + SetReadOnlyProperty(appInfo, 'installDate', syncResult.appInfo.installDate); + SetReadOnlyProperty(appInfo, 'size', syncResult.appInfo.size); + SetReadOnlyProperty(appInfo, 'packageId', syncResult.appInfo.packageId); + + var app = new Application(); + SetReadOnlyProperty(app, 'appInfo', appInfo); + SetReadOnlyProperty(app, 'contextId', syncResult.contextId); + return app; +} + +ApplicationManager.prototype.kill = function(contextId) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'contextId', 'type': types_.STRING}, + {'name' : 'successCallback', 'type': types_.FUCTION, optional : true, nullable : true}, + {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['contextId']) { + nativeParam['contextId'] = args.contextId; + } + + try { + var syncResult = callNativeWithCallback('ApplicationManager_kill', nativeParam, function(result) { + if (result.status == 'success') { + if (args.successCallback) { + args.successCallback(); + } + } + if (result.status == 'error') { + if (args.errorCallback) { + args.errorCallback(result.error); + } + } + }); + } catch(e) { + throw e; + } + +} + +ApplicationManager.prototype.launch = function(id) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'id', 'type': types_.STRING}, + {'name' : 'successCallback', 'type': types_.FUNCTION, optional : true, nullable : true}, + {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['id']) { + nativeParam['id'] = args.id; + } + + try { + var syncResult = callNativeWithCallback('ApplicationManager_launch', nativeParam, function(result) { + if (result.status == 'success') { + if (args.successCallback) { + args.successCallback(); + } + } + if (result.status == 'error') { + if (args.errorCallback) { + args.errorCallback(result.error); + } + } + }); + } catch(e) { + throw e; + } + +} + +// Fake call: kill test +/* +ApplicationManager.prototype.launch = function(contextId) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'contextId', 'type': types_.STRING}, + {'name' : 'successCallback', 'type': types_.FUNCTION, optional : true, nullable : true}, + {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['contextId']) { + nativeParam['contextId'] = args.contextId; + } + + try { + var syncResult = callNativeWithCallback('ApplicationManager_kill', nativeParam, function(result) { + if (result.status == 'success') { + if (args.successCallback) { + args.successCallback(); + } + } + if (result.status == 'error') { + if (args.errorCallback) { + args.errorCallback(result.error); + } + } + }); + } catch(e) { + throw e; + } + +} +*/ +ApplicationManager.prototype.launchAppControl = function(appControl) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'appControl', 'type': types_.DICTIONARY}, + {'name' : 'id', 'type': types_.STRING, optional : true, nullable : true}, + {'name' : 'successCallback', 'type': types_.FUNCTION, optional : true, nullable : true}, + {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true}, + {'name' : 'replyCallback', 'type': types_.LISTENER, 'values' : ['onsuccess', 'onfailure'], optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['id']) { + nativeParam['id'] = args.id; + } + try { + var syncResult = callNativeWithCallback('ApplicationManager_launchAppControl', nativeParam, function(result) { + if (result.status == 'success') { + if (args.successCallback) { + args.successCallback(); + } + } + if (result.status == 'error') { + if (args.errorCallback) { + args.errorCallback(result.error); + } + } + }); + } catch(e) { + throw e; + } + +} + +ApplicationManager.prototype.findAppControl = function(appControl, successCallback) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'appControl', 'type': types_.DICTIONARY}, + {'name' : 'successCallback', 'type': types_.FUNCTION, 'values' : ['onsuccess']}, + {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['appControl']) { + nativeParam['appControl'] = args.appControl; + } + try { + var syncResult = callNativeWithCallback('ApplicationManager_findAppControl', nativeParam, function(result) { + if (result.status == 'success') { + args.successCallback.onsuccess(/* success argument */); + } + }); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + +ApplicationManager.prototype.getAppsContext = function(successCallback) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'successCallback', 'type': types_.FUNCTION, 'values' : ['onsuccess']}, + {'name' : 'errorCallback', 'type': types_.FUNCTION, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + try { + var syncResult = callNativeWithCallback('ApplicationManager_getAppsContext', nativeParam, function(result) { + if (result.status == 'success') { + args.successCallback.onsuccess(/* success argument */); + } + }); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + +ApplicationManager.prototype.getAppContext = function() { + var args = validator_.validateArgs(arguments, [ + {'name' : 'contextId', 'type': types_.STING, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['contextId']) { + nativeParam['contextId'] = args.contextId; + } + try { + var syncResult = callNative('ApplicationManager_getAppContext', nativeParam); + } catch(e) { + throw e; + } + + var returnObject = new ApplicationContext(); + SetReadOnlyProperty(returnObject, 'id', null); // read only property + SetReadOnlyProperty(returnObject, 'appId', null); // read only property + + return returnObject; +} + +ApplicationManager.prototype.getAppsInfo = function(successCallback) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'successCallback', 'type': types_.FUNCTION, 'values' : ['onsuccess']}, + {'name' : 'errorCallback', 'type': types_.DICTIONARY, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + try { + var syncResult = callNativeWithCallback('ApplicationManager_getAppsInfo', nativeParam, function(result) { + if (result.status == 'success') { + args.successCallback.onsuccess(/* success argument */); + } + }); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + +ApplicationManager.prototype.getAppInfo = function() { + var args = validator_.validateArgs(arguments, [ + {'name' : 'id', 'type': types_.STRING, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['id']) { + nativeParam['id'] = args.id; + } + try { + var syncResult = callNative('ApplicationManager_getAppInfo', nativeParam); + } catch(e) { + throw e; + } + + var returnObject = new ApplicationInformation(); + SetReadOnlyProperty(returnObject, 'id', syncResult.id); + SetReadOnlyProperty(returnObject, 'name', syncResult.name); + SetReadOnlyProperty(returnObject, 'iconPath', syncResult.iconPath); + SetReadOnlyProperty(returnObject, 'version', syncResult.version); + SetReadOnlyProperty(returnObject, 'show', syncResult.show); + SetReadOnlyProperty(returnObject, 'categories', syncResult.categories); + SetReadOnlyProperty(returnObject, 'installDate', syncResult.installDate); + SetReadOnlyProperty(returnObject, 'size', syncResult.size); + SetReadOnlyProperty(returnObject, 'packageId', syncResult.packageId); + + return returnObject; +} + +ApplicationManager.prototype.getAppCerts = function() { + var args = validator_.validateArgs(arguments, [ + {'name' : 'id', 'type': types_.STRING, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['id']) { + nativeParam['id'] = args.id; + } + try { + var syncResult = callNative('ApplicationManager_getAppCerts', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + + var returnObject = new ApplicationCertificate(); + SetReadOnlyProperty(returnObject, 'type', null); // read only property + SetReadOnlyProperty(returnObject, 'value', null); // read only property + + return returnObject; +} + +ApplicationManager.prototype.getAppSharedURI = function() { + var args = validator_.validateArgs(arguments, [ + {'name' : 'id', 'type': types_.STRING, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['id']) { + nativeParam['id'] = args.id; + } + try { + var syncResult = callNative('ApplicationManager_getAppSharedURI', nativeParam); + } catch(e) { + throw e; + } + + return syncResult; +} + +ApplicationManager.prototype.getAppMetaData = function() { + var args = validator_.validateArgs(arguments, [ + {'name' : 'id', 'type': types_.STRING, optional : true, nullable : true} + ]); + + var nativeParam = { + }; + if (args['id']) { + nativeParam['id'] = args.id; + } + try { + var syncResult = callNative('ApplicationManager_getAppMetaData', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + + var returnObject = new ApplicationMetaData(); + SetReadOnlyProperty(returnObject, 'key', null); // read only property + SetReadOnlyProperty(returnObject, 'value', null); // read only property + + return returnObject; +} + +ApplicationManager.prototype.addAppInfoEventListener = function(eventCallback) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'eventCallback', 'type': types_.LISTENER, 'values' : ['oninstalled', 'onupdated', 'onuninstalled']} + ]); + + var nativeParam = { + }; + try { + var syncResult = callNativeWithCallback('ApplicationManager_addAppInfoEventListener', nativeParam, function(result) { + if (result.type == 'oninstalled') { + args.eventCallback.oninstalled(result.info); + } + if (result.type == 'onupdated') { + args.eventCallback.onupdated(result.info); + } + if (result.type == 'onuninstalled') { + args.eventCallback.onuninstalled(result.id); + } + }); + } catch(e) { + throw e; + } + + return syncResult; +} + +ApplicationManager.prototype.removeAppInfoEventListener = function(watchId) { + var args = validator_.validateArgs(arguments, [ + {'name' : 'watchId', 'type': types_.LONG} + ]); + + var nativeParam = { + 'watchId': args.watchId + }; + try { + var syncResult = callNative('ApplicationManager_removeAppInfoEventListener', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } +} + + +function Application() { + // constructor of Application +} + + +Application.prototype.exit = function() { + var nativeParam = {}; + try { + var syncResult = callNative('Application_exit', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + +Application.prototype.hide = function() { + var nativeParam = {}; + try { + var syncResult = callNative('Application_hide', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + +Application.prototype.getRequestedAppControl = function() { + var nativeParam = {}; + try { + var syncResult = callNative('Application_getRequestedAppControl', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + + var returnObject = new RequestedApplicationControl(); + SetReadOnlyProperty(returnObject, 'appControl', null); // read only property + SetReadOnlyProperty(returnObject, 'callerAppId', null); // read only property + + return returnObject; +} + + +function ApplicationInformation() { + // constructor of ApplicationInformation +} + + + +function ApplicationContext() { + // constructor of ApplicationContext +} + +tizen.ApplicationControlData = function(key, value) { + if (this && this.constructor == tizen.ApplicationControlData && + (typeof(key) == 'string' || key instanceof String) && + (value && value instanceof Array)) { + + Object.defineProperties(this, { + 'key': { writable: true, enumerable: true, value: key }, + 'value': { writable: true, enumerable: true, value: value } + }); + + } else { + throw new exports.WebAPIException(exports.WebAPIException.TYPE_MISMATCH_ERR); + } +}; + +tizen.ApplicationControl = function(operation, uri, mime, category, data) { + + if (this && this.constructor == tizen.ApplicationControl && + (typeof(operation) == 'string' || operation instanceof String) && + data) { + + Object.defineProperties(this, { + 'operation': { writable: true, enumerable: true, value: operation }, + 'uri': { writable: true, enumerable: true, value: uri === undefined ? null : uri }, + 'mime': { writable: true, enumerable: true, value: mime === undefined ? null : mime }, + 'category': { writable: true, enumerable: true, value: category === undefined ? null : category }, + 'data': { writable: true, enumerable: true, value: data } + }); + + } else { + throw new exports.WebAPIException(exports.WebAPIException.TYPE_MISMATCH_ERR); + } +}; + +function RequestedApplicationControl() { + // constructor of RequestedApplicationControl +} + + +RequestedApplicationControl.prototype.replyResult = function() { + var args = validator_.validateArgs(arguments, [ + {'name' : 'data', 'type': types_.ARRAY, optional : true} + ]); + + var nativeParam = { + }; + if (args['data']) { + nativeParam['data'] = args.data; + } + try { + var syncResult = callNative('RequestedApplicationControl_replyResult', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + +RequestedApplicationControl.prototype.replyFailure = function() { + + try { + var syncResult = callNative('RequestedApplicationControl_replyFailure', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch(e) { + throw e; + } + +} + + +function ApplicationCertificate() { + // constructor of ApplicationCertificate +} + + + +function ApplicationMetaData() { + // constructor of ApplicationMetaData +} + + + + +exports = new ApplicationManager(); + +console.log("======================================= Application ends here"); diff --git a/src/application/application_context.cc b/src/application/application_context.cc new file mode 100644 index 00000000..0c2fd477 --- /dev/null +++ b/src/application/application_context.cc @@ -0,0 +1,62 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "application/application_context.h" + +#include + +#include "common/logger.h" +#include "tizen/tizen.h" + +namespace extension { +namespace application { + +ApplicationContext::ApplicationContext() { + +} + +ApplicationContext::ApplicationContext(const ApplicationContextPtr app) { + +} + +ApplicationContext::ApplicationContext(const std::string& context_id) + : context_id_(context_id) { + +} + +ApplicationContext::~ApplicationContext() { +} + +const picojson::value& ApplicationContext::Value() { + if (value_.is() && IsValid()) { + picojson::object obj; + obj["id"] = picojson::value(context_id_); + obj["appId"] = picojson::value(app_id_); + value_ = picojson::value(obj); + } + return value_; +} + +bool ApplicationContext::IsValid() const { + return error_.empty(); +} + +std::string ApplicationContext::get_context_id() { + return context_id_; +} + +void ApplicationContext::set_context_id(const std::string& context_id) { + context_id_ = context_id; +} + +std::string ApplicationContext::get_app_id() { + return app_id_; +} + +void ApplicationContext::set_app_id(const std::string& app_id) { + app_id_ = app_id; +} + +} // namespace application +} // namespace extension diff --git a/src/application/application_context.h b/src/application/application_context.h new file mode 100644 index 00000000..48afe4ee --- /dev/null +++ b/src/application/application_context.h @@ -0,0 +1,48 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPLICATION_APPLICATION_CONTEXT_H_ +#define APPLICATION_APPLICATION_CONTEXT_H_ + +#include +#include + +#include "common/picojson.h" +#include "tizen/tizen.h" + +namespace extension { +namespace application { + +class ApplicationContext; +typedef std::shared_ptr ApplicationContextPtr; + +class ApplicationContext { + public: + ApplicationContext(); + ApplicationContext(const std::string& context_id); + ApplicationContext(const ApplicationContextPtr); + ~ApplicationContext(); + + const picojson::value& Value(); + bool IsValid() const; + + std::string get_context_id(); + void set_context_id(const std::string& context_id); + + std::string get_app_id(); + void set_app_id(const std::string& app_id); + + + private: + std::string context_id_; + std::string app_id_; + + picojson::object data_; + picojson::object error_; + picojson::value value_; +}; +} // namespace application +} // namespace extension + +#endif // APPLICATION_APPLICATION_CONTEXT_H_ diff --git a/src/application/application_extension.cc b/src/application/application_extension.cc new file mode 100644 index 00000000..3ad1aab8 --- /dev/null +++ b/src/application/application_extension.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2014 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "application/application_extension.h" + +#include +#include + +#include "application/application_instance.h" +#include "common/logger.h" + +// This will be generated from application_api.js +extern const char kSource_application_api[]; + +common::Extension* CreateExtension() { + + std::string app_id = common::Extension::GetRuntimeVariable("app_id", 64); + LoggerD("app_id: %s", app_id.c_str()); + + if (app_id.empty()) { + LoggerD("Application extension will not be created."); + return NULL; + } + + return new ApplicationExtension(app_id); +} + +ApplicationExtension::ApplicationExtension(const std::string& app_id) { + app_id_ = app_id; + + SetExtensionName("tizen.application"); + SetJavaScriptAPI(kSource_application_api); + + const char* entry_points[] = { + "tizen.ApplicationControlData", "tizen.ApplicationControl", NULL}; + SetExtraJSEntryPoints(entry_points); +} + +ApplicationExtension::~ApplicationExtension() {} + +common::Instance* ApplicationExtension::CreateInstance() { + return new extension::application::ApplicationInstance(app_id_); +} diff --git a/src/application/application_extension.h b/src/application/application_extension.h new file mode 100644 index 00000000..c14b23ef --- /dev/null +++ b/src/application/application_extension.h @@ -0,0 +1,23 @@ +// Copyright (c) 2014 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPLICATION_APPLICATION_EXTENSION_H_ +#define APPLICATION_APPLICATION_EXTENSION_H_ + +#include + +#include "common/extension.h" + +class ApplicationExtension : public common::Extension { + public: + explicit ApplicationExtension(const std::string& app_id); + virtual ~ApplicationExtension(); + + private: + std::string app_id_; + // common::Extension implementation. + virtual common::Instance* CreateInstance(); +}; + +#endif // APPLICATION_APPLICATION_EXTENSION_H_ diff --git a/src/application/application_information.cc b/src/application/application_information.cc new file mode 100644 index 00000000..73bcf682 --- /dev/null +++ b/src/application/application_information.cc @@ -0,0 +1,135 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "application/application_information.h" + +#include + +#include "common/logger.h" +#include "tizen/tizen.h" + +namespace extension { +namespace application { + +ApplicationInformation::ApplicationInformation() { + +} + +ApplicationInformation::ApplicationInformation(const ApplicationInformationPtr app) { + +} + +ApplicationInformation::~ApplicationInformation() { + +} + +std::string ApplicationInformation::get_app_id() const { + return app_id_; +} + +void ApplicationInformation::set_app_id(const std::string &app_id) { + app_id_ = app_id; +} + +std::string ApplicationInformation::get_name() const { + return name_; +} + +void ApplicationInformation::set_name(const std::string &name) { + name_ = name; +} + +std::string ApplicationInformation::get_icon_path() const { + return icon_path_; +} + +void ApplicationInformation::set_icon_path(const std::string &icon_path) { + icon_path_ = icon_path; +} + +bool ApplicationInformation::get_show() const { + return show_; +} + +void ApplicationInformation::set_show(const bool show) { + show_ = show; +} + +std::string ApplicationInformation::get_package_id() const { + return package_id_; +} + +void ApplicationInformation::set_package_id(const std::string &package_id) { + package_id_ = package_id; +} + +std::string ApplicationInformation::get_version() const { + return version_; +} + +void ApplicationInformation::set_version(const std::string &version) { + version_ = version; +} + +double ApplicationInformation::get_install_date() const { + return install_date_; +} + +void ApplicationInformation::set_install_date(const time_t &install_date) { + install_date_ = (double)(install_date); + + // pkgmgrinfo_pkginfo_get_installed_time() returns installed time by using int type + // but, it can't have millisecond value fully + install_date_ = install_date_ * 1000; +} + +std::vector ApplicationInformation::get_categories() const { + return categories_; +} + +void ApplicationInformation::set_categories(const std::vector &categories) { + categories_ = categories; +} + +void ApplicationInformation::add_categories(const std::string &category) { + categories_.push_back(category); +} + +void ApplicationInformation::set_size(const int &size) { + size_ = (double)size; +} + +double ApplicationInformation::get_size() const { + return size_; +} + +const picojson::value& ApplicationInformation::Value() { + if (value_.is() && IsValid()) { + data_["id"] = picojson::value(app_id_); + data_["name"] = picojson::value(name_); + data_["iconPath"] = picojson::value(icon_path_); + data_["show"] = picojson::value(show_); + data_["packageId"] = picojson::value(package_id_); + data_["version"] = picojson::value(version_); + data_["installDate"] = picojson::value(install_date_); + picojson::value categories = picojson::value(picojson::array()); + picojson::array& categories_array = categories.get(); + for (auto it = categories_.begin(); it != categories_.end(); it++) { + categories_array.push_back(picojson::value(*it)); + } + data_["categories"] = categories; + LoggerD("size: %f", size_); + data_["size"] = picojson::value(size_); + + value_ = picojson::value(data_); + } + return value_; +} + +bool ApplicationInformation::IsValid() const { + return error_.empty(); +} + +} // namespace application +} // namespace extension diff --git a/src/application/application_information.h b/src/application/application_information.h new file mode 100644 index 00000000..40b4be8d --- /dev/null +++ b/src/application/application_information.h @@ -0,0 +1,67 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPLICATION_APPLICATION_INFORMATION_H_ +#define APPLICATION_APPLICATION_INFORMATION_H_ + +#include +#include + +#include "common/picojson.h" + +namespace extension { +namespace application { + +class ApplicationInformation; +typedef std::shared_ptr ApplicationInformationPtr; + +class ApplicationInformation { + public: + ApplicationInformation(); + ApplicationInformation(const ApplicationInformationPtr); + ~ApplicationInformation(); + + const picojson::value& Value(); + bool IsValid() const; + + std::string get_app_id() const; + void set_app_id(const std::string &app_id); + std::string get_name() const; + void set_name(const std::string &name); + std::string get_icon_path() const; + void set_icon_path(const std::string &icon_path); + bool get_show() const; + void set_show(const bool show); + void set_package_id(const std::string &package_id); + std::string get_package_id() const; + void set_version(const std::string &version); + std::string get_version() const; + void set_install_date(const time_t& install_date); + double get_install_date() const; + std::vector get_categories() const; + void set_categories(const std::vector &categories); + void add_categories(const std::string &category); + void set_size(const int& size); + double get_size() const; + + private: + std::string app_id_; + std::string name_; + std::string icon_path_; + bool show_; + std::string package_id_; + std::string version_; + double install_date_; + std::vector categories_; + double size_; + + picojson::object data_; + picojson::object error_; + picojson::value value_; +}; + +} // namespace application +} // namespace extension + +#endif // APPLICATION_APPLICATION_INFORMATION_H_ diff --git a/src/application/application_instance.cc b/src/application/application_instance.cc new file mode 100644 index 00000000..b1438721 --- /dev/null +++ b/src/application/application_instance.cc @@ -0,0 +1,1233 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "application/application_instance.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +// to launch app by aul +#include + +// to get package name by appid +#include +#include + +// To get cert information from package +#include +#include + +// To get app size and installed time +#include + +#include + +// To get ppid +#include + +#include "common/logger.h" +#include "common/picojson.h" +#include "common/platform_exception.h" +#include "common/task-queue.h" + +#include "application.h" +#include "application_context.h" + +namespace extension { +namespace application { + +namespace { +// The privileges that required in Application API +const std::string kPrivilegeApplication = ""; + +} // namespace + +using namespace common; +using namespace extension::application; + +static int category_cb(const char *category, void *user_data) { + LoggerD("category: %s", category); + if (category == NULL) + return true; + + ApplicationInformation* appInfo = (ApplicationInformation*)user_data; + appInfo->add_categories(category); + return true; +} + + +ApplicationInstance::ApplicationInstance(const std::string& app_id) { + manager_handle_ = NULL; + watch_id_ = 0; + app_id_ = app_id; + + using namespace std::placeholders; + #define REGISTER_SYNC(c,x) \ + RegisterSyncHandler(c, std::bind(&ApplicationInstance::x, this, _1, _2)); + REGISTER_SYNC("ApplicationManager_getAppCerts", ApplicationManagerGetappcerts); + REGISTER_SYNC("Application_getRequestedAppControl", ApplicationGetrequestedappcontrol); + REGISTER_SYNC("ApplicationManager_addAppInfoEventListener", ApplicationManagerAddappinfoeventlistener); + REGISTER_SYNC("ApplicationManager_getAppMetaData", ApplicationManagerGetappmetadata); + REGISTER_SYNC("ApplicationManager_launchAppControl", ApplicationManagerLaunchappcontrol); + REGISTER_SYNC("ApplicationManager_removeAppInfoEventListener", ApplicationManagerRemoveappinfoeventlistener); + REGISTER_SYNC("ApplicationManager_getAppInfo", ApplicationManagerGetappinfo); + REGISTER_SYNC("ApplicationManager_getAppSharedURI", ApplicationManagerGetappshareduri); + REGISTER_SYNC("RequestedApplicationControl_replyResult", RequestedApplicationControlReplyresult); + REGISTER_SYNC("ApplicationManager_kill", ApplicationManagerKill); + REGISTER_SYNC("ApplicationManager_getAppsInfo", ApplicationManagerGetappsinfo); + REGISTER_SYNC("ApplicationManager_launch", ApplicationManagerLaunch); + REGISTER_SYNC("Application_hide", ApplicationHide); + REGISTER_SYNC("ApplicationManager_getAppsContext", ApplicationManagerGetappscontext); + REGISTER_SYNC("ApplicationManager_getAppContext", ApplicationManagerGetappcontext); + REGISTER_SYNC("RequestedApplicationControl_replyFailure", RequestedApplicationControlReplyfailure); + REGISTER_SYNC("Application_exit", ApplicationExit); + REGISTER_SYNC("ApplicationManager_getCurrentApplication", ApplicationManagerGetcurrentapplication); + REGISTER_SYNC("ApplicationManager_findAppControl", ApplicationManagerFindappcontrol); + #undef REGISTER_SYNC + + set_installed_size(GetAppInstalledSize(app_id_)); +/* + pkgmgrinfo_appinfo_h handle; + int ret = pkgmgrinfo_appinfo_get_appinfo(app_id_.c_str(), &handle); + if (ret == PMINFO_R_OK) { + ret = pkgmgrinfo_appinfo_foreach_category(handle, category_cb, NULL); + if (ret != PMINFO_R_OK) { + LoggerD("Failed to get category info"); + pkgmgrinfo_appinfo_destroy_appinfo(handle); + } else { + LoggerD("Waiting for callback"); + } + } else { + LoggerD("Failed to get handle"); + } +*/ +} + +ApplicationInstance::~ApplicationInstance() { + LoggerD("Destructor of ApplicationInstance called."); +} + + +enum ApplicationErrors { + APP_ERROR_OK = 0, + APP_ERROR_UNKNOWN = 1, + APP_ERROR_TYPE_MISMATCH = 2, + APP_ERROR_IO = 3, + APP_ERROR_SVC_NOT_AVAILABLE = 4, + APP_ERROR_SECURITY = 5, + APP_ERROR_NETWORK = 6, + APP_ERROR_NOT_SUPPORTED = 7, + APP_ERROR_NOT_FOUND = 8, + APP_ERROR_INVALID_ACCESS = 9, + APP_ERROR_ABORT = 10, + APP_ERROR_QUOTA_EXCEEDED = 11, + APP_ERROR_INVALID_STATE = 12, + APP_ERROR_INVALID_MODIFICATION = 13, +}; + +enum ApplicationCallbacks { + ApplicationManagerGetappcertsCallback, + ApplicationGetrequestedappcontrolCallback, + ApplicationManagerAddappinfoeventlistenerCallback, + ApplicationManagerGetappmetadataCallback, + ApplicationManagerLaunchappcontrolCallback, + ApplicationManagerRemoveappinfoeventlistenerCallback, + ApplicationManagerGetappinfoCallback, + ApplicationManagerGetappshareduriCallback, + RequestedApplicationControlReplyresultCallback, + ApplicationManagerKillCallback, + ApplicationManagerGetappsinfoCallback, + ApplicationManagerLaunchCallback, + ApplicationHideCallback, + ApplicationManagerGetappscontextCallback, + ApplicationManagerGetappcontextCallback, + RequestedApplicationControlReplyfailureCallback, + ApplicationExitCallback, + ApplicationManagerGetcurrentapplicationCallback, + ApplicationManagerFindappcontrolCallback +}; + +struct CallbackInfo { + ApplicationInstance* instance; + bool is_success; + int error_type; + char error_msg[256]; + char id[256]; + int callback_id; +}; + +static picojson::value GetAppError(int type, const char* msg) { + switch (type) { + case APP_ERROR_UNKNOWN: + return UnknownException(msg).ToJSON(); + case APP_ERROR_TYPE_MISMATCH: + return TypeMismatchException(msg).ToJSON(); + case APP_ERROR_IO: + return IOException(msg).ToJSON(); + case APP_ERROR_SVC_NOT_AVAILABLE: + return ServiceNotAvailableException(msg).ToJSON(); + case APP_ERROR_SECURITY: + return SecurityException(msg).ToJSON(); + case APP_ERROR_NETWORK: + return NetworkException(msg).ToJSON(); + case APP_ERROR_NOT_SUPPORTED: + return NotSupportedException(msg).ToJSON(); + case APP_ERROR_NOT_FOUND: + return NotFoundException(msg).ToJSON(); + case APP_ERROR_INVALID_ACCESS: + return InvalidAccessException(msg).ToJSON(); + case APP_ERROR_ABORT: + return AbortException(msg).ToJSON(); + case APP_ERROR_QUOTA_EXCEEDED: + return QuotaExceededException(msg).ToJSON(); + case APP_ERROR_INVALID_STATE: + return InvalidStateException(msg).ToJSON(); + case APP_ERROR_INVALID_MODIFICATION: + return InvalidModificationException(msg).ToJSON(); + default: + return UnknownException(msg).ToJSON(); + } +} +static void ReplyAsync(ApplicationInstance* instance, ApplicationCallbacks cbfunc, + int callback_id, bool isSuccess, picojson::object& param, int err_id, const char* err_msg) { + param["callbackId"] = picojson::value(static_cast(callback_id)); + if (isSuccess) { + param["status"] = picojson::value("success"); + } else { + param.insert(std::make_pair("status", picojson::value("error"))); + param.insert(std::make_pair("error", GetAppError(err_id, err_msg))); + } + + // insert result for async callback to param + switch(cbfunc) { + case ApplicationManagerGetcurrentapplicationCallback: { + // do something... + break; + } + case ApplicationManagerKillCallback: { + LoggerD("ApplicationManagerKillCallbak called"); + break; + } + case ApplicationManagerLaunchCallback: { + LoggerD("ApplicationManagerLaunchCallbak called"); + break; + } + case ApplicationManagerLaunchappcontrolCallback: { + LoggerD("ApplicationManagerLaunchCallbak called"); + break; + } + case ApplicationManagerFindappcontrolCallback: { + // do something... + break; + } + case ApplicationManagerGetappscontextCallback: { + // do something... + break; + } + case ApplicationManagerGetappcontextCallback: { + // do something... + break; + } + case ApplicationManagerGetappsinfoCallback: { + // do something... + break; + } + case ApplicationManagerGetappinfoCallback: { + // do something... + break; + } + case ApplicationManagerGetappcertsCallback: { + // do something... + break; + } + case ApplicationManagerGetappshareduriCallback: { + // do something... + break; + } + case ApplicationManagerGetappmetadataCallback: { + // do something... + break; + } + case ApplicationManagerAddappinfoeventlistenerCallback: { + LoggerD("ApplicationManagerAppappinfoeventlistenerCallback called"); + break; + } + case ApplicationManagerRemoveappinfoeventlistenerCallback: { + // do something... + break; + } + case ApplicationExitCallback: { + // do something... + break; + } + case ApplicationHideCallback: { + // do something... + break; + } + case ApplicationGetrequestedappcontrolCallback: { + // do something... + break; + } + case RequestedApplicationControlReplyresultCallback: { + // do something... + break; + } + case RequestedApplicationControlReplyfailureCallback: { + // do something... + break; + } + default: { + LoggerE("Invalid Callback Type"); + return; + } + } + + picojson::value result = picojson::value(param); + LoggerD("async result: %s", result.serialize().c_str()); + instance->PostMessage(result.serialize().c_str()); +} + +static ApplicationInformationPtr get_app_info(pkgmgrinfo_appinfo_h handle) { + char* app_id = NULL; + char* name = NULL; + char* icon_path = NULL; + bool no_display = false; + char* pkg_id = NULL; + int ret = 0; + + ApplicationInformationPtr app_info(new ApplicationInformation()); + ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id); + if (ret != PMINFO_R_OK) { + LoggerD("Fail to get appid"); + } else { + app_info->set_app_id(app_id); + } + + ret = pkgmgrinfo_appinfo_get_label(handle, &name); + if ((ret != PMINFO_R_OK) || (name == NULL)) { + LoggerD("Fail to get label"); + } else { + app_info->set_name(name); + } + + ret = pkgmgrinfo_appinfo_get_icon(handle, &icon_path); + if ((ret != PMINFO_R_OK) || (icon_path == NULL)) { + LoggerD("Fail to get icon"); + } else { + app_info->set_icon_path(icon_path); + } + + ret = pkgmgrinfo_appinfo_foreach_category(handle, category_cb, (void*)app_info.get()); + if (ret != PMINFO_R_OK) { + LoggerD("Fail to get categories"); + } else { + LoggerD("Waiting for callback response..."); + } + + ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &no_display); + if (ret != PMINFO_R_OK) { + LoggerD("Fail to get nodisplay"); + } else { + app_info->set_show(!no_display); + } + + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkg_id); + if ((ret != PMINFO_R_OK) || (pkg_id == NULL)) { + LoggerD("Fail to get pkgId"); + return app_info; + } else { + app_info->set_package_id(pkg_id); + } + + char* version = NULL; + int installed_time = 0; + pkgmgrinfo_pkginfo_h pkginfo_h; + + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkg_id, &pkginfo_h); + if (ret != PMINFO_R_OK) { + LoggerE("Fail to get pkginfo"); + } else { + ret = pkgmgrinfo_pkginfo_get_version(pkginfo_h, &version); + if (ret != PMINFO_R_OK) { + LoggerE("Fail to get version"); + } else { + app_info->set_version(version); + } + + ret = pkgmgrinfo_pkginfo_get_installed_time(pkginfo_h, &installed_time); + if (ret != PMINFO_R_OK) { + LoggerE("Fail to get installed time"); + } else { + app_info->set_install_date(installed_time); + LoggerD("installed_time: %d", installed_time); + } + + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + } + + // size + return app_info; +} + +// Callback from 'app_manager_set_app_context_event_cb' +// Used by 'kill' +static void app_manager_app_context_event_callback(app_context_h app_context, + app_context_event_e event, void *user_data) { + + CallbackInfo *info = (CallbackInfo*)user_data; + int ret = 0; + + LoggerD("context_id: %s, callback_id: %d", info->id, info->callback_id); + if(event != APP_CONTEXT_EVENT_TERMINATED) { + picojson::object data; + info->error_type = APP_ERROR_UNKNOWN; + sprintf(info->error_msg, "Not terminated."); + ReplyAsync(info->instance, ApplicationManagerKillCallback, info->callback_id, + false, data, info->error_type, info->error_msg); + } else { + picojson::object data; + ReplyAsync(info->instance, ApplicationManagerKillCallback, info->callback_id, + true, data, 0, NULL); + } + + if (user_data) + free(user_data); +} + +static gboolean LaunchCompleted(const std::shared_ptr& user_data) +{ + LoggerD("Entered"); + picojson::object data; + + if (user_data->is_success) { + ReplyAsync(user_data->instance, ApplicationManagerLaunchCallback, user_data->callback_id, + true, data, 0, NULL); + } else { + ReplyAsync(user_data->instance, ApplicationManagerLaunchCallback, user_data->callback_id, + false, data, user_data->error_type, user_data->error_msg); + } + return true; +} +static void* LaunchThread(const std::shared_ptr& user_data) +{ + int ret; + + LoggerD("app_id: %s, callback_id: %d", user_data->id, user_data->callback_id); + + ret = aul_open_app(user_data->id); + if (ret < 0) { + std::string msg; + int type = APP_ERROR_OK; + switch (ret) { + case AUL_R_EINVAL: + case AUL_R_ERROR: + LoggerE("Not Found error"); + msg = "Not Found error"; + type = APP_ERROR_NOT_FOUND; + break; + case AUL_R_ECOMM: + LoggerE("Internal IPC error"); + msg = "Internal IPC error"; + type = APP_ERROR_IO; + break; + default: + LoggerE("Unknown error"); + msg = "Unknown error"; + type = APP_ERROR_UNKNOWN; + break; + } + user_data->is_success = false; + user_data->error_type = type; + sprintf(user_data->error_msg, msg.c_str()); + } else { + LoggerD("Success to launch."); + user_data->is_success = true; + } +} + +#define CHECK_EXIST(args, name, out) \ + if (!args.contains(name)) {\ + ReportError(TypeMismatchException(name" is required argument"), out);\ + return;\ + } + +void ApplicationInstance::ApplicationManagerGetcurrentapplication(const picojson::value& args, picojson::object& out) { + + try { + ApplicationPtr app = GetCurrentApplication(app_id_); + LoggerD("context id = %s", app->get_context_id().c_str()); + ReportSuccess(app->Value(), out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerKill(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + const std::string& contextId = args.get("contextId").get(); + + LoggerD("callbackId = %d", callbackId); + LoggerD("contextId = %s", contextId.c_str()); + + try { + Kill(contextId, callbackId); + ReportSuccess(out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerLaunch(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + const std::string& id = args.get("id").get(); + + LoggerD("callbackId = %d", callbackId); + LoggerD("appId = %s", id.c_str()); + + try { + Launch(id, callbackId); + ReportSuccess(out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerLaunchappcontrol(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + const std::string& id = args.get("id").get(); + + LoggerD("callbackId = %d", callbackId); + LoggerD("appId = %s", id.c_str()); + + try { + ReportSuccess(out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerFindappcontrol(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + + // implement it + + // call ReplyAsync in later (Asynchronously) + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::ApplicationManagerGetappscontext(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + + // implement it + + // call ReplyAsync in later (Asynchronously) + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::ApplicationManagerGetappcontext(const picojson::value& args, picojson::object& out) { + const std::string& contextId = args.get("contextId").get(); + + LoggerD("contextId = %s", contextId.c_str()); + + try { + ApplicationContextPtr appCtx; + if (contextId.compare("null") == 0) + appCtx = GetAppContext(""); + else + appCtx = GetAppContext(contextId); + + LoggerD("appCtx: id = %s", appCtx->get_context_id().c_str()); + LoggerD("appCtx: appId = %s", appCtx->get_app_id().c_str()); + + ReportSuccess(picojson::value(appCtx->Value()), out); + } catch (const PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerGetappsinfo(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + + // implement it + + // call ReplyAsync in later (Asynchronously) + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::ApplicationManagerGetappinfo(const picojson::value& args, picojson::object& out) { + std::string id; + if (args.contains("id")) { + id = args.get("id").get(); + if (id.empty()) { + LoggerD("Id is null. use current app id"); + id = app_id_; + } + } else { + id = app_id_; + } + + LoggerD("app_id = %s", id.c_str()); + + try { + ApplicationInformationPtr app_info_ptr = GetAppInfo(id); + ReportSuccess(app_info_ptr->Value(), out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } + +} +void ApplicationInstance::ApplicationManagerGetappcerts(const picojson::value& args, picojson::object& out) { + + + // implement it + + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::ApplicationManagerGetappshareduri(const picojson::value& args, picojson::object& out) { + std::string id; + if (args.contains("id")) { + id = args.get("id").get(); + if (id.empty()) { + LoggerD("Id is null. use current app id"); + id = app_id_; + } + } else { + id = app_id_; + } + + LoggerD("app_id = %s", id.c_str()); + + try { + const std::string& ret = GetAppSharedURI(id); + ReportSuccess(picojson::value(ret), out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerGetappmetadata(const picojson::value& args, picojson::object& out) { + + + // implement it + + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::ApplicationManagerAddappinfoeventlistener(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + + int callbackId = static_cast(args.get("callbackId").get()); + + try { + const double ret = static_cast(AddAppInfoEventListener(callbackId)); + ReportSuccess(picojson::value(ret), out); + } catch (const common::PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationManagerRemoveappinfoeventlistener(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "watchId", out) + long watch_id = static_cast(args.get("watchId").get()); + + try { + RemoveAppInfoEventListener(watch_id); + ReportSuccess(out); + } catch (const PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationExit(const picojson::value& args, picojson::object& out) { + LoggerD("Hide is called"); + + try { + //Blink + //IPCSupport::Instance().Post(IPCMsg::MsgExitApp(), "" ); + IPCMessageSupport::sendAsyncMessageToUiProcess(IPCMessageSupport::TIZEN_EXIT, NULL, NULL, NULL); + ReportSuccess(out); + } catch (const PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationHide(const picojson::value& args, picojson::object& out) { + LoggerD("Hide is called"); + + try { + //Blink + //IPCSupport::Instance().Post(IPCMsg::MsgHideApp(), "" ); + + IPCMessageSupport::sendAsyncMessageToUiProcess(IPCMessageSupport::TIZEN_HIDE, NULL, NULL, NULL); + ReportSuccess(out); + } catch (const PlatformException& err) { + ReportError(err, out); + } catch (...) { + ReportError(out); + } +} +void ApplicationInstance::ApplicationGetrequestedappcontrol(const picojson::value& args, picojson::object& out) { + + + // implement it + + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::RequestedApplicationControlReplyresult(const picojson::value& args, picojson::object& out) { + + + // implement it + + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void ApplicationInstance::RequestedApplicationControlReplyfailure(const picojson::value& args, picojson::object& out) { + + + // implement it + + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +ApplicationPtr ApplicationInstance::GetCurrentApplication(const std::string app_id) { + + LoggerD("app_id: %s", app_id.c_str()); + + pkgmgrinfo_appinfo_h handle; + int ret = pkgmgrinfo_appinfo_get_appinfo(app_id.c_str(), &handle); + if (ret != PMINFO_R_OK) { + LoggerE("Fail to get appInfo"); + throw UnknownException("pkgmgrinfo_appinfo_get_appinfo error : unknown error"); + } + + ApplicationInformationPtr app_info_ptr = get_app_info(handle); + app_info_ptr->set_size(get_installed_size()); + + pkgmgrinfo_appinfo_destroy_appinfo(handle); + + Application *app = new Application(); + ApplicationPtr app_ptr = ApplicationPtr(app); + app_ptr->set_app_info(app_info_ptr); + + LoggerD("set appinfo to application"); + { + int pid = getppid(); + LoggerD("context id = %d", pid); + + std::stringstream sstr; + sstr << pid; + app_ptr->set_context_id(sstr.str()); + } + + return app_ptr; +} +ApplicationInformationPtr ApplicationInstance::GetAppInfo(const std::string app_id) { + + LoggerD("app_id: %s", app_id.c_str()); + + pkgmgrinfo_appinfo_h handle; + int ret = pkgmgrinfo_appinfo_get_appinfo(app_id.c_str(), &handle); + if (ret != PMINFO_R_OK) { + LoggerE("Fail to get appInfo"); + throw NotFoundException("Given app id is not found"); + } + + ApplicationInformationPtr app_info_ptr = get_app_info(handle); + if (app_id.compare(app_id_) == 0) { + app_info_ptr->set_size(get_installed_size()); + } else { + app_info_ptr->set_size(GetAppInstalledSize(app_id)); + } + + pkgmgrinfo_appinfo_destroy_appinfo(handle); + + return app_info_ptr; +} +void ApplicationInstance::Kill(const std::string contextId, int callbackId) { + if (contextId.empty()) { + LoggerE("contextId is mandatory field."); + throw InvalidValuesException("Context id is mandatory field."); + } + + int ret; + int pid; + std::stringstream(contextId) >> pid; + + if (pid <= 0) { + LoggerE("Given context id is wrong."); + throw InvalidValuesException("Given context id is wrong."); + } + + // if kill request is come for current context, throw InvalidValueException by spec + if (pid == getppid()) { + LoggerE("Given context id is same with me."); + throw InvalidValuesException("Given context id is same with me."); + } + + char *appIdCStr = NULL; + ret = app_manager_get_app_id(pid, &appIdCStr); + if (ret != APP_MANAGER_ERROR_NONE) { + LoggerE("Error while getting app id"); + throw NotFoundException("Error while getting app id"); + } + + std::string appId = appIdCStr; + free(appIdCStr); + + app_context_h appContext; + ret = app_manager_get_app_context (appId.c_str(), &appContext); + if (ret != APP_MANAGER_ERROR_NONE) { + LoggerE("Error while getting app context"); + throw NotFoundException("Error while getting app context"); + } + + CallbackInfo* info = (CallbackInfo*)malloc(sizeof(CallbackInfo)); + info->instance = this; + sprintf(info->id, "%s", contextId.c_str()); + info->callback_id = callbackId; + + // TODO thread + ret = app_manager_set_app_context_event_cb(app_manager_app_context_event_callback, info); + if (ret != APP_MANAGER_ERROR_NONE) { + if (info) + free(info); + LoggerE("Error while registering app context event"); + throw InvalidValuesException("Error while registering app context event"); + } + + ret = app_manager_terminate_app(appContext); + if (ret != APP_MANAGER_ERROR_NONE) { + if (info) + free(info); + LoggerE("Error while terminating app"); + throw InvalidValuesException("Error while terminating app"); + } + +} +void ApplicationInstance::Launch(const std::string appId, int callbackId) { + if (appId.empty()) { + LoggerE("appId is mandatory field."); + throw InvalidValuesException("App id is mandatory field."); + } + + auto user_data = std::shared_ptr(new CallbackInfo); + user_data->instance = this; + sprintf(user_data->id, "%s", appId.c_str()); + user_data->callback_id = callbackId; + + common::TaskQueue::GetInstance().Queue(LaunchThread, LaunchCompleted, user_data); +} + +ApplicationContextPtr ApplicationInstance::GetAppContext(const std::string contextId) { + int ret = 0; + + LoggerD("contextId: %s", contextId.c_str()); + + std::string curCtxId = contextId; + int pid; + + if (curCtxId.empty()) { + pid = getppid(); + std::stringstream sstr; + sstr << pid; + curCtxId = sstr.str(); + } + else { + std::stringstream(contextId) >> pid; + if (pid <= 0) { + LoggerE("Given contextId is wrong"); + throw NotFoundException("Given contextId is wrong"); + } + } + + char *app_id = NULL; + LoggerD("pid: %d", pid); + + ret = app_manager_get_app_id(pid, &app_id); + if (ret != APP_MANAGER_ERROR_NONE) { + if (app_id) { + free(app_id); + } + switch (ret) { + case APP_MANAGER_ERROR_INVALID_PARAMETER: + LoggerE("app_manager_get_app_id error : invalid parameter"); + throw NotFoundException("app_manager_get_app_id error : invalid parameter"); + case APP_MANAGER_ERROR_NO_SUCH_APP: + LoggerE("app_manager_get_app_id error : no such app"); + throw NotFoundException("app_manager_get_app_id error : no such app"); + case APP_MANAGER_ERROR_DB_FAILED: + LoggerE("app_manager_get_app_id error : db failed"); + throw NotFoundException("app_manager_get_app_id error : db failed"); + case APP_MANAGER_ERROR_OUT_OF_MEMORY: + LoggerE("app_manager_get_app_id error : out of memory"); + throw NotFoundException("app_manager_get_app_id error : out of memory"); + default: + LoggerE("app_manager_get_app_id error"); + throw UnknownException("app_manager_get_app_id error : unknown error"); + } + } + + ApplicationContextPtr appContext(new ApplicationContext()); + appContext->set_app_id(app_id); + appContext->set_context_id(curCtxId); + + if(app_id) + free(app_id); + + return appContext; +} + +std::string ApplicationInstance::GetAppSharedURI(const std::string app_id) { + +#define TIZENAPIS_APP_FILE_SCHEME "file://" +#define TIZENAPIS_APP_SLASH "/" +#define TIZENAPIS_APP_SHARED "shared" + + app_info_h handle; + char* pkg_name = NULL; + + int ret = app_manager_get_app_info(app_id.c_str(), &handle); + if (ret != APP_ERROR_NONE) { + LoggerD("Fail to get appinfo"); + throw NotFoundException("Fail to get appinfo"); + } + + ret = app_info_get_package(handle, &pkg_name); + if ((ret != APP_ERROR_NONE) || (pkg_name == NULL)) { + LoggerD("Fail to get pkg_name"); + throw NotFoundException("Fail to get pkg_name"); + } + + app_info_destroy(handle); + + pkgmgrinfo_pkginfo_h pkginfo_h; + char* root_path = NULL; + + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkg_name, &pkginfo_h); + if (ret != PMINFO_R_OK) { + free(pkg_name); + throw UnknownException("Fail to get pkginfo"); + } + + ret = pkgmgrinfo_pkginfo_get_root_path(pkginfo_h, &root_path); + if ((ret != PMINFO_R_OK) || (root_path == NULL)) { + LoggerE("Fail to get root path"); + free(pkg_name); + throw UnknownException("Fail to get root path"); + } + + std::string sharedURI = TIZENAPIS_APP_FILE_SCHEME + std::string(root_path) + TIZENAPIS_APP_SLASH + TIZENAPIS_APP_SHARED + TIZENAPIS_APP_SLASH; + free(pkg_name); + + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + + return sharedURI; +} + +int ApplicationInstance::AddAppInfoEventListener(const int& callback_id) { + + if (manager_handle_ != NULL) { + LoggerD("AppListChanged callback is already registered. watch_id_ = %d", watch_id_); + throw UnknownException("Listener is already registered."); + } + LoggerD("pkgmgr_client_new() ----1----"); + manager_handle_ = pkgmgr_client_new(PC_LISTENING); + LoggerD("pkgmgr_client_new() ----2----"); + if (manager_handle_ == NULL) { + throw UnknownException("Error while registering listener to pkgmgr"); + } + + pkgmgr_client_listen_status(manager_handle_, app_list_changed_cb, this); + + callback_id_list_.push_back(callback_id); + return get_watch_id_and_increase(); +} +int ApplicationInstance::app_list_changed_cb(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data) +{ + static app_info_event_e event_type; + + LoggerD("ENTERED"); + + // pre-process + if (!strcasecmp(key, "start")) { + if (!strcasecmp(val, "install")) { + LoggerD("start: install"); + event_type = APP_INFO_EVENT_INSTALLED; + } else if (!strcasecmp(val, "uninstall")) { + // After uninstallation, we cannot get app ids from package name. + // So, we have to store app ids which is included to target package. + LoggerD("start: uninstall"); + package_info_h package_info; + + int ret = package_info_create(package, &package_info); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + LoggerE("Cannot create package info"); + } + + ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, app_callback, data); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + LoggerE("failed while getting appids"); + } + ret = package_info_destroy(package_info); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + LoggerE("Cannot destroy package info"); + } + event_type = APP_INFO_EVENT_UNINSTALLED; + } else if (!strcasecmp(val, "update")) { + LoggerD("start: update"); + event_type = APP_INFO_EVENT_UPDATED; + } + // post-process + } else if (!strcasecmp(key, "end") && !strcasecmp(val, "ok")) { + if (event_type >= 0) { + if (data != NULL) { + LoggerD("end & ok is called: package = %s", package); + ApplicationInstance* app_instance = (ApplicationInstance*)data; + app_instance->ReplyAppListChangedCallback(event_type, package, data); + } + } + } + + return APP_MANAGER_ERROR_NONE; +} + +bool ApplicationInstance::app_callback(package_info_app_component_type_e comp_type, const char *app_id, void *user_data) +{ + LoggerD("ENTERED"); + + if(app_id == NULL) { + LoggerE("Callback is called. but no package name is passed. skip this request"); + return true; + } + + if(user_data == NULL) { + LoggerE("user data is not exist. skip this request"); + return true; + } + + LoggerD("app_id = %s", app_id); + ApplicationInstance* app_instance = (ApplicationInstance*)user_data; + app_instance->app_list_.push_back(app_id); + + return true; +} + +void ApplicationInstance::ReplyAppListChangedCallback(app_info_event_e event_type, const char* pkg_id, void* user_data) { + LoggerD("ENTERED"); + + ApplicationInstance* app_instance = (ApplicationInstance*)user_data; + + if (event_type == APP_INFO_EVENT_UNINSTALLED) { + for (size_t i = 0; i < app_list_.size(); i++) { + + // onuninstalled + LoggerD("onuninstalled: %d of %d", i, app_list_.size()); + std::string app_id = app_list_.at(i); + + for (size_t j = 0; j < callback_id_list_.size(); j++) { + int callback_id = callback_id_list_.at(j); + LoggerD("%d th callback_id(%d) of %d", j, callback_id, callback_id_list_.size()); + picojson::object data; + data.insert(std::make_pair("type", picojson::value("onuninstalled"))); + data.insert(std::make_pair("id", picojson::value(app_id))); + ReplyAsync(this, ApplicationManagerAddappinfoeventlistenerCallback, + callback_id, true, data, 0, NULL); + } + } + } else { + package_info_h package_info; + + int ret = package_info_create(pkg_id, &package_info); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + LoggerE("Cannot create package info"); + return; + } + + // app_callback is called immediately + ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, app_callback, user_data); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + LoggerE("failed while getting appids"); + package_info_destroy(package_info); + return; + } + + ret = package_info_destroy(package_info); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + LoggerE("Cannot destroy package info"); + } + + for (size_t i = 0; i < app_list_.size(); i++) { + switch(event_type) { + case APP_INFO_EVENT_INSTALLED: + { + // oninstalled + LoggerD("oninstalled: %d of %d", i, app_list_.size()); + std::string app_id = app_list_.at(i); + + ApplicationInformationPtr app_info_ptr = GetAppInfo(app_id); + + for (size_t j = 0; j < callback_id_list_.size(); j++) { + int callback_id = callback_id_list_.at(j); + LoggerD("%d th callback_id(%d) of %d", j, callback_id, callback_id_list_.size()); + picojson::object data; + data.insert(std::make_pair("type", picojson::value("oninstalled"))); + data.insert(std::make_pair("info", picojson::value(app_info_ptr->Value()))); + ReplyAsync(this, ApplicationManagerAddappinfoeventlistenerCallback, + callback_id, true, data, 0, NULL); + } + } + break; + case APP_INFO_EVENT_UPDATED: + { + // onupdated + LoggerD("onupdated: %d of %d", i, app_list_.size()); + std::string app_id = app_list_.at(i); + + ApplicationInformationPtr app_info_ptr = GetAppInfo(app_id); + + for (size_t j = 0; j < callback_id_list_.size(); j++) { + int callback_id = callback_id_list_.at(j); + LoggerD("%d th callback_id(%d) of %d", j, callback_id, callback_id_list_.size()); + picojson::object data; + data.insert(std::make_pair("type", picojson::value("onupdated"))); + data.insert(std::make_pair("info", picojson::value(app_info_ptr->Value()))); + ReplyAsync(this, ApplicationManagerAddappinfoeventlistenerCallback, + callback_id, true, data, 0, NULL); + } + } + break; + default: + LoggerE("app_manager listener gave wrong event_type"); + break; + } + } + } + + // clean-up applist + app_list_.clear(); +} + +void ApplicationInstance::RemoveAppInfoEventListener(long watch_id) { + LoggerD("RemoveAppInfoEventListener called. watch_id = %d", watch_id); + + if (manager_handle_ == NULL) { + LoggerE("Listener is not added before."); + throw UnknownException("Listener is not added before."); + } + + callback_id_list_.clear(); + + if (watch_id_ != watch_id) { + LoggerE("Invalid watch id: %d", watch_id); + throw InvalidValuesException("Watch id is invalid."); + } + + pkgmgr_client_free(manager_handle_); + manager_handle_ = NULL; +} + + + +int ApplicationInstance::GetAppInstalledSize(const std::string &app_id) { + LoggerD("Get app size: %s", app_id.c_str()); + char* package_id = NULL; + int size = 0; + int ret = 0; + + ret = package_manager_get_package_id_by_app_id(app_id.c_str(), &package_id); + if ((ret != PACKAGE_MANAGER_ERROR_NONE) || (package_id == NULL)) { + LoggerE("Failed to get package id(%s)", package_id); + } else { + // get installed size from package server (to solve smack issue) + pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST); + if (pc == NULL) { + LoggerE("Failed to create pkgmgr client"); + } else { + size = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, pc, NULL, package_id, NULL, NULL, NULL); + if (size < 0) { + LoggerE("Failed to get installed size"); + } + pkgmgr_client_free(pc); + pc = NULL; + } + + if (package_id) { + free(package_id); + } + } + return size; +} + +int ApplicationInstance::get_installed_size() { + return installed_size_; +} + +void ApplicationInstance::set_installed_size(const int &installed_size) { + LoggerD("app size: installed_size: %d", installed_size); + installed_size_ = installed_size; +} + +int ApplicationInstance::get_watch_id_and_increase() { + return ++watch_id_; +} +#undef CHECK_EXIST + +} // namespace application +} // namespace extension diff --git a/src/application/application_instance.h b/src/application/application_instance.h new file mode 100644 index 00000000..0ab08e7a --- /dev/null +++ b/src/application/application_instance.h @@ -0,0 +1,79 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APPLICATION_APPLICATION_INSTANCE_H_ +#define APPLICATION_APPLICATION_INSTANCE_H_ + +#include "common/extension.h" + +#include +#include + +#include +#include +#include + +#include "application.h" +#include "application_context.h" + +namespace extension { +namespace application { + +class ApplicationInstance + : public common::ParsedInstance { + public: + ApplicationInstance(const std::string& app_id); + virtual ~ApplicationInstance(); + + private: + + void ApplicationManagerGetcurrentapplication(const picojson::value& args, picojson::object& out); + void ApplicationManagerKill(const picojson::value& args, picojson::object& out); + void ApplicationManagerLaunch(const picojson::value& args, picojson::object& out); + void ApplicationManagerLaunchappcontrol(const picojson::value& args, picojson::object& out); + void ApplicationManagerFindappcontrol(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappscontext(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappcontext(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappsinfo(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappinfo(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappcerts(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappshareduri(const picojson::value& args, picojson::object& out); + void ApplicationManagerGetappmetadata(const picojson::value& args, picojson::object& out); + void ApplicationManagerAddappinfoeventlistener(const picojson::value& args, picojson::object& out); + void ApplicationManagerRemoveappinfoeventlistener(const picojson::value& args, picojson::object& out); + void ApplicationExit(const picojson::value& args, picojson::object& out); + void ApplicationHide(const picojson::value& args, picojson::object& out); + void ApplicationGetrequestedappcontrol(const picojson::value& args, picojson::object& out); + void RequestedApplicationControlReplyresult(const picojson::value& args, picojson::object& out); + void RequestedApplicationControlReplyfailure(const picojson::value& args, picojson::object& out); + + ApplicationPtr GetCurrentApplication(const std::string app_id); + ApplicationInformationPtr GetAppInfo(const std::string app_id); + void Kill(const std::string contextId, int callbackId); + void Launch(const std::string appId, int callbackId); + ApplicationContextPtr GetAppContext(const std::string contextId); + std::string GetAppSharedURI(std::string app_id); + int AddAppInfoEventListener(const int& callback_id); + static bool app_callback(package_info_app_component_type_e comp_type, const char *app_id, void *user_data); + static int app_list_changed_cb(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data); + void ReplyAppListChangedCallback(app_info_event_e event_type, const char *pkg_id, void *user_data); + void RemoveAppInfoEventListener(long watch_id); + int GetAppInstalledSize(const std::string& app_id); + + int get_installed_size(); + void set_installed_size(const int &installed_size); + int get_watch_id_and_increase(); + + std::string app_id_; + int installed_size_; + pkgmgr_client* manager_handle_; + std::vector callback_id_list_; + int watch_id_; + std::vector app_list_; +}; + +} // namespace application +} // namespace extension + +#endif // APPLICATION_APPLICATION_INSTANCE_H_ diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 59feb6a7..b0c130e2 100644 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -9,6 +9,7 @@ 'type': 'none', 'dependencies': [ 'tizen/tizen.gyp:*', + 'application/application.gyp:*', 'time/time.gyp:*', 'utils/utils.gyp:*', 'messageport/messageport.gyp:*',