Improve package signal handling performance 08/182708/1
authorjusung son <jusung07.son@samsung.com>
Mon, 25 Jun 2018 11:11:36 +0000 (20:11 +0900)
committerjusung son <jusung07.son@samsung.com>
Wed, 27 Jun 2018 08:33:15 +0000 (08:33 +0000)
Change-Id: If3bae8e5e2f1e4ed8780da92e734f534b8844251
Signed-off-by: jusung son <jusung07.son@samsung.com>
(cherry picked from commit e24860bfd9d9896845cf9dc88aaf9d73c58bf490)

src/service_common.c

index 30547bb62cfff0de285eb2bcc9492f64eec0b4be..ed937688572019a1f584272d9e7fd738c922a7e5 100755 (executable)
@@ -27,6 +27,7 @@
 #include <badge_db.h>
 #include <package-manager.h>
 #include <tzplatform_config.h>
+#include <pkgmgr-info.h>
 
 #include "debug.h"
 #include "pkgmgr.h"
@@ -43,6 +44,8 @@
 #define PROVIDER_OBJECT_PATH "/org/tizen/data_provider_service"
 
 static GDBusConnection *_gdbus_conn = NULL;
+static GHashTable *_noti_pkg_privilege_info;
+static GHashTable *_badge_pkg_privilege_info;
 
 uid_t get_sender_uid(const char *sender_name)
 {
@@ -421,11 +424,42 @@ out:
 
 static int _package_install_cb(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data)
 {
-       if (status == PKGMGR_STATUS_END) {
-               if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
-                       uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
-               notification_setting_insert_package_for_uid(pkgname, uid);
-               badge_setting_insert_package_for_uid(pkgname, uid);
+       int ret;
+       gpointer tmp;
+       int privilege_info;
+
+       if (status != PKGMGR_STATUS_END)
+               return 0;
+
+       if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
+               uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+
+       if (g_hash_table_contains(_noti_pkg_privilege_info, pkgname)) {
+               tmp = g_hash_table_lookup(_noti_pkg_privilege_info, pkgname);
+               privilege_info = GPOINTER_TO_UINT(tmp);
+               if (privilege_info == 1)
+                       notification_setting_db_update_pkg_disabled(pkgname, false, uid);
+
+               g_hash_table_remove(_noti_pkg_privilege_info, pkgname);
+       } else {
+               /* In consideration of the reboot status, change the disable information. */
+               ret = notification_setting_db_update_pkg_disabled(pkgname, false, uid);
+               if (ret != NOTIFICATION_ERROR_NONE)
+                       notification_setting_insert_package_for_uid(pkgname, uid);
+       }
+
+       if (g_hash_table_contains(_badge_pkg_privilege_info, pkgname)) {
+               tmp = g_hash_table_lookup(_badge_pkg_privilege_info, pkgname);
+               privilege_info = GPOINTER_TO_UINT(tmp);
+               if (privilege_info == 1)
+                        badge_db_update_pkg_disabled(pkgname, false, uid);
+
+               g_hash_table_remove(_badge_pkg_privilege_info, pkgname);
+       } else {
+               /* In consideration of the reboot status, change the disable information. */
+               ret = badge_db_update_pkg_disabled(pkgname, false, uid);
+               if (ret != BADGE_ERROR_NONE)
+                       badge_setting_insert_package_for_uid(pkgname, uid);
        }
 
        return 0;
@@ -433,9 +467,36 @@ static int _package_install_cb(uid_t uid, const char *pkgname, enum pkgmgr_statu
 
 static int _package_uninstall_cb(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data)
 {
-       if (status == PKGMGR_STATUS_END) {
-               if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
-                       uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+       int ret;
+       pkgmgrinfo_pkginfo_h pkginfo;
+
+       if (status != PKGMGR_STATUS_END)
+               return 0;
+
+       if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
+               uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+
+       ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgname, uid, &pkginfo);
+       if (ret == PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+
+               if (_noti_pkg_privilege_info == NULL) {
+                       _noti_pkg_privilege_info = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+                       _badge_pkg_privilege_info = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+               }
+
+               ret = notification_setting_db_update_pkg_disabled(pkgname, true, uid);
+               if (ret == NOTIFICATION_ERROR_NONE)
+                       g_hash_table_insert(_noti_pkg_privilege_info, strdup(pkgname), GUINT_TO_POINTER(1));
+               else
+                       g_hash_table_insert(_noti_pkg_privilege_info, strdup(pkgname), GUINT_TO_POINTER(0));
+
+               ret = badge_db_update_pkg_disabled(pkgname, true, uid);
+               if (ret == BADGE_ERROR_NONE)
+                       g_hash_table_insert(_badge_pkg_privilege_info, strdup(pkgname), GUINT_TO_POINTER(1));
+               else
+                       g_hash_table_insert(_badge_pkg_privilege_info, strdup(pkgname), GUINT_TO_POINTER(0));
+       } else {
                notification_setting_delete_package_for_uid(pkgname, uid);
                badge_db_delete_by_pkgname(pkgname, uid);
                badge_setting_delete_package_for_uid(pkgname, uid);