Do not wait for complete event when uninstall app 24/70424/2
authorKyungwook Tak <k.tak@samsung.com>
Thu, 19 May 2016 07:52:49 +0000 (16:52 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Thu, 19 May 2016 08:59:59 +0000 (17:59 +0900)
Sometimes timeout callback behaves undefine way.
Even though pkgmgr_client_uninstall API returns success and it's
uninstalled really on pkgmgr server side but timeout callback runs
immediately several times on csr server side.

So we just believe pkgmgr_client_uninstall returned value. Other pkgmgr
client API users(settings, homescreen, menubar, etc.) uses it like
this(without g_main_loop and end callback).

Change-Id: I5e5b0894303752ae33bb3e9e4f7232d8e79f2cb4
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
packaging/csr-framework.spec
src/CMakeLists.txt
src/framework/service/app-deleter.cpp
test/internals/test-file-system.cpp
test/test-api-content-screening.cpp
test/test-common.h

index 49d4969..85c40d2 100644 (file)
@@ -13,7 +13,6 @@ BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(pkgmgr)
-BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(libsmack)
 Requires:      lib%{name}-common = %{version}-%{release}
 %{?systemd_requires}
index 67d0c27..0a09e47 100755 (executable)
@@ -22,7 +22,6 @@ PKG_CHECK_MODULES(${TARGET_CSR_SERVER}_DEP
        REQUIRED
        libsystemd-daemon
        sqlite3
-       glib-2.0
        pkgmgr
        libsmack
 )
index d5a78f5..83b99c7 100644 (file)
 #include <memory>
 #include <cstring>
 
-#include <glib.h>
 #include <package-manager.h>
 
 #include "common/audit/logger.h"
 #include "service/exception.h"
 
-#define MAX_WAIT_SEC 10
-
-namespace {
-
-struct LoopData {
-       bool isDeleted;
-       GMainLoop *loop;
-       const std::string &pkgid;
-
-       explicit LoopData(GMainLoop *_loop, const std::string &_pkgid) :
-               isDeleted(false), loop(_loop), pkgid(_pkgid) {}
-};
-
-void setRemoveResult(bool result, gpointer data)
-{
-       auto pdata = reinterpret_cast<LoopData *>(data);
-
-       pdata->isDeleted = result;
-       g_main_loop_quit(pdata->loop);
-}
-
-static int __app_uninstall_cb(int req_id, const char *pkg_type,
-                                                         const char *pkgid, const char *key,
-                                                         const char *val, const void *pmsg, void *data)
-{
-       (void) req_id;
-       (void) pkg_type;
-       (void) pkgid;
-       (void) pmsg;
-
-       DEBUG("__app_uninstall_cb called : " << pkgid << ":" << key << ":" << val);
-
-       if (key && strncmp(key, "end", strlen("end")) == 0)
-               setRemoveResult(strncmp(val, "ok", strlen("ok")) == 0, data);
-
-       return 0;
-}
-
-static gboolean __app_uninstall_timeout(gpointer data)
-{
-       ERROR("Package[" << reinterpret_cast<LoopData *>(data)->pkgid
-                 << "] remove timed out!");
-
-       setRemoveResult(false, data);
-
-       return FALSE;
-}
-
-} // namespace anonymous
-
 namespace Csr {
 
 void AppDeleter::remove(const std::string &pkgid)
@@ -90,28 +39,16 @@ void AppDeleter::remove(const std::string &pkgid)
        std::unique_ptr<pkgmgr_client, int(*)(pkgmgr_client *)> client(
                pkgmgr_client_new(PC_REQUEST), pkgmgr_client_free);
 
-       std::unique_ptr<GMainLoop, void(*)(GMainLoop *)> loop(
-               g_main_loop_new(nullptr, false), g_main_loop_unref);
-
-       if (!client || !loop)
+       if (!client)
                throw std::bad_alloc();
 
-       LoopData data(loop.get(), pkgid);
-
        auto ret = pkgmgr_client_uninstall(client.get(), nullptr, pkgid.c_str(), PM_QUIET,
-                                                                          ::__app_uninstall_cb, &data);
-       if (ret <= PKGMGR_R_OK)
+                                                                          nullptr, nullptr);
+       if (ret < PKGMGR_R_OK)
                ThrowExc(RemoveFailed, "Failed to pkgmgr_client_uninstall for pkg: " << pkgid <<
                                 " ret: " << ret);
 
-       g_timeout_add_seconds(MAX_WAIT_SEC, ::__app_uninstall_timeout, &data);
-
-       g_main_loop_run(loop.get());
-
-       if (data.isDeleted)
-               DEBUG("App Removed. pkgid: " << pkgid);
-       else
-               ThrowExc(RemoveFailed, "Failed to remove app: " << pkgid);
+       DEBUG("App Removed. pkgid: " << pkgid);
 }
 
 } // namespace Csr
index 013540f..17114e4 100644 (file)
@@ -30,7 +30,6 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <glib.h>
 
 #include <package-manager.h>
 #include <pkgmgr-info.h>
@@ -154,19 +153,12 @@ BOOST_AUTO_TEST_CASE(remove_app)
        EXCEPTION_GUARD_START
 
        Test::uninstall_app(TEST_TPK_PKG_ID);
-       // install the test app
        ASSERT_INSTALL_APP(TEST_TPK_PATH, TEST_TPK_TYPE);
 
-       // remove the app
        auto app = File::create(TEST_TPK_MAL_FILE);
        CHECK_IS_NOT_NULL(app);
        app->remove();
 
-       // check if the app still exists
-       pkgmgrinfo_pkginfo_h handle;
-       BOOST_REQUIRE(pkgmgrinfo_pkginfo_get_pkginfo(app->getAppPkgId().c_str(), &handle)
-                                 < PKGMGR_R_OK);
-
        EXCEPTION_GUARD_END
 }
 
index ea64171..bc5a359 100644 (file)
@@ -920,8 +920,6 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_remove_wgt)
 
        ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(Test::is_app_exist(TEST_WGT_PKG_ID), false);
-
        EXCEPTION_GUARD_END
 }
 
@@ -943,8 +941,6 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_remove_tpk)
 
        ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(Test::is_app_exist(TEST_TPK_PKG_ID), false);
-
        EXCEPTION_GUARD_END
 }
 
index 4a875b9..9101408 100644 (file)
@@ -105,7 +105,6 @@ void touch_file(const char *file);
 bool is_file_exist(const char *file);
 bool install_app(const char *app_path, const char *app_type);
 bool uninstall_app(const char *pkg_id);
-bool is_app_exist(const char *pkg_id);
 
 template <typename T>
 class Context {