Update change log and spec for wrt-plugins-tizen_0.4.25-1
[platform/framework/web/wrt-plugins-tizen.git] / src / Package / PackageManager.cpp
index 5cb5fca..91813ce 100644 (file)
@@ -15,7 +15,6 @@
 // limitations under the License.
 //
 
-#include <dlog.h>
 #include <glib.h>
 
 #include <JSTizenExceptionFactory.h>
@@ -39,6 +38,7 @@
 #include "PackageManager.h"
 #include "PackageInformation.h"
 #include "JSPackageInformation.h"
+#include <Logger.h>
 
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
@@ -93,6 +93,7 @@ PackageInfoEventCallback::PackageInfoEventCallback(CallbackUserData* oninstalled
        m_oninstalled = oninstalled;
        m_onupdated = onupdated;
        m_onuninstalled = onuninstalled;
+       m_handle_p = NULL;
 }
 
 PackageInfoEventCallback::~PackageInfoEventCallback()
@@ -122,6 +123,15 @@ CallbackUserData* PackageInfoEventCallback::getOnUninstalled()
        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)
 {
@@ -136,7 +146,6 @@ PackageInstallEventCallback::PackageInstallEventCallback(JSContextRef globalCtx,
 PackageInstallEventCallback::~PackageInstallEventCallback()
 {
        if (m_request_handle != NULL) {
-               LogDebug("destroy client handle");
                //package_manager_request_destroy(m_request_handle);
                package_manager_client_destroy(m_request_handle);
        }
@@ -183,35 +192,25 @@ package_manager_request_h PackageInstallEventCallback::getHandle()
 
 static int get_current_pkg_id(char** pkg_id)
 {
-       LogDebug("get_current_pkg_id enter");
-       int parent_pid = getppid();
-       LogDebug("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);
-               return ret;
-       } else {
-               LogDebug("app_id : " << app_id);
-       }
+       string appId = PackageManager::getInstance()->getCurrentAppId();
 
-       ret = app_manager_get_app_info(app_id, &handle);
+       int ret = app_manager_get_app_info(appId.c_str(), &handle);
        if (ret != APP_MANAGER_ERROR_NONE) {
-               LogDebug("Fail to get appinfo by " << app_id);
+               LoggerE("Fail to get appinfo");
                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);
+               LoggerE("Fail to get pkg_id");
                return ret;
        }
 
        ret = app_info_destroy(handle);
        if (ret != APP_MANAGER_ERROR_NONE) {
-               LogDebug("Fail to get destory appinfo");
+               LoggerE("Fail to get destory appinfo");
                return ret;
        }
 
@@ -220,7 +219,6 @@ static int get_current_pkg_id(char** pkg_id)
 
 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);
        PackageInformation* pkgInfo = (PackageInformation*)user_data;
        pkgInfo->m_appIds.push_back(app_id);
        return true;
@@ -228,8 +226,6 @@ static bool app_callback(package_info_app_component_type_e comp_type, const char
 
 static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
 {
-       //LogDebug("enter");
-
        PackageInformation *pkgInfo = new PackageInformation();
 
        char* id = NULL;
@@ -246,71 +242,73 @@ static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
        int ret = 0;
 
        ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &id);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get id");
+       if ((ret != PMINFO_R_OK) || (id == NULL)) {
+               LoggerE("Fail to get id. return NULL.");
+               delete pkgInfo;
+               return NULL;
        } else {
                pkgInfo->m_id = id;
        }
 
        ret = pkgmgrinfo_pkginfo_get_label(handle, &name);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get labe");
+       if ((ret != PMINFO_R_OK) || (name == NULL)) {
+               LoggerE("Fail to get labe");
        } else {
                pkgInfo->m_name = name;
        }
 
        ret = pkgmgrinfo_pkginfo_get_icon(handle, &iconPath);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get iconPath");
+       if ((ret != PMINFO_R_OK) || (iconPath == NULL)) {
+               LoggerE("Fail to get iconPath");
        } else {
                pkgInfo->m_iconPath = iconPath;
        }
 
        ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get version");
+       if ((ret != PMINFO_R_OK) || (version == NULL)) {
+               LoggerE("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");
+               LoggerE("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");
+               LoggerE("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");
+               LoggerE("Fail to get lastModified");
        } else {
                pkgInfo->m_lastModified = lastModified;
        }
 
        ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get type");
+       if ((ret != PMINFO_R_OK) || (type == NULL)) {
+               LoggerE("Fail to get type");
        } else {
                pkgInfo->m_type = type;
        }
 
        ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get author");
+       if ((ret != PMINFO_R_OK) || (author == NULL)) {
+               LoggerE("Fail to get author");
        } else {
                pkgInfo->m_author = author;
        }
 
        ret = pkgmgrinfo_pkginfo_get_description(handle, &description);
-       if (ret != PMINFO_R_OK) {
-               LogDebug("Fail to get description");
+       if ((ret != PMINFO_R_OK) || (description == NULL)) {
+               LoggerE("Fail to get description");
        } else {
                pkgInfo->m_description = description;
        }
@@ -319,17 +317,19 @@ static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
        
        ret = package_manager_get_package_info(id, &package_info);
        if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               LogDebug("Cannot create package info by : " << id);
+               LoggerE("Cannot create package info");
+               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");
+               LoggerE("failed while getting appids");
        }
 
        ret = package_info_destroy(package_info);
        if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               LogDebug("Cannot destroy package info");
+               LoggerE("Cannot destroy package info");
        }       
 
        // REMARK: do not destroy handle. because handle is comes from outside!!
@@ -338,8 +338,6 @@ static PackageInformation* create_pkg_info(pkgmgrinfo_pkginfo_h handle)
 
 static gboolean getCompleteCB(void *data)
 {
-       LogDebug("entered");
-
        PackageInfoCallbackData *callback = (PackageInfoCallbackData *)data;
        JSContextRef context = callback->getContext();
 
@@ -353,7 +351,7 @@ static gboolean getCompleteCB(void *data)
                        return false;
            }
 
-           for (std::size_t i = 0; i < pkgInfoList.size(); ++i) {
+           for (size_t i = 0; i < pkgInfoList.size(); ++i) {
                JSValueRef tmpVal = JSPackageInformation::createJSObject(context, &pkgInfoList[i]);
                if (!JSSetArrayElement(context, jsResult, i, tmpVal)) {
                                JSValueRef error = JSTizenExceptionFactory::makeErrorObject(callback->getContext(), JSTizenException::UNKNOWN_ERROR, "platform exception");
@@ -364,12 +362,10 @@ static gboolean getCompleteCB(void *data)
 
                callback->callSuccessCallback(jsResult);
        } else {
-               LogDebug("Fail!!");
                JSValueRef error = JSTizenExceptionFactory::makeErrorObject(callback->getContext(), JSTizenException::UNKNOWN_ERROR, "platform exception");
                callback->callErrorCallback(error);
        }
 
-       // TODO: cleanup each packageInformation items
     delete callback;
        
        return false;
@@ -377,27 +373,24 @@ static gboolean getCompleteCB(void *data)
 
 static int get_package_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
 {
-       //LogDebug("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");
-
        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");
+               LoggerE("Fail to get package info");
                callback->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformException);
        }
 
@@ -406,69 +399,113 @@ static void getThreadCB(void *data, Ecore_Thread *thread)
        g_idle_add(getCompleteCB, data);
 }
 
-static void package_event_cb(const char *type, const char *package,
-                       package_manager_event_type_e event_type,
-                       package_manager_event_state_e event_state,
-                       int progress,
-                       package_manager_error_e error,
-                       void *user_data)
-{
-       LogDebug("event callback is called!!! : event_state " << event_state << " : package " << package << " : event_type " << event_type );
-       if (event_state == PACAKGE_MANAGER_EVENT_STATE_COMPLETED) {
-               PackageInfoEventCallback *eventCB = (PackageInfoEventCallback *)user_data;
-
-               switch(event_type) {
-               case PACAKGE_MANAGER_EVENT_TYPE_INSTALL: {
-                       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);
-                               // 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;
-                       }
-
-                       PackageInformation* pkgInfo = create_pkg_info(handle);
-                       pkgmgrinfo_appinfo_destroy_appinfo(handle);
 
+static void package_event_cb(app_manger_event_type_e event_type, const char *package, void *user_data)
+{
+       PackageInfoEventCallback *eventCB = (PackageInfoEventCallback *)user_data;
+       
+       switch(event_type) {
+       case APP_MANAGER_EVENT_INSTALLED: {
+               pkgmgrinfo_pkginfo_h handle;
+               int ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
+               if (ret != PMINFO_R_OK) {
+                       LoggerE("fail to find pkg info with given pkg");
+                       // 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;
+               }
+       
+               PackageInformation* pkgInfo = create_pkg_info(handle);
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       
+               if (pkgInfo == NULL) {
+                       LoggerE("Fail to get pkg info. skip callback call");
+               } else {
                        CallbackUserData *callback = eventCB->getOnInstalled();
                        if (callback) {
                                callback->callSuccessCallback(JSPackageInformation::createJSObject(callback->getContext(), pkgInfo));
                        }
-                       break;
                }
-               case PACAKGE_MANAGER_EVENT_TYPE_UNINSTALL: {
-                       LogDebug("uninstall : " << package);
-                       CallbackUserData *callback = eventCB->getOnUninstalled();
-                       if (callback) {
-                               Converter converter(callback->getContext());
-                               callback->callSuccessCallback(converter.toJSValueRef(package));
-                       }
+               break;
+       }
+       case APP_MANAGER_EVENT_UNINSTALLED: {
+               CallbackUserData *callback = eventCB->getOnUninstalled();
+               if (callback) {
+                       Converter converter(callback->getContext());
+                       callback->callSuccessCallback(converter.toJSValueRef(package));
+               }
+               break;
+       }
+       case APP_MANAGER_EVENT_UPDATED: {
+               pkgmgrinfo_pkginfo_h handle;
+               int ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
+               if (ret != PMINFO_R_OK) {
+                       // 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;
                }
-               case PACAKGE_MANAGER_EVENT_TYPE_UPDATE: {
-                       pkgmgrinfo_pkginfo_h handle;
-                       int ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
-                       if (ret != PMINFO_R_OK) {
-                               // 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;
-                       }
-
-                       PackageInformation* pkgInfo = create_pkg_info(handle);
-                       pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
+       
+               PackageInformation* pkgInfo = create_pkg_info(handle);
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       
+               if (pkgInfo == NULL) {
+                       LoggerE("Fail to get pkg info. skip callback call");
+               } else {
                        CallbackUserData *callback = eventCB->getOnUpdated();
                        if (callback) {
                                callback->callSuccessCallback(JSPackageInformation::createJSObject(callback->getContext(), pkgInfo));
                        }
-                       break;
                }
-               default:
-                       LogDebug("Fail!! Unknown event type is entered : " << event_type);
-                       break;
+               break;
+       }
+       default:
+               LoggerE("Fail!! Unknown event type is entered : " << event_type);
+               break;
+       }
+
+       
+}
+
+static int app_list_changed_cb_broker(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data)
+{
+       static app_manger_event_type_e event_type;
+
+       if (!strcasecmp(key, "start"))
+       {
+               LoggerD("start ");
+               if (!strcasecmp(val, "install"))
+               {
+                       event_type = APP_MANAGER_EVENT_INSTALLED;
+               }
+               else if (!strcasecmp(val, "uninstall"))
+               {
+                       event_type = APP_MANAGER_EVENT_UNINSTALLED;
+               }
+               else if (!strcasecmp(val, "update"))
+               {
+                       event_type = APP_MANAGER_EVENT_UPDATED;
+               }
+       }
+       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) {
+                               LoggerE("handler is NULL");
+                               return -1;
+                       }
+                       LoggerE("handler is not NULL");
                }
        }
+
+       return 0;
 }
 
 
@@ -479,21 +516,21 @@ void install_request_cb(int id, const char *type, const char *package,
                                package_manager_error_e error,
                                void *user_data)
 {
-       LogDebug("install_request_cb ");
        PackageInstallEventCallback *callback = (PackageInstallEventCallback *)user_data;
        JSContextRef context = callback->getContext();;
 
        switch (event_state) {
        case PACAKGE_MANAGER_EVENT_STATE_COMPLETED: {
-               LogDebug("destroy client handle");
                if (callback->getOnComplete()) {
                        Converter converter(context);
                        callback->getOnComplete()->callSuccessCallback(converter.toJSValueRef(package));
                }
 
+               LoggerD("destroy client handle");
                // this api is not supported from platform.
                //package_manager_request_destroy(callback->getHandle());
                package_manager_client_destroy(callback->getHandle());
+               callback->setHandle(NULL);
 
                //clean-up callback object
                delete callback;
@@ -512,10 +549,11 @@ void install_request_cb(int id, const char *type, const char *package,
                        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());
+               callback->setHandle(NULL);
 
                //clean-up callback object
                delete callback;
@@ -536,10 +574,11 @@ void install_request_cb(int id, const char *type, const char *package,
                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());
+               callback->setHandle(NULL);
 
                //clean-up callback object
                delete callback;
@@ -551,7 +590,6 @@ void install_request_cb(int id, const char *type, const char *package,
 
 void PackageManager::install(string pkgPath, PackageInstallEventCallback* callback)
 {
-       LogDebug("install");
        int ret = 0;
        int id = 0;
        package_manager_request_h request_h;
@@ -565,17 +603,18 @@ void PackageManager::install(string pkgPath, PackageInstallEventCallback* callba
                                JSTizenExceptionFactory::makeErrorObject(globalCtx, JSTizenException::UNKNOWN_ERROR, "Platform Error");
                        errCallback->callSuccessCallback(error);
                }
+               delete callback;
                return;
        }
 
        ret = package_manager_request_install(request_h, pkgPath.c_str(), &id);
        if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               LogDebug("error : " << pkgPath);
                if (errCallback) {
                        JSValueRef error = 
                                JSTizenExceptionFactory::makeErrorObject(globalCtx, JSTizenException::NOT_FOUND_ERROR, "Not proper file");
                        errCallback->callSuccessCallback(error);
                }
+               delete callback;
                return;
        }
 
@@ -588,13 +627,13 @@ void PackageManager::install(string pkgPath, PackageInstallEventCallback* callba
                                JSTizenExceptionFactory::makeErrorObject(globalCtx, JSTizenException::UNKNOWN_ERROR, "Platform Error");
                        errCallback->callSuccessCallback(error);
                }
+               delete callback;
                return;
        }
 }
 
 void PackageManager::uninstall(string pkgPath, PackageInstallEventCallback* callback)
 {
-       LogDebug("uninstall");
        int ret = 0;
        int id = 0;
        package_manager_request_h request_h;
@@ -615,7 +654,6 @@ void PackageManager::uninstall(string pkgPath, PackageInstallEventCallback* call
 
        ret = package_manager_request_uninstall(request_h, pkgPath.c_str(), &id);
        if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               LogDebug("error : " << pkgPath);
                if (errCallback) {
                        JSValueRef error = 
                                JSTizenExceptionFactory::makeErrorObject(globalCtx, JSTizenException::NOT_FOUND_ERROR, "Not proper file");
@@ -650,7 +688,7 @@ PackageInformation* PackageManager::getPackageInfo(string pkgId)
 
                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");
                        throw NotFoundException("Can't find given package");
                }
                pkgId = pkg_id;
@@ -666,14 +704,16 @@ PackageInformation* PackageManager::getPackageInfo(string pkgId)
        PackageInformation* pkgInfo = create_pkg_info(handle);
        pkgmgrinfo_appinfo_destroy_appinfo(handle);
 
+       if (pkgInfo == NULL) {
+               throw UnknownException("Can't get pkg info from given package");
+       }
+
        return pkgInfo;
 }
 
 
 void PackageManager::getPackagesInfo(PackageInfoCallbackData *user_data)
 {
-       LogDebug("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);
 }
@@ -681,62 +721,56 @@ void PackageManager::getPackagesInfo(PackageInfoCallbackData *user_data)
 
 void PackageManager::setPackageInfoEventListener(PackageInfoEventCallback * eventCB)
 {
-       LogDebug("enter");
-       int ret = 0;
-
        if (m_manager_handle == NULL) {
-               ret = package_manager_create(&m_manager_handle);
-               if (ret != PACKAGE_MANAGER_ERROR_NONE) {
+               m_manager_handle = pkgmgr_client_new(PC_LISTENING);
+               if (m_manager_handle == NULL) {
                        throw UnknownException("Fail to create package manager handle");
                }
        }
-       
-       ret = package_manager_set_event_cb(m_manager_handle, package_event_cb, eventCB);
-       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               throw UnknownException("Fail to set event cb");
-       }
+
+       eventCB->setEventHandler(&m_manager_handle);
+
+       pkgmgr_client_listen_status(m_manager_handle, app_list_changed_cb_broker, eventCB);
 }
 
 void PackageManager::unsetPackageInfoEventListener()
 {
-       LogDebug("enter");
-       int ret = 0;
-
        if (m_manager_handle == NULL) {
-               LogDebug("no package manager handle registered");
+               LoggerE("no package manager handle registered");
                return;
        }
-       
-       ret = package_manager_unset_event_cb(m_manager_handle);
-       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               throw UnknownException("Fail to unset event cb");
-       }
 
-       ret = package_manager_destroy(m_manager_handle);
-       if (ret != PACKAGE_MANAGER_ERROR_NONE) {
-               throw UnknownException("Fail to destroy package manager handle");
-       } else {
-               m_manager_handle = NULL;
-       }
+       pkgmgr_client_free(m_manager_handle);
+       m_manager_handle = NULL;
 }
 
-PackageManager* PackageManager::getInstance(){
-       LogDebug("enter to getInstance()");
+PackageManager* PackageManager::getInstance()
+{
     static PackageManager instance;
     return &instance;
 }
 
+void PackageManager::setCurrentAppId(string appId)
+{
+       m_curr_app_id = appId;
+}
+
+string PackageManager::getCurrentAppId() const
+{
+       return m_curr_app_id;
+}
+
 PackageManager::PackageManager()
 {
-       LogDebug("Create PackageManager");
 }
 
 PackageManager::~PackageManager()
 {
-       LogDebug("Destroy PackageManager");
        if (m_manager_handle != NULL) {
-               package_manager_destroy(m_manager_handle);
-       }       
+               pkgmgr_client_free(m_manager_handle);
+               m_manager_handle = NULL;
+       }
+
 }
 
 
@@ -744,7 +778,6 @@ PackageManager::~PackageManager()
 #if 0
 void PackageManager::move(string pkgPath, string target, PackageInstallEventCallback* callback)
 {
-       LogDebug("entered : " << pkgPath);
        int ret = 0;
        package_manager_move_type_e type = PACAKGE_MANAGER_REQUEST_MOVE_TO_INTERNAL;
 
@@ -777,13 +810,11 @@ void PackageManager::move(string pkgPath, string target, PackageInstallEventCall
 
 bool PackageManager::isInstalled(string pkgId)
 {
-       LogDebug("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);
                return false;
        } else if (ret == PACKAGE_MANAGER_ERROR_NONE) {
                // TODO: Should I exception handling while destory handle? what should I do for that time?
@@ -796,14 +827,12 @@ bool PackageManager::isInstalled(string pkgId)
 
 string PackageManager::getPackageIdFromAppId(string appId)
 {
-       LogDebug("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);
                ThrowMsg(NotFoundException, "Not found pkg");
        }