Modify logic related with setting refresh 46/128746/6
authorSeungha Son <seungha.son@samsung.com>
Thu, 11 May 2017 07:47:57 +0000 (16:47 +0900)
committerSeungha Son <seungha.son@samsung.com>
Mon, 15 May 2017 00:29:47 +0000 (09:29 +0900)
 If an application wants to get a notification_setting_h by using appid,
 the response time will be longer if DB data is not created.
 If the information is not in DB data, it shortens response time
 by sending initialized setting handle.

Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: Ie131b6d93309560c395d50f9b90921b2e41f7cfd

src/notification_service.c

index 30fc09d..de7796e 100755 (executable)
@@ -886,20 +886,64 @@ int notification_get_setting_array(GVariant *parameters, GVariant **reply_body,
        return ret;
 }
 
+static bool __init_setting_handle_by_appid(const char *appid, notification_setting_h *setting, uid_t uid)
+{
+       bool ret = false;
+       int ret_pkgmgr;
+       char *pkgname = NULL;
+       notification_setting_h ret_setting = NULL;
+       pkgmgrinfo_appinfo_h handle = NULL;
+
+       if (appid == NULL || setting == NULL)
+               return false;
+
+       ret_pkgmgr = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret_pkgmgr != PMINFO_R_OK) {
+               ErrPrint("failed to pkgmgrinfo_appinfo_get_appinfo [%s][%d]", appid, ret);
+               goto out;
+       }
+
+       ret_pkgmgr = pkgmgrinfo_appinfo_get_pkgname(handle, &pkgname);
+       if (ret_pkgmgr != PMINFO_R_OK) {
+               ErrPrint("failed to pkgmgrinfo_appinfo_get_pkgname [%s][%d]", appid, ret);
+               goto out;
+       }
+
+       ret_setting = (struct notification_setting *)malloc(sizeof(struct notification_setting));
+       if (ret_setting == NULL) {
+               ErrPrint("failed to alloc memory");
+               goto out;
+       }
+
+       ret_setting->package_name = strdup(pkgname);
+       ret_setting->appid = strdup(appid);
+       ret_setting->allow_to_notify = 1;
+       ret_setting->do_not_disturb_except = 0;
+       ret_setting->visibility_class = 0;
+       ret_setting->pop_up_notification = 1;
+       ret_setting->lock_screen_content_level = 0;
+       ret_setting->app_disabled = 0;
+
+       *setting = ret_setting;
+       ret = true;
+
+out:
+       if (handle)
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+       return ret;
+}
+
 /* get_setting_by_appid */
 int notification_get_setting_by_appid(GVariant *parameters, GVariant **reply_body, uid_t uid)
 {
+       bool err;
        int ret;
        GVariant *body;
        char *appid = NULL;
        notification_setting_h setting = NULL;
        uid_t param_uid;
 
-       if (need_to_reload_pkginfo_for_notification) {
-               notification_setting_refresh_setting_table(tzplatform_getuid(TZ_SYS_DEFAULT_USER));
-               need_to_reload_pkginfo_for_notification = 0;
-       }
-
        g_variant_get(parameters, "(&si)", &appid, &param_uid);
        ret = _validate_and_set_param_uid_with_uid(uid, &param_uid);
        if (ret != NOTIFICATION_ERROR_NONE)
@@ -907,23 +951,28 @@ int notification_get_setting_by_appid(GVariant *parameters, GVariant **reply_bod
        DbgPrint("get setting by appid : %s uid : %d", appid, param_uid);
 
        ret = noti_setting_service_get_setting_by_appid(appid, &setting, param_uid);
-       if (ret == NOTIFICATION_ERROR_NONE) {
-               body = notification_ipc_make_gvariant_from_setting(setting);
-               notification_setting_free_notification(setting);
-
-               if (body == NULL) {
-                       ErrPrint("fail to make gvariant");
-                       return NOTIFICATION_ERROR_OUT_OF_MEMORY;
-               }
-       } else {
+       if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID) {
+               err = __init_setting_handle_by_appid(appid, &setting, param_uid);
+               if (err == false)
+                       return NOTIFICATION_ERROR_IO_ERROR;
+               ret = NOTIFICATION_ERROR_NONE;
+       } else if (ret != NOTIFICATION_ERROR_NONE) {
                return ret;
        }
 
+       body = notification_ipc_make_gvariant_from_setting(setting);
+       notification_setting_free_notification(setting);
+       if (body == NULL) {
+               ErrPrint("fail to make gvariant");
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
        *reply_body = g_variant_new("(v)", body);
        if (*reply_body == NULL) {
                ErrPrint("cannot make reply_body");
                return NOTIFICATION_ERROR_OUT_OF_MEMORY;
        }
+
        return ret;
 }