Release version 0.24.14
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index 6a522f9..8ea2611 100644 (file)
@@ -96,7 +96,8 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
                return ret;
        }
 
-       if (!g_hash_table_size(list)) {
+       if (!g_hash_table_size(list) || !g_hash_table_lookup(list, appid) ||
+               ((application_x *)g_hash_table_lookup(list, appid))->package == NULL) {
                _LOGD("appinfo for [%s] is not existed for user [%d]",
                                appid, uid);
                g_hash_table_destroy(list);
@@ -111,13 +112,6 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        }
 
        info->app_info = (application_x *)g_hash_table_lookup(list, appid);
-       if (!info->app_info || !info->app_info->package) {
-               _LOGD("appinfo for [%s] is not existed for user [%d]",
-                               appid, uid);
-               g_hash_table_destroy(list);
-               free(info);
-               return PMINFO_R_ENOENT;
-       }
        info->locale = strdup(info->app_info->locale);
        if (!info->locale) {
                _LOGE("out of memory");
@@ -185,11 +179,32 @@ API int pkgmgrinfo_appinfo_get_disabled_appinfo(
                        appid, _getuid(), handle);
 }
 
+static char *__get_real_appid(const char *appid)
+{
+       char *str;
+       char *saveptr;
+       char *token;
+
+       str = strdup(appid);
+       if (str == NULL)
+               return NULL;
+
+       token = strtok_r(str, "::", &saveptr);
+       if (token == NULL)
+               return str;
+
+       LOGD("Real appid = %s", token);
+       token = strdup(token);
+       free(str);
+       return token;
+}
+
 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                pkgmgrinfo_appinfo_h *handle)
 {
        int ret;
        pkgmgrinfo_appinfo_filter_h filter;
+       char *real_appid;
 
        if (appid == NULL || handle == NULL) {
                LOGE("invalid parameter");
@@ -200,10 +215,18 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
        if (ret != PMINFO_R_OK)
                return ret;
 
+       real_appid = __get_real_appid(appid);
+       if (real_appid == NULL) {
+               LOGE("Out of memory");
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        ret = pkgmgrinfo_appinfo_filter_add_string(filter,
-                       PMINFO_APPINFO_PROP_APP_ID, appid);
+                       PMINFO_APPINFO_PROP_APP_ID, real_appid);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
+               free(real_appid);
                return PMINFO_R_ERROR;
        }
 
@@ -211,6 +234,7 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                        PMINFO_APPINFO_PROP_APP_DISABLE, false);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
+               free(real_appid);
                return PMINFO_R_ERROR;
        }
 
@@ -218,10 +242,12 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                        PMINFO_APPINFO_PROP_PKG_DISABLE, false);
        if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
+               free(real_appid);
                return PMINFO_R_ERROR;
        }
 
-       ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
+       ret = _pkgmgrinfo_get_appinfo(real_appid, uid, filter, handle);
+       free(real_appid);
        pkgmgrinfo_appinfo_filter_destroy(filter);
        return ret;
 }
@@ -430,6 +456,30 @@ static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
        return splashscreen;
 }
 
+static gpointer __copy_res_control(gconstpointer src, gpointer data)
+{
+       res_control_x *tmp = (res_control_x *)src;
+       res_control_x *res_control;
+
+       res_control = (res_control_x *)calloc(1, sizeof(res_control_x));
+       if (res_control == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->res_type)
+               res_control->res_type = strdup(tmp->res_type);
+       if (tmp->min_res_version)
+               res_control->min_res_version = strdup(tmp->min_res_version);
+       if (tmp->max_res_version)
+               res_control->max_res_version = strdup(tmp->max_res_version);
+       if (tmp->auto_close)
+               res_control->auto_close = strdup(tmp->auto_close);
+
+       return res_control;
+}
+
 static int _appinfo_copy_appinfo(
                application_x **application, application_x *data)
 {
@@ -582,6 +632,14 @@ static int _appinfo_copy_appinfo(
                return PMINFO_R_ERROR;
        }
 
+       ret = 0;
+       app_info->res_control = g_list_copy_deep(data->res_control, __copy_res_control, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
        *application = app_info;
 
        return PMINFO_R_OK;
@@ -1882,6 +1940,36 @@ API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_foreach_res_control(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_res_control_list_cb res_control_func,
+               void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(res_control_func == NULL, PMINFO_R_EINVAL,
+                       "Callback function is NULL");
+       int ret = -1;
+       res_control_x *res_control;
+       GList *tmp;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->res_control; tmp; tmp = tmp->next) {
+               res_control = (res_control_x *)tmp->data;
+               if (res_control == NULL)
+                       continue;
+               ret = res_control_func(res_control->res_type,
+                               res_control->min_res_version,
+                               res_control->max_res_version,
+                               res_control->auto_close,
+                               user_data);
+               if (ret < 0)
+                       break;
+       }
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_is_nodisplay(
                pkgmgrinfo_appinfo_h handle, bool *nodisplay)
 {
@@ -2236,6 +2324,24 @@ API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_light_user_switch_mode(
+               pkgmgrinfo_appinfo_h handle, char **mode)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info == NULL || mode == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (info->app_info == NULL || info->app_info->light_user_switch_mode == NULL)
+               return PMINFO_R_ERROR;
+
+       *mode = info->app_info->light_user_switch_mode;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
@@ -2311,8 +2417,10 @@ API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
         */
        link = g_slist_find_custom(filter->list,
                        (gconstpointer)node, __compare_func);
-       if (link)
+       if (link) {
+               _pkgmgrinfo_node_destroy(link->data);
                filter->list = g_slist_delete_link(filter->list, link);
+       }
        filter->list = g_slist_append(filter->list, (gpointer)node);
        return PMINFO_R_OK;
 
@@ -2361,8 +2469,10 @@ API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
         */
        link = g_slist_find_custom(filter->list,
                        (gconstpointer)node, __compare_func);
-       if (link)
+       if (link) {
+               _pkgmgrinfo_node_destroy(link->data);
                filter->list = g_slist_delete_link(filter->list, link);
+       }
        filter->list = g_slist_append(filter->list, (gpointer)node);
        return PMINFO_R_OK;
 
@@ -2404,8 +2514,10 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                node->value = strdup(value);
                link = g_slist_find_custom(filter->list,
                                (gconstpointer)node, __compare_func);
-               if (link)
+               if (link) {
+                       _pkgmgrinfo_node_destroy(link->data);
                        filter->list = g_slist_delete_link(filter->list, link);
+               }
                filter->list = g_slist_append(filter->list, (gpointer)node);
                break;
        case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
@@ -2422,6 +2534,7 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                        ptr = (pkgmgrinfo_node_x *)link->data;
                        strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
                        _LOGI("Previous value is %s\n", prev);
+                       _pkgmgrinfo_node_destroy(ptr);
                        filter->list = g_slist_delete_link(filter->list, link);
                        ret = snprintf(temp, PKG_STRING_LEN_MAX - 1,
                                        "%s,%s", prev, value);
@@ -2451,8 +2564,10 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
                link = g_slist_find_custom(filter->list,
                                (gconstpointer)node, __compare_func);
-               if (link)
+               if (link) {
+                       _pkgmgrinfo_node_destroy(link->data);
                        filter->list = g_slist_delete_link(filter->list, link);
+               }
                filter->list = g_slist_append(filter->list, (gpointer)node);
                break;
        }