// limitations under the License.
//
-#include <dlog.h>
#include <glib.h>
#include <JSTizenExceptionFactory.h>
#include "PackageManager.h"
#include "PackageInformation.h"
#include "JSPackageInformation.h"
+#include <Logger.h>
using namespace WrtDeviceApis::Commons;
using namespace WrtDeviceApis::CommonsJavaScript;
m_oninstalled = oninstalled;
m_onupdated = onupdated;
m_onuninstalled = onuninstalled;
+ m_handle_p = NULL;
}
PackageInfoEventCallback::~PackageInfoEventCallback()
return m_onuninstalled;
}
+pkgmgr_client** PackageInfoEventCallback::getEventHandler()
+{
+ return m_handle_p;
+}
+
+void PackageInfoEventCallback::setEventHandler(pkgmgr_client **handler)
+{
+ m_handle_p = handler;
+}
PackageInstallEventCallback::PackageInstallEventCallback(JSContextRef globalCtx, CallbackUserData* onprogress, CallbackUserData* oncomplete, CallbackUserData* onerror)
{
PackageInstallEventCallback::~PackageInstallEventCallback()
{
if (m_request_handle != NULL) {
- LogDebug("destroy client handle");
+ LoggerD("destroy client handle");
//package_manager_request_destroy(m_request_handle);
package_manager_client_destroy(m_request_handle);
}
static int get_current_pkg_id(char** pkg_id)
{
- LogDebug("get_current_pkg_id enter");
+ LoggerD("get_current_pkg_id enter");
int parent_pid = getppid();
- LogDebug("parent pid : " << parent_pid);
+ LoggerD("parent pid : " << parent_pid);
char* app_id = NULL;
app_info_h handle;
int ret = app_manager_get_app_id(parent_pid, &app_id);
if ((ret != APP_MANAGER_ERROR_NONE) || (app_id == NULL)) {
- LogDebug("Cannot get app id from pid : " << parent_pid);
+ LoggerD("Cannot get app id from pid : " << parent_pid);
return ret;
} else {
- LogDebug("app_id : " << app_id);
+ LoggerD("app_id : " << app_id);
}
ret = app_manager_get_app_info(app_id, &handle);
if (ret != APP_MANAGER_ERROR_NONE) {
- LogDebug("Fail to get appinfo by " << app_id);
+ LoggerD("Fail to get appinfo by " << app_id);
return ret;
}
ret = app_info_get_package(handle, pkg_id);
if ((ret != APP_MANAGER_ERROR_NONE) || (*pkg_id == NULL)) {
- LogDebug("Fail to get pkg_id by " << app_id);
+ LoggerD("Fail to get pkg_id by " << app_id);
return ret;
}
ret = app_info_destroy(handle);
if (ret != APP_MANAGER_ERROR_NONE) {
- LogDebug("Fail to get destory appinfo");
+ LoggerD("Fail to get destory appinfo");
return ret;
}
static bool app_callback(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
{
- //LogDebug("app_callback enter : " << app_id);
+ //LoggerD("app_callback enter : " << app_id);
PackageInformation* pkgInfo = (PackageInformation*)user_data;
pkgInfo->m_appIds.push_back(app_id);
return true;
static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
{
- //LogDebug("enter");
+ //LoggerD("enter");
PackageInformation *pkgInfo = new PackageInformation();
ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &id);
if ((ret != PMINFO_R_OK) || (id == NULL)) {
- LogDebug("Fail to get id. return NULL.");
+ LoggerD("Fail to get id. return NULL.");
delete pkgInfo;
return NULL;
} else {
ret = pkgmgrinfo_pkginfo_get_label(handle, &name);
if ((ret != PMINFO_R_OK) || (name == NULL)) {
- LogDebug("Fail to get labe");
+ LoggerD("Fail to get labe");
} else {
pkgInfo->m_name = name;
}
ret = pkgmgrinfo_pkginfo_get_icon(handle, &iconPath);
if ((ret != PMINFO_R_OK) || (iconPath == NULL)) {
- LogDebug("Fail to get iconPath");
+ LoggerD("Fail to get iconPath");
} else {
pkgInfo->m_iconPath = iconPath;
}
ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
if ((ret != PMINFO_R_OK) || (version == NULL)) {
- LogDebug("Fail to get version");
+ LoggerD("Fail to get version");
} else {
pkgInfo->m_version = version;
}
ret = pkgmgrinfo_pkginfo_get_total_size(handle, &totalSize);
if (ret != PMINFO_R_OK) {
- LogDebug("Fail to get totalSize");
+ LoggerD("Fail to get totalSize");
} else {
pkgInfo->m_totalSize = totalSize;
}
ret = pkgmgrinfo_pkginfo_get_data_size(handle, &dataSize);
if (ret != PMINFO_R_OK) {
- LogDebug("Fail to get dataSize");
+ LoggerD("Fail to get dataSize");
} else {
pkgInfo->m_dataSize = dataSize;
}
ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &lastModified);
if (ret != PMINFO_R_OK) {
- LogDebug("Fail to get lastModified");
+ LoggerD("Fail to get lastModified");
} else {
pkgInfo->m_lastModified = lastModified;
}
ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
if ((ret != PMINFO_R_OK) || (type == NULL)) {
- LogDebug("Fail to get type");
+ LoggerD("Fail to get type");
} else {
pkgInfo->m_type = type;
}
ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author);
if ((ret != PMINFO_R_OK) || (author == NULL)) {
- LogDebug("Fail to get author");
+ LoggerD("Fail to get author");
} else {
pkgInfo->m_author = author;
}
ret = pkgmgrinfo_pkginfo_get_description(handle, &description);
if ((ret != PMINFO_R_OK) || (description == NULL)) {
- LogDebug("Fail to get description");
+ LoggerD("Fail to get description");
} else {
pkgInfo->m_description = description;
}
ret = package_manager_get_package_info(id, &package_info);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogDebug("Cannot create package info by : " << id);
+ LoggerD("Cannot create package info by : " << id);
delete pkgInfo;
return NULL;
}
ret = package_info_foreach_app_from_package(package_info, PACKAGE_INFO_ALLAPP, app_callback, (void*)pkgInfo);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogDebug("failed while getting appids");
+ LoggerD("failed while getting appids");
}
ret = package_info_destroy(package_info);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogDebug("Cannot destroy package info");
+ LoggerD("Cannot destroy package info");
}
// REMARK: do not destroy handle. because handle is comes from outside!!
static gboolean getCompleteCB(void *data)
{
- LogDebug("entered");
+ LoggerD("entered");
PackageInfoCallbackData *callback = (PackageInfoCallbackData *)data;
JSContextRef context = callback->getContext();
callback->callSuccessCallback(jsResult);
} else {
- LogDebug("Fail!!");
+ LoggerD("Fail!!");
JSValueRef error = JSTizenExceptionFactory::makeErrorObject(callback->getContext(), JSTizenException::UNKNOWN_ERROR, "platform exception");
callback->callErrorCallback(error);
}
static int get_package_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
{
- //LogDebug("entered");
+ //LoggerD("entered");
PackageInfoCallbackData *callback = (PackageInfoCallbackData *)user_data;
PackageInformation* pkgInfo = create_pkg_info(handle);
if (pkgInfo != NULL) {
callback->addPackageInfo(*pkgInfo);
delete pkgInfo;
} else {
- LogError("Fail to get pkgInfo");
+ LoggerE("Fail to get pkgInfo");
}
return 0;
}
static void getThreadCB(void *data, Ecore_Thread *thread)
{
- LogDebug("entered");
+ LoggerD("entered");
PackageInfoCallbackData *callback = (PackageInfoCallbackData *)data;
int ret = pkgmgrinfo_pkginfo_get_list(get_package_list_cb, data);
if (ret != PMINFO_R_OK) {
- LogDebug("Fail to get package info");
+ LoggerD("Fail to get package info");
callback->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformException);
}
pkgmgrinfo_pkginfo_h handle;
int ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
if (ret != PMINFO_R_OK) {
- LogDebug("fail to find pkg info with given pkg : " << package);
+ LoggerD("fail to find pkg info with given pkg : " << package);
// Do not throw exception. No one can handle exception because this code is called from async callback.
//throw NotFoundException("Can't find given package");
break;
pkgmgrinfo_appinfo_destroy_appinfo(handle);
if (pkgInfo == NULL) {
- LogDebug("Fail to get pkg info. skip callback call for pkgid " << package);
+ LoggerD("Fail to get pkg info. skip callback call for pkgid " << package);
} else {
CallbackUserData *callback = eventCB->getOnInstalled();
if (callback) {
break;
}
case APP_MANAGER_EVENT_UNINSTALLED: {
- LogDebug("uninstall : " << package);
+ LoggerD("uninstall : " << package);
CallbackUserData *callback = eventCB->getOnUninstalled();
if (callback) {
Converter converter(callback->getContext());
pkgmgrinfo_appinfo_destroy_appinfo(handle);
if (pkgInfo == NULL) {
- LogDebug("Fail to get pkg info. skip callback call for pkgid " << package);
+ LoggerD("Fail to get pkg info. skip callback call for pkgid " << package);
} else {
CallbackUserData *callback = eventCB->getOnUpdated();
if (callback) {
break;
}
default:
- LogDebug("Fail!! Unknown event type is entered : " << event_type);
+ LoggerD("Fail!! Unknown event type is entered : " << event_type);
break;
}
if (!strcasecmp(key, "start"))
{
+ LoggerD("start ");
if (!strcasecmp(val, "install"))
{
event_type = APP_MANAGER_EVENT_INSTALLED;
}
else if (!strcasecmp(key, "end") && !strcasecmp(val, "ok"))
{
+ LoggerD("end ");
if (event_type >= 0)
{
package_event_cb(event_type, package, data);
+
+ // Check whether handler is freed in the callback function or not.
+ // if freed, return error code to avoid iteration of callback function. (core platform side)
+ PackageInfoEventCallback * callback = (PackageInfoEventCallback *)data;
+ pkgmgr_client ** handler_p = callback->getEventHandler();
+ if (*handler_p == NULL) {
+ LoggerD("handler is NULL");
+ return -1;
+ }
+ LoggerD("handler is not NULL");
}
}
- return APP_MANAGER_ERROR_NONE;
+ return 0;
}
package_manager_error_e error,
void *user_data)
{
- LogDebug("install_request_cb ");
+ LoggerD("install_request_cb ");
PackageInstallEventCallback *callback = (PackageInstallEventCallback *)user_data;
JSContextRef context = callback->getContext();;
callback->getOnComplete()->callSuccessCallback(converter.toJSValueRef(package));
}
- LogDebug("destroy client handle");
+ LoggerD("destroy client handle");
// this api is not supported from platform.
//package_manager_request_destroy(callback->getHandle());
package_manager_client_destroy(callback->getHandle());
callback->getOnError()->callSuccessCallback(jsError);
}
- LogDebug("destroy client handle");
+ LoggerD("destroy client handle");
// this api is not supported from platform.
//package_manager_request_destroy(callback->getHandle());
package_manager_client_destroy(callback->getHandle());
if (callback->getOnError()) {
callback->getOnError()->callSuccessCallback(error);
}
- LogDebug("destroy client handle");
+ LoggerD("destroy client handle");
// this api is not supported from platform.
//package_manager_request_destroy(callback->getHandle());
package_manager_client_destroy(callback->getHandle());
void PackageManager::install(string pkgPath, PackageInstallEventCallback* callback)
{
- LogDebug("install");
+ LoggerD("install");
int ret = 0;
int id = 0;
package_manager_request_h request_h;
ret = package_manager_request_install(request_h, pkgPath.c_str(), &id);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogDebug("error : " << pkgPath);
+ LoggerD("error : " << pkgPath);
if (errCallback) {
JSValueRef error =
JSTizenExceptionFactory::makeErrorObject(globalCtx, JSTizenException::NOT_FOUND_ERROR, "Not proper file");
void PackageManager::uninstall(string pkgPath, PackageInstallEventCallback* callback)
{
- LogDebug("uninstall");
+ LoggerD("uninstall");
int ret = 0;
int id = 0;
package_manager_request_h request_h;
ret = package_manager_request_uninstall(request_h, pkgPath.c_str(), &id);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogDebug("error : " << pkgPath);
+ LoggerD("error : " << pkgPath);
if (errCallback) {
JSValueRef error =
JSTizenExceptionFactory::makeErrorObject(globalCtx, JSTizenException::NOT_FOUND_ERROR, "Not proper file");
int ret = get_current_pkg_id(&pkg_id);
if((ret != APP_MANAGER_ERROR_NONE) || (pkg_id == NULL)) {
- LogError("Can not get app id from current pid (" << ret << ")");
+ LoggerE("Can not get app id from current pid (" << ret << ")");
throw NotFoundException("Can't find given package");
}
pkgId = pkg_id;
void PackageManager::getPackagesInfo(PackageInfoCallbackData *user_data)
{
- LogDebug("entered");
+ LoggerD("entered");
// getting info of all package from other thread. the result callback will be called on main thread
ecore_thread_run(getThreadCB, NULL, NULL, user_data);
void PackageManager::setPackageInfoEventListener(PackageInfoEventCallback * eventCB)
{
- LogDebug("enter");
+ LoggerD("enter");
if (m_manager_handle == NULL) {
m_manager_handle = pkgmgr_client_new(PC_LISTENING);
}
}
+ eventCB->setEventHandler(&m_manager_handle);
+
pkgmgr_client_listen_status(m_manager_handle, app_list_changed_cb_broker, eventCB);
}
void PackageManager::unsetPackageInfoEventListener()
{
- LogDebug("enter");
+ LoggerD("enter");
if (m_manager_handle == NULL) {
- LogDebug("no package manager handle registered");
+ LoggerD("no package manager handle registered");
return;
}
}
PackageManager* PackageManager::getInstance(){
- LogDebug("enter to getInstance()");
+ LoggerD("enter to getInstance()");
static PackageManager instance;
return &instance;
}
PackageManager::PackageManager()
{
- LogDebug("Create PackageManager");
+ LoggerD("Create PackageManager");
}
PackageManager::~PackageManager()
{
- LogDebug("Destroy PackageManager");
+ LoggerD("Destroy PackageManager");
if (m_manager_handle != NULL) {
pkgmgr_client_free(m_manager_handle);
#if 0
void PackageManager::move(string pkgPath, string target, PackageInstallEventCallback* callback)
{
- LogDebug("entered : " << pkgPath);
+ LoggerD("entered : " << pkgPath);
int ret = 0;
package_manager_move_type_e type = PACAKGE_MANAGER_REQUEST_MOVE_TO_INTERNAL;
bool PackageManager::isInstalled(string pkgId)
{
- LogDebug("pkgId = " << pkgId);
+ LoggerD("pkgId = " << pkgId);
package_info_h handle;
int ret = 0;
ret = package_manager_get_package_info(pkgId.c_str(), &handle);
if (ret == PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE) {
- LogError("No patched package: " << pkgId);
+ LoggerE("No patched package: " << pkgId);
return false;
} else if (ret == PACKAGE_MANAGER_ERROR_NONE) {
// TODO: Should I exception handling while destory handle? what should I do for that time?
string PackageManager::getPackageIdFromAppId(string appId)
{
- LogDebug("appId = " << appId);
+ LoggerD("appId = " << appId);
char *pkg_id = NULL;
string pkgId;
int ret = 0;
ret = package_manager_get_package_id_by_app_id(appId.c_str(), &pkg_id);
if (ret != PACKAGE_MANAGER_ERROR_NONE) {
- LogError("Error on get pkgId from appId : " << appId);
+ LoggerE("Error on get pkgId from appId : " << appId);
ThrowMsg(NotFoundException, "Not found pkg");
}