4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
32 #include "pkgmgr-info.h"
33 #include "pkgmgrinfo_debug.h"
34 #include "pkgmgrinfo_private.h"
35 #include "pkgmgr_parser.h"
37 struct _pkginfo_str_map_t {
38 pkgmgrinfo_pkginfo_filter_prop_str prop;
42 static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = {
43 {E_PMINFO_PKGINFO_PROP_PACKAGE_ID, PMINFO_PKGINFO_PROP_PACKAGE_ID},
44 {E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE, PMINFO_PKGINFO_PROP_PACKAGE_TYPE},
45 {E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION, PMINFO_PKGINFO_PROP_PACKAGE_VERSION},
46 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION},
47 {E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE},
48 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME},
49 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL},
50 {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF},
51 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE}
54 struct _pkginfo_int_map_t {
55 pkgmgrinfo_pkginfo_filter_prop_int prop;
59 static struct _pkginfo_int_map_t pkginfo_int_prop_map[] = {
60 {E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE, PMINFO_PKGINFO_PROP_PACKAGE_SIZE}
63 struct _pkginfo_bool_map_t {
64 pkgmgrinfo_pkginfo_filter_prop_bool prop;
68 static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = {
69 {E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE},
70 {E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD},
71 {E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY, PMINFO_PKGINFO_PROP_PACKAGE_READONLY},
72 {E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, PMINFO_PKGINFO_PROP_PACKAGE_UPDATE},
73 {E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING},
74 {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING, PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING},
75 {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE},
76 {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE}
79 struct _appinfo_str_map_t {
80 pkgmgrinfo_appinfo_filter_prop_str prop;
84 static struct _appinfo_str_map_t appinfo_str_prop_map[] = {
85 {E_PMINFO_APPINFO_PROP_APP_ID, PMINFO_APPINFO_PROP_APP_ID},
86 {E_PMINFO_APPINFO_PROP_APP_COMPONENT, PMINFO_APPINFO_PROP_APP_COMPONENT},
87 {E_PMINFO_APPINFO_PROP_APP_EXEC, PMINFO_APPINFO_PROP_APP_EXEC},
88 {E_PMINFO_APPINFO_PROP_APP_ICON, PMINFO_APPINFO_PROP_APP_ICON},
89 {E_PMINFO_APPINFO_PROP_APP_TYPE, PMINFO_APPINFO_PROP_APP_TYPE},
90 {E_PMINFO_APPINFO_PROP_APP_OPERATION, PMINFO_APPINFO_PROP_APP_OPERATION},
91 {E_PMINFO_APPINFO_PROP_APP_URI, PMINFO_APPINFO_PROP_APP_URI},
92 {E_PMINFO_APPINFO_PROP_APP_MIME, PMINFO_APPINFO_PROP_APP_MIME},
93 {E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY},
94 {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION},
95 {E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER},
96 {E_PMINFO_APPINFO_PROP_APP_METADATA_KEY, PMINFO_APPINFO_PROP_APP_METADATA_KEY},
97 {E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE, PMINFO_APPINFO_PROP_APP_METADATA_VALUE},
98 {E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE}
101 struct _appinfo_int_map_t {
102 pkgmgrinfo_appinfo_filter_prop_int prop;
103 const char *property;
106 static struct _appinfo_int_map_t appinfo_int_prop_map[] = {
107 {E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER}
110 struct _appinfo_bool_map_t {
111 pkgmgrinfo_appinfo_filter_prop_bool prop;
112 const char *property;
115 static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
116 {E_PMINFO_APPINFO_PROP_APP_NODISPLAY, PMINFO_APPINFO_PROP_APP_NODISPLAY},
117 {E_PMINFO_APPINFO_PROP_APP_MULTIPLE, PMINFO_APPINFO_PROP_APP_MULTIPLE},
118 {E_PMINFO_APPINFO_PROP_APP_ONBOOT, PMINFO_APPINFO_PROP_APP_ONBOOT},
119 {E_PMINFO_APPINFO_PROP_APP_AUTORESTART, PMINFO_APPINFO_PROP_APP_AUTORESTART},
120 {E_PMINFO_APPINFO_PROP_APP_TASKMANAGE, PMINFO_APPINFO_PROP_APP_TASKMANAGE},
121 {E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION, PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION},
122 {E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET},
123 {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
124 {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE}
127 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
131 pkgmgrinfo_pkginfo_filter_prop_str prop = -1;
133 if (property == NULL)
135 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR + 1;
136 for (i = 0 ; i < max; i++) {
137 if (strcmp(property, pkginfo_str_prop_map[i].property) == 0) {
138 prop = pkginfo_str_prop_map[i].prop;
145 inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property)
149 pkgmgrinfo_pkginfo_filter_prop_int prop = -1;
151 if (property == NULL)
153 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT + 1;
154 for (i = 0 ; i < max; i++) {
155 if (strcmp(property, pkginfo_int_prop_map[i].property) == 0) {
156 prop = pkginfo_int_prop_map[i].prop;
163 inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property)
167 pkgmgrinfo_pkginfo_filter_prop_bool prop = -1;
169 if (property == NULL)
171 max = E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL - E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL + 1;
172 for (i = 0 ; i < max; i++) {
173 if (strcmp(property, pkginfo_bool_prop_map[i].property) == 0) {
174 prop = pkginfo_bool_prop_map[i].prop;
181 inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property)
185 pkgmgrinfo_appinfo_filter_prop_str prop = -1;
187 if (property == NULL)
189 max = E_PMINFO_APPINFO_PROP_APP_MAX_STR - E_PMINFO_APPINFO_PROP_APP_MIN_STR + 1;
190 for (i = 0 ; i < max; i++) {
191 if (strcmp(property, appinfo_str_prop_map[i].property) == 0) {
192 prop = appinfo_str_prop_map[i].prop;
199 inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property)
203 pkgmgrinfo_appinfo_filter_prop_int prop = -1;
205 if (property == NULL)
207 max = E_PMINFO_APPINFO_PROP_APP_MAX_INT - E_PMINFO_APPINFO_PROP_APP_MIN_INT + 1;
208 for (i = 0 ; i < max; i++) {
209 if (strcmp(property, appinfo_int_prop_map[i].property) == 0) {
210 prop = appinfo_int_prop_map[i].prop;
217 inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property)
221 pkgmgrinfo_appinfo_filter_prop_bool prop = -1;
223 if (property == NULL)
225 max = E_PMINFO_APPINFO_PROP_APP_MAX_BOOL - E_PMINFO_APPINFO_PROP_APP_MIN_BOOL + 1;
226 for (i = 0 ; i < max; i++) {
227 if (strcmp(property, appinfo_bool_prop_map[i].property) == 0) {
228 prop = appinfo_bool_prop_map[i].prop;
235 int __get_filter_condition(gpointer data, char **condition, GList **params)
237 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
238 char buf[MAX_QUERY_LEN] = {'\0'};
241 char *saveptr = NULL;
243 switch (node->prop) {
244 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
245 snprintf(buf, sizeof(buf), "pi.package=?");
247 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
248 snprintf(buf, sizeof(buf), "pi.package_type=?");
250 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
251 snprintf(buf, sizeof(buf), "pi.package_version=?");
253 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
254 snprintf(buf, sizeof(buf), "pi.install_location=?");
256 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
257 snprintf(buf, sizeof(buf), "pi.installed_storage=?");
259 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
260 snprintf(buf, sizeof(buf), "pi.author_name=?");
262 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
263 snprintf(buf, sizeof(buf), "pi.author_href=?");
265 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
266 snprintf(buf, sizeof(buf), "pi.author_email=?");
268 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE:
269 snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?");
270 flag = E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO;
272 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
273 snprintf(buf, sizeof(buf), "pi.package_size=?");
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
276 snprintf(buf, sizeof(buf), "pi.package_removable=? COLLATE NOCASE");
278 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
279 snprintf(buf, sizeof(buf), "pi.package_preload=? COLLATE NOCASE");
281 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
282 snprintf(buf, sizeof(buf), "pi.package_readonly=? COLLATE NOCASE");
284 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
285 snprintf(buf, sizeof(buf), "pi.package_update=? COLLATE NOCASE");
287 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
288 snprintf(buf, sizeof(buf), "pi.package_appsetting=? COLLATE NOCASE");
290 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
291 snprintf(buf, sizeof(buf), "pi.package_nodisplay=? COLLATE NOCASE");
293 case E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE:
294 snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE");
296 case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE:
297 snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE");
300 case E_PMINFO_APPINFO_PROP_APP_ID:
301 snprintf(buf, sizeof(buf), "ai.app_id=?");
303 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
304 snprintf(buf, sizeof(buf), "ai.app_component=?");
306 case E_PMINFO_APPINFO_PROP_APP_EXEC:
307 snprintf(buf, sizeof(buf), "ai.app_exec=?");
309 case E_PMINFO_APPINFO_PROP_APP_ICON:
310 snprintf(buf, sizeof(buf), "package_app_localized_info.app_icon=?");
311 flag = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO;
313 case E_PMINFO_APPINFO_PROP_APP_TYPE:
314 snprintf(buf, sizeof(buf), "ai.app_type=?");
316 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
317 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE ?||'|%%%%|%%%%'");
318 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
320 case E_PMINFO_APPINFO_PROP_APP_URI:
321 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|'||?||'|%%%%'");
322 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
324 case E_PMINFO_APPINFO_PROP_APP_MIME:
325 snprintf(buf, sizeof(buf), "package_app_app_control.app_control LIKE '%%%%|%%%%|'||?");
326 flag = E_PMINFO_APPINFO_JOIN_APP_CONTROL;
328 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
329 snprintf(buf, sizeof(buf), "package_app_app_category.category IN (");
330 ptr = strtok_r(node->value, ",", &saveptr);
333 strncat(buf, "?", MAX_QUERY_LEN - 2);
334 *params = g_list_append(*params, strdup(ptr));
335 while ((ptr = strtok_r(NULL, ",", &saveptr))) {
336 strncat(buf, ", ?", MAX_QUERY_LEN - strlen(", ?") - 1);
337 *params = g_list_append(*params, strdup(ptr));
339 strncat(buf, ")", MAX_QUERY_LEN - 2);
340 *condition = strdup(buf);
341 flag = E_PMINFO_APPINFO_JOIN_CATEGORY;
344 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
345 snprintf(buf, sizeof(buf), "ai.app_nodisplay=? COLLATE NOCASE");
347 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
348 snprintf(buf, sizeof(buf), "ai.app_multiple=? COLLATE NOCASE");
350 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
351 snprintf(buf, sizeof(buf), "ai.app_onboot=? COLLATE NOCASE");
353 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
354 snprintf(buf, sizeof(buf), "ai.app_autorestart=? COLLATE NOCASE");
356 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
357 snprintf(buf, sizeof(buf), "ai.app_taskmanage=? COLLATE NOCASE");
359 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
360 snprintf(buf, sizeof(buf), "ai.app_hwacceleration=?");
362 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
363 snprintf(buf, sizeof(buf), "ai.app_screenreader=?");
365 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
366 snprintf(buf, sizeof(buf), "ai.app_launchcondition=? COLLATE NOCASE");
368 case E_PMINFO_APPINFO_PROP_APP_PACKAGE:
369 snprintf(buf, sizeof(buf), "ai.package=?");
371 case E_PMINFO_APPINFO_PROP_APP_UI_GADGET:
372 snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE");
374 case E_PMINFO_APPINFO_PROP_APP_METADATA_KEY:
375 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_key=?");
376 flag = E_PMINFO_APPINFO_JOIN_METADATA;
378 case E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE:
379 snprintf(buf, sizeof(buf), "package_app_app_metadata.md_value=?");
380 flag = E_PMINFO_APPINFO_JOIN_METADATA;
382 case E_PMINFO_APPINFO_PROP_APP_DISABLE:
383 snprintf(buf, MAX_QUERY_LEN, "ai.app_disable=? COLLATE NOCASE");
385 case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
386 snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
388 case E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER:
389 snprintf(buf, MAX_QUERY_LEN, "ai.app_id NOT IN "
390 "(SELECT app_id from package_app_info_for_uid WHERE uid=? " \
391 "AND is_disabled='true' COLLATE NOCASE)");
394 _LOGE("Invalid Property Type\n");
398 *condition = strdup(buf);
399 *params = g_list_append(*params, strdup(node->value));
403 char *_get_system_locale(void)
408 lang = vconf_get_str(VCONFKEY_LANGSET);
410 locale = strdup(DEFAULT_LOCALE);
411 if (locale == NULL) {
412 LOGE("out of memory");
418 locale = malloc(sizeof(char) * 6);
419 if (locale == NULL) {
420 LOGE("out of memory");
425 strncpy(locale, lang, 2);
427 locale[3] = tolower(lang[3]);
428 locale[4] = tolower(lang[4]);