tizen 2.3.1 release
[framework/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
1 /*
2  * pkgmgrinfo-appinfo
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Junsuk Oh <junsuk77.oh@samsung.com>,
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include "pkgmgrinfo_private.h"
23 #include "pkgmgr_parser.h"
24
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28 #define LOG_TAG "PKGMGR_INFO"
29
30 #define LANGUAGE_LENGTH 2
31 #define MAX_PACKAGE_STR_SIZE 512
32
33 #define SAT_UI_APPID_1  "org.tizen.sat-ui"
34 #define SAT_UI_APPID_2  "org.tizen.sat-ui-2"
35 #define PKG_DATA_PATH   "/opt/usr/data/pkgmgr"
36
37
38 #define FILTER_QUERY_COUNT_APP  "select DISTINCT package_app_info.app_id, package_app_info.app_component, package_app_info.app_installed_storage " \
39                                 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
40                                 "ON package_app_info.app_id=package_app_localized_info.app_id " \
41                                 "and package_app_localized_info.app_locale='%s' " \
42                                 "LEFT OUTER JOIN package_app_app_svc " \
43                                 "ON package_app_info.app_id=package_app_app_svc.app_id " \
44                                 "LEFT OUTER JOIN package_app_app_category " \
45                                 "ON package_app_info.app_id=package_app_app_category.app_id where "
46
47 #define FILTER_QUERY_LIST_APP   "select DISTINCT package_app_info.*, package_app_localized_info.app_locale, package_app_localized_info.app_label, package_app_localized_info.app_icon " \
48                                 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
49                                 "ON package_app_info.app_id=package_app_localized_info.app_id " \
50                                 "and package_app_localized_info.app_locale IN ('%s', '%s') " \
51                                 "LEFT OUTER JOIN package_app_app_svc " \
52                                 "ON package_app_info.app_id=package_app_app_svc.app_id " \
53                                 "LEFT OUTER JOIN package_app_app_category " \
54                                 "ON package_app_info.app_id=package_app_app_category.app_id where "
55
56 #define METADATA_FILTER_QUERY_SELECT_CLAUSE     "select DISTINCT package_app_info.* " \
57                                 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
58                                 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
59
60 #define METADATA_FILTER_QUERY_UNION_CLAUSE      " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
61
62 typedef struct _pkgmgr_locale_x {
63         char *locale;
64 } pkgmgr_locale_x;
65
66 typedef struct _pkgmgrinfo_appcontrol_x {
67         int operation_count;
68         int uri_count;
69         int mime_count;
70         int subapp_count;
71         char **operation;
72         char **uri;
73         char **mime;
74         char **subapp;
75 } pkgmgrinfo_appcontrol_x;
76
77 static char* __get_aliasid_from_db(sqlite3 *appinfo_db, const char *appid)
78 {
79         int ret = PMINFO_R_OK;
80         char *alias_id = NULL;
81         char *query = NULL;
82         sqlite3_stmt *stmt = NULL;
83
84         query = sqlite3_mprintf("select alias_id from package_app_aliasid where app_id=%Q", appid);
85         tryvm_if(query == NULL, ret = PMINFO_R_ERROR,"Malloc failed!!");
86
87         /*Prepare query*/
88         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
89         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
90
91         alias_id = (char*)malloc(MAX_PACKAGE_STR_SIZE);
92         tryvm_if(alias_id == NULL, ret = PMINFO_R_ERROR,"Malloc failed!!");
93         memset(alias_id,'\0',MAX_PACKAGE_STR_SIZE);
94
95         /*Step query*/
96         ret = sqlite3_step(stmt);
97         if(ret == SQLITE_ROW){
98                 /*Get the alias id*/
99                 snprintf(alias_id, MAX_PACKAGE_STR_SIZE, "%s", (const char *)sqlite3_column_text(stmt, 0));
100                 _LOGD("alias id [%s] id found for [%s] in DB",alias_id,appid);
101         }
102
103 catch:
104         if (query)
105                 sqlite3_free(query);
106         if (stmt)
107                 sqlite3_finalize(stmt);
108
109         /*If alias id is not found then set the appid as alias id*/
110         if ( alias_id == NULL || strlen(alias_id) == 0 ) {
111                 FREE_AND_NULL(alias_id);
112                 alias_id = strdup(appid);
113         }
114
115         return alias_id;
116
117 }
118
119 static void __get_appinfo_from_db(char *colname, char *coltxt, uiapplication_x *uiapp)
120 {
121         if (colname == NULL || uiapp == NULL)
122                 return;
123
124         if (strcmp(colname, "app_id") == 0) {
125                 if (uiapp->appid)
126                         return;
127
128                 if (coltxt)
129                         uiapp->appid = strdup(coltxt);
130
131         } else if (strcmp(colname, "app_component") == 0) {
132                 if (coltxt)
133                         uiapp->app_component = strdup(coltxt);
134                 else
135                         uiapp->app_component = NULL;
136         } else if (strcmp(colname, "app_exec") == 0) {
137                 if (coltxt)
138                         uiapp->exec = strdup(coltxt);
139                 else
140                         uiapp->exec = NULL;
141         } else if (strcmp(colname, "app_ambient_support") == 0) {
142                 if (coltxt)
143                         uiapp->ambient_support = strdup(coltxt);
144                 else
145                         uiapp->ambient_support = NULL;
146         } else if (strcmp(colname, "app_nodisplay") == 0) {
147                 if (coltxt)
148                         uiapp->nodisplay = strdup(coltxt);
149                 else
150                         uiapp->nodisplay = NULL;
151         } else if (strcmp(colname, "app_type") == 0 ) {
152                 if (coltxt)
153                         uiapp->type = strdup(coltxt);
154                 else
155                         uiapp->type = NULL;
156         } else if (strcmp(colname, "app_onboot") == 0 ) {
157                 if (coltxt)
158                         uiapp->onboot= strdup(coltxt);
159                 else
160                         uiapp->onboot = NULL;
161         } else if (strcmp(colname, "app_multiple") == 0 ) {
162                 if (coltxt)
163                         uiapp->multiple = strdup(coltxt);
164                 else
165                         uiapp->multiple = NULL;
166         } else if (strcmp(colname, "app_autorestart") == 0 ) {
167                 if (coltxt)
168                         uiapp->autorestart= strdup(coltxt);
169                 else
170                         uiapp->autorestart = NULL;
171         } else if (strcmp(colname, "app_taskmanage") == 0 ) {
172                 if (coltxt)
173                         uiapp->taskmanage = strdup(coltxt);
174                 else
175                         uiapp->taskmanage = NULL;
176         } else if (strcmp(colname, "app_enabled") == 0 ) {
177                 if (coltxt)
178                         uiapp->enabled= strdup(coltxt);
179                 else
180                         uiapp->enabled = NULL;
181         } else if (strcmp(colname, "app_hwacceleration") == 0 ) {
182                 if (coltxt)
183                         uiapp->hwacceleration = strdup(coltxt);
184                 else
185                         uiapp->hwacceleration = NULL;
186         } else if (strcmp(colname, "app_screenreader") == 0 ) {
187                 if (coltxt)
188                         uiapp->screenreader = strdup(coltxt);
189                 else
190                         uiapp->screenreader = NULL;
191         } else if (strcmp(colname, "app_mainapp") == 0 ) {
192                 if (coltxt)
193                         uiapp->mainapp = strdup(coltxt);
194                 else
195                         uiapp->mainapp = NULL;
196         } else if (strcmp(colname, "app_recentimage") == 0 ) {
197                 if (coltxt)
198                         uiapp->recentimage = strdup(coltxt);
199                 else
200                         uiapp->recentimage = NULL;
201         } else if (strcmp(colname, "app_launchcondition") == 0 ) {
202                 if (coltxt)
203                         uiapp->launchcondition = strdup(coltxt);
204                 else
205                         uiapp->launchcondition = NULL;
206         } else if (strcmp(colname, "app_indicatordisplay") == 0){
207                 if (coltxt)
208                         uiapp->indicatordisplay = strdup(coltxt);
209                 else
210                         uiapp->indicatordisplay = NULL;
211         } else if (strcmp(colname, "app_portraitimg") == 0){
212                 if (coltxt)
213                         uiapp->portraitimg = strdup(coltxt);
214                 else
215                         uiapp->portraitimg = NULL;
216         } else if (strcmp(colname, "app_landscapeimg") == 0){
217                 if (coltxt)
218                         uiapp->landscapeimg = strdup(coltxt);
219                 else
220                         uiapp->landscapeimg = NULL;
221         } else if (strcmp(colname, "app_effectimage_type") == 0){
222                 if (coltxt)
223                         uiapp->effectimage_type = strdup(coltxt);
224                 else
225                         uiapp->effectimage_type = NULL;
226         } else if (strcmp(colname, "app_guestmodevisibility") == 0){
227                 if (coltxt)
228                         uiapp->guestmode_visibility = strdup(coltxt);
229                 else
230                         uiapp->guestmode_visibility = NULL;
231         } else if (strcmp(colname, "app_permissiontype") == 0 ) {
232                 if (coltxt)
233                         uiapp->permission_type = strdup(coltxt);
234                 else
235                         uiapp->permission_type = NULL;
236         } else if (strcmp(colname, "app_preload") == 0 ) {
237                 if (coltxt)
238                         uiapp->preload = strdup(coltxt);
239                 else
240                         uiapp->preload = NULL;
241         } else if (strcmp(colname, "app_submode") == 0 ) {
242                 if (coltxt)
243                         uiapp->submode = strdup(coltxt);
244                 else
245                         uiapp->submode = NULL;
246         } else if (strcmp(colname, "app_submode_mainid") == 0 ) {
247                 if (coltxt)
248                         uiapp->submode_mainid = strdup(coltxt);
249                 else
250                         uiapp->submode_mainid = NULL;
251         } else if (strcmp(colname, "app_installed_storage") == 0 ) {
252                 if (coltxt)
253                         uiapp->installed_storage = strdup(coltxt);
254                 else
255                         uiapp->installed_storage = NULL;
256         } else if (strcmp(colname, "app_process_pool") == 0 ) {
257                 if (coltxt)
258                         uiapp->process_pool = strdup(coltxt);
259                 else
260                         uiapp->process_pool = NULL;
261         } else if (strcmp(colname, "app_multi_instance") == 0 ) {
262                 if (coltxt)
263                         uiapp->multi_instance = strdup(coltxt);
264                 else
265                         uiapp->multi_instance = NULL;
266         } else if (strcmp(colname, "app_multi_instance_mainid") == 0 ) {
267                 if (coltxt)
268                         uiapp->multi_instance_mainid = strdup(coltxt);
269                 else
270                         uiapp->multi_instance_mainid = NULL;
271         } else if (strcmp(colname, "app_multi_window") == 0 ) {
272                 if (coltxt)
273                         uiapp->multi_window = strdup(coltxt);
274                 else
275                         uiapp->multi_window = NULL;
276         } else if (strcmp(colname, "app_support_disable") == 0 ) {
277                 if (coltxt)
278                         uiapp->support_disable= strdup(coltxt);
279                 else
280                         uiapp->support_disable = NULL;
281         } else if (strcmp(colname, "app_ui_gadget") == 0 ) {
282                 if (coltxt)
283                         uiapp->ui_gadget = strdup(coltxt);
284                 else
285                         uiapp->ui_gadget = NULL;
286         } else if (strcmp(colname, "app_removable") == 0 ) {
287                 if (coltxt)
288                         uiapp->removable = strdup(coltxt);
289                 else
290                         uiapp->removable = NULL;
291         } else if (strcmp(colname, "app_support_mode") == 0 ) {
292                 if (coltxt)
293                         uiapp->support_mode = strdup(coltxt);
294                 else
295                         uiapp->support_mode = NULL;
296         } else if (strcmp(colname, "app_support_feature") == 0 ) {
297                 if (coltxt)
298                         uiapp->support_feature = strdup(coltxt);
299                 else
300                         uiapp->support_feature = NULL;
301         } else if (strcmp(colname, "component_type") == 0 ) {
302                 if (coltxt)
303                         uiapp->component_type = strdup(coltxt);
304                 else
305                         uiapp->component_type = NULL;
306         } else if (strcmp(colname, "package") == 0 ) {
307                 if (coltxt)
308                         uiapp->package = strdup(coltxt);
309                 else
310                         uiapp->package = NULL;
311         } else if (strcmp(colname, "app_package_type") == 0 ) {
312                 if (coltxt)
313                         uiapp->package_type = strdup(coltxt);
314                 else
315                         uiapp->package_type = NULL;
316         } else if (strcmp(colname, "app_package_system") == 0 ) {
317                 if (coltxt)
318                         uiapp->package_system = strdup(coltxt);
319                 else
320                         uiapp->package_system = NULL;
321         } else if (strcmp(colname, "app_package_installed_time") == 0 ) {
322                 if (coltxt)
323                         uiapp->package_installed_time = strdup(coltxt);
324                 else
325                         uiapp->package_installed_time = NULL;
326
327         /*end of package_app_info table*/
328
329         } else if (strcmp(colname, "app_locale") == 0 ) {
330                 if (coltxt) {
331                         uiapp->icon->lang = strdup(coltxt);
332                         uiapp->label->lang = strdup(coltxt);
333                 }
334                 else {
335                         uiapp->icon->lang = NULL;
336                         uiapp->label->lang = NULL;
337                 }
338         } else if (strcmp(colname, "app_label") == 0 ) {
339                 if (coltxt)
340                         uiapp->label->text = strdup(coltxt);
341                 else
342                         uiapp->label->text = NULL;
343         } else if (strcmp(colname, "app_icon") == 0) {
344                 if (coltxt)
345                         uiapp->icon->text = strdup(coltxt);
346                 else
347                         uiapp->icon->text = NULL;
348         /*end of package_app_localized_info table*/
349
350         } else if (strcmp(colname, "category") == 0 ) {
351                 if (coltxt)
352                         uiapp->category->name = strdup(coltxt);
353                 else
354                         uiapp->category->name = NULL;
355         /*end of package_app_category_info table*/
356
357         } else if (strcmp(colname, "md_key") == 0 ) {
358                 if (coltxt)
359                         uiapp->metadata->key = strdup(coltxt);
360                 else
361                         uiapp->metadata->key = NULL;
362         } else if (strcmp(colname, "md_value") == 0 ) {
363                 if (coltxt)
364                         uiapp->metadata->value = strdup(coltxt);
365                 else
366                         uiapp->metadata->value = NULL;
367         /*end of package_app_metadata_info table*/
368
369         } else if (strcmp(colname, "pm_type") == 0 ) {
370                 if (coltxt)
371                         uiapp->permission->type= strdup(coltxt);
372                 else
373                         uiapp->permission->type = NULL;
374         } else if (strcmp(colname, "pm_value") == 0 ) {
375                 if (coltxt)
376                         uiapp->permission->value = strdup(coltxt);
377                 else
378                         uiapp->permission->value = NULL;
379         /*end of package_app_permission_info table*/
380
381         } else if (strcmp(colname, "app_image") == 0) {
382                 if (coltxt)
383                         uiapp->image->text= strdup(coltxt);
384                 else
385                         uiapp->image->text = NULL;
386         } else if (strcmp(colname, "app_image_section") == 0) {
387                 if (coltxt)
388                         uiapp->image->section= strdup(coltxt);
389                 else
390                         uiapp->image->section = NULL;
391         /*end of package_app_image_info table*/
392         }
393 }
394
395 static void __update_localed_label_for_list(sqlite3_stmt *stmt, pkgmgr_pkginfo_x *info)
396 {
397         int i = 0;
398         int ncols = 0;
399         char *colname = NULL;
400         char *coltxt = NULL;
401
402 //      uiapplication_x *ptr1 = NULL;
403
404 //      LISTHEAD(info->manifest_info->uiapplication, ptr1);
405
406         ncols = sqlite3_column_count(stmt);
407
408         for(i = 0; i < ncols; i++)
409         {
410                 colname = (char *)sqlite3_column_name(stmt, i);
411                 if (colname && strcmp(colname, "app_label") == 0 ){
412                         coltxt = (char *)sqlite3_column_text(stmt, i);
413                         FREE_AND_STRDUP(coltxt, info->manifest_info->uiapplication->label->text);
414                 }
415         }
416 }
417
418 /* get the first locale value*/
419 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
420 {
421         pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
422
423         if (ncols >= 1)
424                 info->locale = strdup(coltxt[0]);
425         else
426                 info->locale = NULL;
427
428         return 0;
429 }
430
431 int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
432 {
433         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
434         int i = 0;
435         icon_x *icon = NULL;
436         label_x *label = NULL;
437         category_x *category = NULL;
438         metadata_x *metadata = NULL;
439         permission_x *permission = NULL;
440         image_x *image = NULL;
441
442         icon = calloc(1, sizeof(icon_x));
443         retvm_if(icon == NULL, PMINFO_R_ERROR, "out of memory");
444         LISTADD(info->uiapp_info->icon, icon);
445         label = calloc(1, sizeof(label_x));
446         retvm_if(label == NULL, PMINFO_R_ERROR, "out of memory");
447         LISTADD(info->uiapp_info->label, label);
448         category = calloc(1, sizeof(category_x));
449         retvm_if(category == NULL, PMINFO_R_ERROR, "out of memory");
450         LISTADD(info->uiapp_info->category, category);
451         metadata = calloc(1, sizeof(metadata_x));
452         retvm_if(metadata == NULL, PMINFO_R_ERROR, "out of memory");
453         LISTADD(info->uiapp_info->metadata, metadata);
454         permission = calloc(1, sizeof(permission_x));
455         retvm_if(permission == NULL, PMINFO_R_ERROR, "out of memory");
456         LISTADD(info->uiapp_info->permission, permission);
457         image = calloc(1, sizeof(image_x));
458         retvm_if(image == NULL, PMINFO_R_ERROR, "out of memory");
459         LISTADD(info->uiapp_info->image, image);
460
461         for(i = 0; i < ncols; i++)
462         {
463                 __get_appinfo_from_db(colname[i], coltxt[i], info->uiapp_info);
464         }
465         return 0;
466 }
467
468 int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
469 {
470         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
471         int i = 0;
472         uiapplication_x *uiapp = NULL;
473         icon_x *icon = NULL;
474         label_x *label = NULL;
475
476         uiapp = calloc(1, sizeof(uiapplication_x));
477         retvm_if(uiapp == NULL, PMINFO_R_ERROR, "out of memory");
478         LISTADD(info->manifest_info->uiapplication, uiapp);
479         icon = calloc(1, sizeof(icon_x));
480         retvm_if(icon == NULL, PMINFO_R_ERROR, "out of memory");
481         LISTADD(info->manifest_info->uiapplication->icon, icon);
482         label = calloc(1, sizeof(label_x));
483         retvm_if(label == NULL, PMINFO_R_ERROR, "out of memory");
484         LISTADD(info->manifest_info->uiapplication->label, label);
485
486         for(i = 0; i < ncols; i++)
487         {
488                 __get_appinfo_from_db(colname[i], coltxt[i], info->manifest_info->uiapplication);
489         }
490         return 0;
491 }
492
493 static void __get_appinfo_for_list(sqlite3_stmt *stmt, pkgmgr_pkginfo_x *udata)
494 {
495         int i = 0;
496         int ncols = 0;
497         char *colname = NULL;
498         char *coltxt = NULL;
499
500         uiapplication_x *uiapp = NULL;
501
502         uiapp = calloc(1, sizeof(uiapplication_x));
503         retvm_if(uiapp == NULL, PMINFO_R_ERROR, "out of memory");
504         uiapp->icon= calloc(1, sizeof(icon_x));
505         uiapp->label= calloc(1, sizeof(label_x));
506
507         LISTADD(udata->manifest_info->uiapplication, uiapp);
508
509         ncols = sqlite3_column_count(stmt);
510
511         for(i = 0; i < ncols; i++)
512         {
513                 colname = (char *)sqlite3_column_name(stmt, i);
514                 coltxt = (char *)sqlite3_column_text(stmt, i);
515
516 //              _LOGE("field value      :: %s = %s \n", colname, coltxt);
517                 __get_appinfo_from_db(colname, coltxt, udata->manifest_info->uiapplication);
518         }
519 }
520
521 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
522 {
523         int result_query = -1;
524         int ret = 0;
525
526         char *query = sqlite3_mprintf("select exists(select app_locale from package_app_localized_info where app_id=%Q and app_locale=%Q)", appid, locale);
527         ret = __exec_db_query(db, query, _pkgmgrinfo_validate_cb, (void *)&result_query);
528         sqlite3_free(query);
529         retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
530         return result_query;
531 }
532
533 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
534 {
535         int result_query = -1;
536         int ret = 0;
537         char wildcard[2] = {'%','\0'};
538         char lang[3] = {'\0'};
539         strncpy(lang, locale, LANGUAGE_LENGTH);
540
541         char *query = sqlite3_mprintf("select exists(select app_locale from package_app_localized_info where app_id=%Q and app_locale like %Q%Q)", appid, lang, wildcard);
542         ret = __exec_db_query(db, query, _pkgmgrinfo_validate_cb, (void *)&result_query);
543         sqlite3_free(query);
544         retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
545         return result_query;
546 }
547
548 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
549 {
550         int ret = 0;
551         char wildcard[2] = {'%','\0'};
552         char lang[3] = {'\0'};
553         char *locale_new = NULL;
554         pkgmgr_locale_x *info = NULL;
555
556         info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
557         if (info == NULL) {
558                 _LOGE("Out of Memory!!!\n");
559                 return NULL;
560         }
561         memset(info, '\0', sizeof(*info));
562
563         strncpy(lang, locale, LANGUAGE_LENGTH);
564         char *query = sqlite3_mprintf("select app_locale from package_app_localized_info where app_id=%Q  and app_locale like %Q%Q", appid, lang, wildcard);
565
566         ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
567         sqlite3_free(query);
568         if (ret < 0)
569                 goto catch;
570
571         locale_new = info->locale;
572         FREE_AND_NULL(info);
573         return locale_new;
574 catch:
575         FREE_AND_NULL(info);
576         return NULL;
577 }
578
579 char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid)
580 {
581         assert(appid);
582
583         char *locale = NULL;
584         char *locale_new = NULL;
585         int check_result = 0;
586
587         locale = __convert_system_locale_to_manifest_locale();
588
589         /*check exact matching */
590         check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
591
592         /* Exact found */
593         if (check_result == 1) {
594 //              _LOGD("%s find exact locale(%s)\n", appid, locale);
595                 return locale;
596         }
597
598         /* fallback matching */
599         check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
600         if(check_result == 1) {
601                    locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
602                    FREE_AND_NULL(locale);
603                    if (locale_new == NULL)
604                            locale_new =  strdup(DEFAULT_LOCALE);
605                    return locale_new;
606         }
607
608         /* default locale */
609         FREE_AND_NULL(locale);
610         return  strdup(DEFAULT_LOCALE);
611 }
612
613 static void __get_metadata_filter_condition(gpointer data, char **condition)
614 {
615         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
616         char key[MAX_QUERY_LEN] = {'\0'};
617         char value[MAX_QUERY_LEN] = {'\0'};
618         if (node->key) {
619                 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
620         }
621         if (node->value) {
622                 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
623                 strcat(key, value);
624         } else {
625                 strcat(key, ")");
626         }
627         *condition = strdup(key);
628         return;
629 }
630
631 static int __sat_ui_is_enabled(const char *appid, bool *enabled)
632 {
633         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
634         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
635
636         if ((strncmp(appid, SAT_UI_APPID_1, strlen(SAT_UI_APPID_1)) == 0) || (strncmp(appid, SAT_UI_APPID_2, strlen(SAT_UI_APPID_2)) == 0)) {
637                 char info_file[MAX_PACKAGE_STR_SIZE] = {'\0', };
638
639                 snprintf(info_file, MAX_PACKAGE_STR_SIZE, "%s/%s", PKG_DATA_PATH, appid);
640                 if (access(info_file, F_OK)==0) {
641                         *enabled = 1;
642                 } else {
643                         *enabled = 0;
644                 }
645                 return PMINFO_R_OK;
646         }
647         return PMINFO_R_EINVAL;
648 }
649
650 static int __sat_ui_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
651 {
652         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
653         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
654
655         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
656         retvm_if(info->uiapp_info->appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
657
658         if ((strncmp((char *)info->uiapp_info->appid, SAT_UI_APPID_1, strlen(SAT_UI_APPID_1)) == 0) || (strncmp((char *)info->uiapp_info->appid, SAT_UI_APPID_2, strlen(SAT_UI_APPID_2)) == 0)) {
659                 char info_file[MAX_PACKAGE_STR_SIZE] = {'\0', };
660
661                 snprintf(info_file, MAX_PACKAGE_STR_SIZE, "%s/%s", PKG_DATA_PATH, (char *)info->uiapp_info->appid);
662                 if (access(info_file, F_OK)==0) {
663                         FILE *fp;
664                         char buf[MAX_PACKAGE_STR_SIZE] = {0};
665
666                         fp = fopen(info_file, "r");
667                         if (fp == NULL){
668                                 _LOGE("fopen[%s] fail\n", info_file);
669                                 return PMINFO_R_ERROR;
670                         }
671
672                         fgets(buf, MAX_PACKAGE_STR_SIZE, fp);
673                         if (buf[0] == '\0') {
674                                 _LOGE("[%s] use db info\n", (char *)info->uiapp_info->appid);
675                                 fclose(fp);
676                                 return PMINFO_R_ERROR;
677                         }
678
679                         FREE_AND_STRDUP(buf, info->uiapp_info->satui_label);
680                         *label = info->uiapp_info->satui_label;
681
682                         fclose(fp);
683                         return PMINFO_R_OK;
684                 }
685         }
686         return PMINFO_R_ERROR;
687 }
688
689 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
690                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
691 {
692         retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
693         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
694         retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
695         retvm_if(component == PMINFO_SVC_APP, PMINFO_R_OK, "PMINFO_SVC_APP is done" );
696
697         char *locale = NULL;
698         int ret = -1;
699         char query[MAX_QUERY_LEN] = {'\0'};
700         pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
701         pkgmgr_pkginfo_x *allinfo = NULL;
702         pkgmgr_appinfo_x *appinfo = NULL;
703         icon_x *ptr1 = NULL;
704         label_x *ptr2 = NULL;
705         category_x *ptr3 = NULL;
706         metadata_x *ptr4 = NULL;
707         permission_x *ptr5 = NULL;
708         image_x *ptr6 = NULL;
709         sqlite3 *appinfo_db = NULL;
710
711         /*check installed storage*/
712         ret = __pkginfo_check_installed_storage(info);
713         retvm_if(ret < 0, PMINFO_R_EINVAL, "[%s] is installed external, but is not in mmc", info->manifest_info->package);
714
715         /*get system locale*/
716         locale = __convert_system_locale_to_manifest_locale();
717         tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
718
719         /*calloc allinfo*/
720         allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
721         tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
722
723         /*calloc manifest_info*/
724         allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
725         tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
726
727         /*calloc appinfo*/
728         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
729         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
730
731         /*open db */
732         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
733         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
734
735         snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
736                         "from package_app_info where " \
737                         "package='%s' and app_component='%s' and app_disable='false'",
738                         info->manifest_info->package,"uiapp");
739
740         /*Populate ui app info */
741         ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
742         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
743
744         uiapplication_x *tmp = NULL;
745         SAFE_LISTHEAD(info->manifest_info->uiapplication, tmp);
746
747         /*Populate localized info for default locales and call callback*/
748         /*If the callback func return < 0 we break and no more call back is called*/
749         while(tmp != NULL)
750         {
751                 if (locale)
752                         appinfo->locale = strdup(locale);
753                 appinfo->uiapp_info = tmp;
754                 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
755                         FREE_AND_NULL(locale);
756                         locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid);
757                 }
758
759                 memset(query, '\0', MAX_QUERY_LEN);
760                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
761                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
762                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
763
764                 memset(query, '\0', MAX_QUERY_LEN);
765                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
766                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
767                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
768
769                 /*store setting notification icon section*/
770                 memset(query, '\0', MAX_QUERY_LEN);
771                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
772                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
773                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
774
775                 /*store app preview image info*/
776                 memset(query, '\0', MAX_QUERY_LEN);
777                 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
778                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
779                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
780
781                 /*Populate app category*/
782                 memset(query, '\0', MAX_QUERY_LEN);
783                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appinfo->uiapp_info->appid);
784                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
785                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
786
787                 /*Populate app metadata*/
788                 memset(query, '\0', MAX_QUERY_LEN);
789                 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appinfo->uiapp_info->appid);
790                 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
791                 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
792
793                 SAFE_LISTHEAD(appinfo->uiapp_info->icon, ptr1);
794                 SAFE_LISTHEAD(appinfo->uiapp_info->label, ptr2);
795                 SAFE_LISTHEAD(appinfo->uiapp_info->category, ptr3);
796                 SAFE_LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
797                 SAFE_LISTHEAD(appinfo->uiapp_info->permission, ptr5);
798                 SAFE_LISTHEAD(appinfo->uiapp_info->image, ptr6);
799
800                 ret = app_func((void *)appinfo, user_data);
801                 if (ret < 0){
802                         FREE_AND_NULL(appinfo->locale);
803                         break;
804                 }
805
806                 FREE_AND_NULL(appinfo->locale);
807                 tmp = tmp->next;
808         }
809
810         ret = PMINFO_R_OK;
811
812 catch:
813         FREE_AND_NULL(locale);
814         FREE_AND_NULL(appinfo);
815         __cleanup_pkginfo(allinfo);
816         sqlite3_close(appinfo_db);
817         return ret;
818 }
819
820 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
821 {
822         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
823
824         int ret = PMINFO_R_OK;
825         char *query = NULL;
826         pkgmgr_pkginfo_x *info = NULL;
827         pkgmgr_appinfo_x *appinfo = NULL;
828         uiapplication_x *ptr1 = NULL;
829         sqlite3 *appinfo_db = NULL;
830         sqlite3_stmt *stmt = NULL;
831
832         /*open db*/
833         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
834         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
835
836         /*calloc pkginfo*/
837         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
838         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
839
840         /*calloc manifest_info*/
841         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
842         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
843
844         /*calloc appinfo*/
845         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
846         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
847
848         /*Start constructing query*/
849         query = sqlite3_mprintf("select * from package_app_info where app_disable='false'");
850
851         /*prepare query*/
852         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
853         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
854
855         /*step query*/
856         while(1) {
857                 ret = sqlite3_step(stmt);
858                 if(ret == SQLITE_ROW) {
859                         __get_appinfo_for_list(stmt, info);
860                 } else {
861                         break;
862                 }
863         }
864
865         /*head up*/
866         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
867
868         /*UI Apps*/
869         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
870         {
871                 appinfo->uiapp_info = ptr1;
872
873                 ret = app_func((void *)appinfo, user_data);
874                 if (ret < 0) {
875                         break;
876                 }
877         }
878         ret = PMINFO_R_OK;
879
880 catch:
881         sqlite3_free(query);
882         sqlite3_finalize(stmt);
883         sqlite3_close(appinfo_db);
884         FREE_AND_NULL(appinfo);
885         __cleanup_pkginfo(info);
886         return ret;
887 }
888
889
890 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
891 {
892         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
893
894         int ret = PMINFO_R_OK;
895         char *query = NULL;
896         char *locale = NULL;
897         char appid[MAX_QUERY_LEN] = {0,};
898         char pre_appid[MAX_QUERY_LEN] = {0,};
899
900         pkgmgr_pkginfo_x *info = NULL;
901         pkgmgr_appinfo_x *appinfo = NULL;
902         uiapplication_x *ptr1 = NULL;
903
904         sqlite3 *appinfo_db = NULL;
905         sqlite3_stmt *stmt = NULL;
906
907
908         /*calloc manifest_info*/
909         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
910         retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
911
912         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
913         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
914
915         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
916         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
917
918         /*open db*/
919         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
920         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
921
922         /*Start constructing query*/
923         locale = __convert_system_locale_to_manifest_locale();
924         query = sqlite3_mprintf("select * from package_app_info LEFT OUTER JOIN package_app_localized_info "\
925                                         "ON package_app_info.app_id=package_app_localized_info.app_id "\
926                                         "where package_app_info.app_disable='false' and package_app_localized_info.app_locale IN (%Q, %Q)", DEFAULT_LOCALE, locale);
927
928         /*prepare query*/
929         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
930         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
931
932         /*step query*/
933         while(1) {
934                 ret = sqlite3_step(stmt);
935                 if(ret == SQLITE_ROW) {
936
937                         memset(appid, 0, MAX_QUERY_LEN);
938                         strncpy(appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
939
940                         if (strlen(pre_appid) != 0) {
941                                 if (strcmp(pre_appid, appid) == 0) {
942                                         /*if same appid is found, then it is about exact matched locale*/
943                                         __update_localed_label_for_list(stmt, info);
944
945                                         memset(pre_appid, 0, MAX_QUERY_LEN);
946                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
947
948                                         continue;
949                                 } else {
950                                         memset(pre_appid, 0, MAX_QUERY_LEN);
951                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
952                                 }
953                         } else {
954                                 strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
955                         }
956
957                         __get_appinfo_for_list(stmt, info);
958                 } else {
959                         break;
960                 }
961         }
962
963         /*head up*/
964         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
965
966         /*UI Apps*/
967         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
968         {
969                 if (locale && appinfo->locale == NULL)
970                         appinfo->locale = strdup(locale);
971                 appinfo->uiapp_info = ptr1;
972
973                 ret = __appinfo_check_installed_storage(appinfo);
974                 if(ret < 0)
975                         continue;
976
977                 ret = app_func((void *)appinfo, user_data);
978                 if (ret < 0)
979                         break;
980                 FREE_AND_NULL(appinfo->locale);
981         }
982         ret = PMINFO_R_OK;
983
984 catch:
985         FREE_AND_NULL(locale);
986         sqlite3_free(query);
987         sqlite3_finalize(stmt);
988         sqlite3_close(appinfo_db);
989         FREE_AND_NULL(appinfo);
990         __cleanup_pkginfo(info);
991         return ret;
992 }
993
994 API int pkgmgrinfo_appinfo_get_mounted_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
995 {
996         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
997
998         int ret = PMINFO_R_OK;
999         char *query = NULL;
1000         char appid[MAX_QUERY_LEN] = {0,};
1001         char pre_appid[MAX_QUERY_LEN] = {0,};
1002         char *locale = NULL;
1003         pkgmgr_pkginfo_x *info = NULL;
1004         pkgmgr_appinfo_x *appinfo = NULL;
1005         uiapplication_x *ptr1 = NULL;
1006         sqlite3 *appinfo_db = NULL;
1007         sqlite3_stmt *stmt = NULL;
1008
1009         /*get system locale*/
1010         locale = __convert_system_locale_to_manifest_locale();
1011         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
1012
1013         /*open db*/
1014         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
1015         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1016
1017         /*calloc pkginfo*/
1018         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
1019         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
1020
1021         /*calloc manifest_info*/
1022         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1023         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
1024
1025         /*calloc appinfo*/
1026         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
1027         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
1028
1029         /*Start constructing query*/
1030         query = sqlite3_mprintf("select * from package_app_info LEFT OUTER JOIN package_app_localized_info " \
1031                                                                 "ON package_app_info.app_id=package_app_localized_info.app_id " \
1032                                                                 "where app_installed_storage='installed_external' and package_app_info.app_disable='false' and package_app_localized_info.app_locale IN (%Q, %Q)", DEFAULT_LOCALE, locale);
1033
1034         /*prepare query*/
1035         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
1036         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1037
1038         /*step query*/
1039         while(1) {
1040                 ret = sqlite3_step(stmt);
1041                 if(ret == SQLITE_ROW) {
1042
1043                         memset(appid, 0, MAX_QUERY_LEN);
1044                         strncpy(appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1045
1046                         if (strlen(pre_appid) != 0) {
1047                                 if (strcmp(pre_appid, appid) == 0) {
1048                                         /*if same appid is found, then it is about exact matched locale*/
1049                                         __update_localed_label_for_list(stmt, info);
1050
1051                                         memset(pre_appid, 0, MAX_QUERY_LEN);
1052                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1053
1054                                         continue;
1055                                 } else {
1056                                         memset(pre_appid, 0, MAX_QUERY_LEN);
1057                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1058                                 }
1059                         } else {
1060                                 strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1061                         }
1062
1063                         __get_appinfo_for_list(stmt, info);
1064                 } else {
1065                         break;
1066                 }
1067         }
1068
1069         /*head up*/
1070         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
1071
1072         /*UI Apps*/
1073         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
1074         {
1075                 appinfo->locale = strdup(locale);
1076                 appinfo->uiapp_info = ptr1;
1077
1078                 ret = __appinfo_check_installed_storage(appinfo);
1079                 if(ret < 0) {
1080                         FREE_AND_NULL(appinfo->locale);
1081                         continue;
1082                 }
1083
1084                 ret = app_func((void *)appinfo, user_data);
1085                 if(ret < 0) {
1086                         FREE_AND_NULL(appinfo->locale);
1087                         break;
1088                 }
1089
1090                 FREE_AND_NULL(appinfo->locale);
1091         }
1092         ret = PMINFO_R_OK;
1093
1094 catch:
1095         FREE_AND_NULL(locale);
1096         sqlite3_free(query);
1097         sqlite3_finalize(stmt);
1098         sqlite3_close(appinfo_db);
1099         FREE_AND_NULL(appinfo);
1100         __cleanup_pkginfo(info);
1101         return ret;
1102 }
1103
1104 API int pkgmgrinfo_appinfo_get_unmounted_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1105 {
1106         retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
1107
1108         int ret = PMINFO_R_OK;
1109         char *query = NULL;
1110         char appid[MAX_QUERY_LEN] = {0,};
1111         char pre_appid[MAX_QUERY_LEN] = {0,};
1112         char *locale = NULL;
1113         pkgmgr_pkginfo_x *info = NULL;
1114         pkgmgr_appinfo_x *appinfo = NULL;
1115         uiapplication_x *ptr1 = NULL;
1116         sqlite3 *appinfo_db = NULL;
1117         sqlite3_stmt *stmt = NULL;
1118
1119         /*get system locale*/
1120         locale = __convert_system_locale_to_manifest_locale();
1121         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
1122
1123         /*open db*/
1124         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
1125         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1126
1127         /*calloc pkginfo*/
1128         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
1129         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
1130
1131         /*calloc manifest_info*/
1132         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1133         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
1134
1135         /*calloc appinfo*/
1136         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
1137         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
1138
1139         /*Start constructing query*/
1140         query = sqlite3_mprintf("select * from package_app_info LEFT OUTER JOIN package_app_localized_info " \
1141                                                                 "ON package_app_info.app_id=package_app_localized_info.app_id " \
1142                                                                 "where app_installed_storage='installed_external' and package_app_info.app_disable='false' and package_app_localized_info.app_locale IN (%Q, %Q)", DEFAULT_LOCALE, locale);
1143
1144         /*prepare query*/
1145         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
1146         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1147
1148         /*step query*/
1149         while(1) {
1150                 ret = sqlite3_step(stmt);
1151                 if(ret == SQLITE_ROW) {
1152
1153                         memset(appid, 0, MAX_QUERY_LEN);
1154                         strncpy(appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1155
1156                         if (strlen(pre_appid) != 0) {
1157                                 if (strcmp(pre_appid, appid) == 0) {
1158                                         /*if same appid is found, then it is about exact matched locale*/
1159                                         __update_localed_label_for_list(stmt, info);
1160
1161                                         memset(pre_appid, 0, MAX_QUERY_LEN);
1162                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1163
1164                                         continue;
1165                                 } else {
1166                                         memset(pre_appid, 0, MAX_QUERY_LEN);
1167                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1168                                 }
1169                         } else {
1170                                 strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1171                         }
1172
1173                         __get_appinfo_for_list(stmt, info);
1174                 } else {
1175                         break;
1176                 }
1177         }
1178
1179         /*head up*/
1180         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
1181
1182         /*UI Apps*/
1183         for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
1184         {
1185                 appinfo->locale = strdup(locale);
1186                 appinfo->uiapp_info = ptr1;
1187
1188                 ret = app_func((void *)appinfo, user_data);
1189                 if(ret < 0) {
1190                         FREE_AND_NULL(appinfo->locale);
1191                         break;
1192                 }
1193
1194                 FREE_AND_NULL(appinfo->locale);
1195         }
1196         ret = PMINFO_R_OK;
1197
1198 catch:
1199         FREE_AND_NULL(locale);
1200         sqlite3_free(query);
1201         sqlite3_finalize(stmt);
1202         sqlite3_close(appinfo_db);
1203         FREE_AND_NULL(appinfo);
1204         __cleanup_pkginfo(info);
1205         return ret;
1206 }
1207
1208 API int pkgmgrinfo_appinfo_get_unmounted_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
1209 {
1210         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
1211         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1212
1213         pkgmgr_appinfo_x *appinfo = NULL;
1214         char *locale = NULL;
1215         int ret = -1;
1216         int exist = 0;
1217         label_x *tmp1 = NULL;
1218         icon_x *tmp2 = NULL;
1219         category_x *tmp3 = NULL;
1220         metadata_x *tmp4 = NULL;
1221         permission_x *tmp5 = NULL;
1222         image_x *tmp6 = NULL;
1223         char *query = NULL;
1224         sqlite3 *appinfo_db = NULL;
1225         char *alias_id = NULL;
1226
1227         /*open db*/
1228         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
1229         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1230
1231         /*Get the alias id*/
1232         alias_id = __get_aliasid_from_db(appinfo_db,appid);
1233
1234         /*check alias_id exist on db*/
1235         query = sqlite3_mprintf("select exists(select * from package_app_info where app_id=%Q and app_disable='false')", alias_id);
1236         ret = __exec_db_query(appinfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist);
1237         sqlite3_free(query);
1238         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
1239         tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", alias_id);
1240
1241         /*get system locale*/
1242         locale = __convert_system_locale_to_manifest_locale();
1243         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
1244
1245         /*calloc appinfo*/
1246         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
1247         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
1248
1249         /*calloc app_component*/
1250         appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
1251         tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
1252
1253         appinfo->locale = strdup(locale);
1254
1255         /*populate app_info from DB*/
1256         query = sqlite3_mprintf("select * from package_app_info where app_id=%Q and app_disable='false' ", alias_id);
1257         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1258         sqlite3_free(query);
1259         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
1260
1261         query = sqlite3_mprintf("select * from package_app_localized_info where app_id=%Q and app_locale=%Q", alias_id, locale);
1262         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1263         sqlite3_free(query);
1264         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
1265
1266         /*Also store the values corresponding to default locales*/
1267         query = sqlite3_mprintf("select * from package_app_localized_info where app_id=%Q and app_locale=%Q", alias_id, DEFAULT_LOCALE);
1268         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1269         sqlite3_free(query);
1270         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
1271
1272         /*Populate app category*/
1273         query = sqlite3_mprintf("select * from package_app_app_category where app_id=%Q", alias_id);
1274         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1275         sqlite3_free(query);
1276         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
1277
1278         /*Populate app metadata*/
1279         query = sqlite3_mprintf("select * from package_app_app_metadata where app_id=%Q", alias_id);
1280         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1281         sqlite3_free(query);
1282         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
1283
1284         /*Populate app permission*/
1285         query = sqlite3_mprintf("select * from package_app_app_permission where app_id=%Q", alias_id);
1286         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1287         sqlite3_free(query);
1288         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
1289
1290         /*store setting notification icon section*/
1291         query = sqlite3_mprintf("select * from package_app_icon_section_info where app_id=%Q", alias_id);
1292         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1293         sqlite3_free(query);
1294         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
1295
1296         /*store app preview image info*/
1297         query = sqlite3_mprintf("select app_image_section, app_image from package_app_image_info where app_id=%Q", alias_id);
1298         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1299         sqlite3_free(query);
1300         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
1301
1302         SAFE_LISTHEAD(appinfo->uiapp_info->label, tmp1);
1303         SAFE_LISTHEAD(appinfo->uiapp_info->icon, tmp2);
1304         SAFE_LISTHEAD(appinfo->uiapp_info->category, tmp3);
1305         SAFE_LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
1306         SAFE_LISTHEAD(appinfo->uiapp_info->permission, tmp5);
1307         SAFE_LISTHEAD(appinfo->uiapp_info->image, tmp6);
1308
1309         ret = PMINFO_R_OK;
1310
1311 catch:
1312         if (ret == PMINFO_R_OK)
1313                 *handle = (void*)appinfo;
1314         else {
1315                 *handle = NULL;
1316                 __cleanup_appinfo(appinfo);
1317         }
1318
1319         sqlite3_close(appinfo_db);
1320         FREE_AND_NULL(locale);
1321         FREE_AND_NULL(alias_id);
1322         return ret;
1323 }
1324
1325 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
1326 {
1327         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
1328         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1329
1330         pkgmgr_appinfo_x *appinfo = NULL;
1331         char *locale = NULL;
1332         int ret = -1;
1333         int exist = 0;
1334         label_x *tmp1 = NULL;
1335         icon_x *tmp2 = NULL;
1336         category_x *tmp3 = NULL;
1337         metadata_x *tmp4 = NULL;
1338         permission_x *tmp5 = NULL;
1339         image_x *tmp6 = NULL;
1340         char *query = NULL;
1341         sqlite3 *appinfo_db = NULL;
1342         char *alias_id = NULL;
1343
1344         /*open db*/
1345         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
1346         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1347
1348         /*Get the alias id*/
1349         alias_id = __get_aliasid_from_db(appinfo_db,appid);
1350
1351         /*check alias_id exist on db*/
1352         query = sqlite3_mprintf("select exists(select * from package_app_info where app_id=%Q and app_disable='false')", alias_id);
1353         ret = __exec_db_query(appinfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist);
1354         sqlite3_free(query);
1355         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
1356         if (exist == 0) {
1357                 _LOGS("Appid[%s] not found in DB", alias_id);
1358                 ret = PMINFO_R_ERROR;
1359                 goto catch;
1360         }
1361
1362         /*get system locale*/
1363         locale = __convert_system_locale_to_manifest_locale();
1364         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
1365
1366         /*calloc appinfo*/
1367         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
1368         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
1369
1370         /*calloc app_component*/
1371         appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
1372         tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
1373
1374         appinfo->locale = strdup(locale);
1375
1376         /*populate app_info from DB*/
1377         query = sqlite3_mprintf("select * from package_app_info where app_id=%Q and app_disable='false' ", alias_id);
1378         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1379         sqlite3_free(query);
1380         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
1381
1382         query = sqlite3_mprintf("select * from package_app_localized_info where app_id=%Q and app_locale=%Q", alias_id, locale);
1383         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1384         sqlite3_free(query);
1385         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
1386
1387         /*Also store the values corresponding to default locales*/
1388         query = sqlite3_mprintf("select * from package_app_localized_info where app_id=%Q and app_locale=%Q", alias_id, DEFAULT_LOCALE);
1389         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1390         sqlite3_free(query);
1391         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
1392
1393         /*Populate app category*/
1394         query = sqlite3_mprintf("select * from package_app_app_category where app_id=%Q", alias_id);
1395         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1396         sqlite3_free(query);
1397         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
1398
1399         /*Populate app metadata*/
1400         query = sqlite3_mprintf("select * from package_app_app_metadata where app_id=%Q", alias_id);
1401         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1402         sqlite3_free(query);
1403         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
1404
1405         /*Populate app permission*/
1406         query = sqlite3_mprintf("select * from package_app_app_permission where app_id=%Q", alias_id);
1407         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1408         sqlite3_free(query);
1409         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
1410
1411         /*store setting notification icon section*/
1412         query = sqlite3_mprintf("select * from package_app_icon_section_info where app_id=%Q", alias_id);
1413         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1414         sqlite3_free(query);
1415         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
1416
1417         /*store app preview image info*/
1418         query = sqlite3_mprintf("select app_image_section, app_image from package_app_image_info where app_id=%Q", alias_id);
1419         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
1420         sqlite3_free(query);
1421         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
1422
1423         ret = __appinfo_check_installed_storage(appinfo);
1424         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "[%s] is installed external, but is not in mmc", appinfo->uiapp_info->package);
1425
1426         SAFE_LISTHEAD(appinfo->uiapp_info->label, tmp1);
1427         SAFE_LISTHEAD(appinfo->uiapp_info->icon, tmp2);
1428         SAFE_LISTHEAD(appinfo->uiapp_info->category, tmp3);
1429         SAFE_LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
1430         SAFE_LISTHEAD(appinfo->uiapp_info->permission, tmp5);
1431         SAFE_LISTHEAD(appinfo->uiapp_info->image, tmp6);
1432
1433         ret = PMINFO_R_OK;
1434
1435 catch:
1436         if (ret == PMINFO_R_OK)
1437                 *handle = (void*)appinfo;
1438         else {
1439                 *handle = NULL;
1440                 __cleanup_appinfo(appinfo);
1441         }
1442
1443         sqlite3_close(appinfo_db);
1444         FREE_AND_NULL(locale);
1445         FREE_AND_NULL(alias_id);
1446         return ret;
1447 }
1448
1449
1450 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
1451 {
1452         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1453         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1454         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1455
1456         *appid = (char *)info->uiapp_info->appid;
1457
1458         return PMINFO_R_OK;
1459 }
1460
1461 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h  handle, char **pkg_name)
1462 {
1463         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1464         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1465         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1466
1467         *pkg_name = (char *)info->uiapp_info->package;
1468
1469         return PMINFO_R_OK;
1470 }
1471
1472 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h  handle, char **pkgid)
1473 {
1474         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1475         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1476         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1477
1478         *pkgid = (char *)info->uiapp_info->package;
1479
1480         return PMINFO_R_OK;
1481 }
1482
1483 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1484 {
1485         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1486         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1487         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1488
1489         *pkgtype = (char *)info->uiapp_info->package_type;
1490
1491         return PMINFO_R_OK;
1492 }
1493
1494 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h  handle, char **exec)
1495 {
1496         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1497         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1498         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1499
1500         *exec = (char *)info->uiapp_info->exec;
1501
1502         return PMINFO_R_OK;
1503 }
1504
1505
1506 API int pkgmgrinfo_appinfo_get_ambient_support(pkgmgrinfo_appinfo_h  handle, bool *ambient_support)
1507 {
1508         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1509         retvm_if(ambient_support == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1510         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1511         char *val = NULL;
1512         bool is_support = false;
1513
1514         val = (char *)info->uiapp_info->ambient_support;
1515         if (val) {
1516                 if (strcasecmp(val, "true") == 0)
1517                         is_support = true;
1518         }
1519
1520         *ambient_support = is_support;
1521
1522         return PMINFO_R_OK;
1523 }
1524
1525 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
1526 {
1527         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1528         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1529
1530     char *locale = NULL;
1531     icon_x *ptr = NULL;
1532     icon_x *start = NULL;
1533     *icon = NULL;
1534
1535     pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1536         locale = info->locale;
1537         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1538
1539         start = info->uiapp_info->icon;
1540
1541     for(ptr = start; ptr != NULL; ptr = ptr->next)
1542     {
1543             if (ptr->lang) {
1544                     if (strcmp(ptr->lang, locale) == 0) {
1545                                                 if (ptr->text) {
1546                             *icon = (char *)ptr->text;
1547                             if (strcasecmp(*icon, PKGMGR_PARSER_EMPTY_STR) == 0) {
1548                                     locale = DEFAULT_LOCALE;
1549                                     continue;
1550                             } else
1551                                     break;
1552                                                 } else {
1553                                                         locale = DEFAULT_LOCALE;
1554                                                         continue;
1555                                                 }
1556                     } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1557                             *icon = (char *)ptr->text;
1558                             break;
1559                     }
1560             }
1561     }
1562         return PMINFO_R_OK;
1563 }
1564
1565
1566 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
1567 {
1568         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1569         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1570         int ret = 0;
1571         char *locale = NULL;
1572         label_x *ptr = NULL;
1573         label_x *start = NULL;
1574         *label = NULL;
1575
1576         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1577         locale = info->locale;
1578         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1579
1580         ret = __sat_ui_get_label(handle, label);
1581         retvm_if(ret == PMINFO_R_OK, PMINFO_R_OK, "sat ui(%s) is enabled", (char *)info->uiapp_info->appid);
1582
1583         start = info->uiapp_info->label;
1584
1585         for(ptr = start; ptr != NULL; ptr = ptr->next)
1586         {
1587                 if (ptr->lang) {
1588                         if (strcmp(ptr->lang, locale) == 0) {
1589                                 if (ptr->text) {
1590                                         *label = (char *)ptr->text;
1591                                         if (strcasecmp(*label, PKGMGR_PARSER_EMPTY_STR) == 0) {
1592                                                 locale = DEFAULT_LOCALE;
1593                                                 continue;
1594                                         } else
1595                                                 break;
1596                                 } else {
1597                                         locale = DEFAULT_LOCALE;
1598                                         continue;
1599                                 }
1600                         } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
1601                                 *label = (char *)ptr->text;
1602                                 if (ptr->text) {
1603                                         if (strcasecmp(*label, PKGMGR_PARSER_EMPTY_STR) == 0) {
1604                                                         locale = DEFAULT_LOCALE;
1605                                                         continue;
1606                                         } else
1607                                                         break;
1608                                 } else {
1609                                         locale = DEFAULT_LOCALE;
1610                                         continue;
1611                                 }
1612                         } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1613                                 *label = (char *)ptr->text;
1614                                 break;
1615                         }
1616                 }
1617         }
1618         return PMINFO_R_OK;
1619 }
1620
1621
1622 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_component *component)
1623 {
1624         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1625         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1626
1627         *component = PMINFO_UI_APP;
1628
1629         return PMINFO_R_OK;
1630 }
1631
1632 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h  handle, char **app_type)
1633 {
1634         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1635         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1636         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1637
1638         *app_type = (char *)info->uiapp_info->type;
1639
1640         return PMINFO_R_OK;
1641 }
1642
1643 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1644                                         int *operation_count, char ***operation)
1645 {
1646         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1647         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1648         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1649         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1650         *operation_count = data->operation_count;
1651         *operation = data->operation;
1652         return PMINFO_R_OK;
1653 }
1654
1655 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1656                                         int *uri_count, char ***uri)
1657 {
1658         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1659         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1660         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1661         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1662         *uri_count = data->uri_count;
1663         *uri = data->uri;
1664         return PMINFO_R_OK;
1665 }
1666
1667 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1668                                         int *mime_count, char ***mime)
1669 {
1670         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1671         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1672         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1673         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1674         *mime_count = data->mime_count;
1675         *mime = data->mime;
1676         return PMINFO_R_OK;
1677 }
1678
1679 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1680                                         int *subapp_count, char ***subapp)
1681 {
1682         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1683         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1684         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1685         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1686         *subapp_count = data->subapp_count;
1687         *subapp = data->subapp;
1688         return PMINFO_R_OK;
1689 }
1690
1691 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
1692 {
1693         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1694         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1695
1696         char *val = NULL;
1697         icon_x *ptr = NULL;
1698         icon_x *start = NULL;
1699         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1700
1701         start = info->uiapp_info->icon;
1702
1703         for(ptr = start; ptr != NULL; ptr = ptr->next)
1704         {
1705                 if (ptr->section) {
1706                         val = (char *)ptr->section;
1707                         if (strcmp(val, "setting") == 0){
1708                                 *icon = (char *)ptr->text;
1709                                 break;
1710                         }
1711                 }
1712         }
1713         return PMINFO_R_OK;
1714 }
1715
1716 API int pkgmgrinfo_appinfo_get_small_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
1717 {
1718         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1719         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1720
1721         char *val = NULL;
1722         icon_x *ptr = NULL;
1723         icon_x *start = NULL;
1724         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1725
1726         start = info->uiapp_info->icon;
1727
1728         for(ptr = start; ptr != NULL; ptr = ptr->next)
1729         {
1730                 if (ptr->section) {
1731                         val = (char *)ptr->section;
1732                         if (strcmp(val, "small") == 0){
1733                                 *icon = (char *)ptr->text;
1734                                 break;
1735                         }
1736                 }
1737         }
1738
1739         return PMINFO_R_OK;
1740 }
1741
1742 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
1743 {
1744         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1745         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1746
1747         char *val = NULL;
1748         icon_x *ptr = NULL;
1749         icon_x *start = NULL;
1750         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1751
1752         start = info->uiapp_info->icon;
1753
1754         for(ptr = start; ptr != NULL; ptr = ptr->next)
1755         {
1756                 if (ptr->section) {
1757                         val = (char *)ptr->section;
1758
1759                         if (strcmp(val, "notification") == 0){
1760                                 *icon = (char *)ptr->text;
1761                                 break;
1762                         }
1763                 }
1764         }
1765
1766         return PMINFO_R_OK;
1767 }
1768
1769 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_recentimage *type)
1770 {
1771         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1772         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1773         char *val = NULL;
1774         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1775         val = (char *)info->uiapp_info->recentimage;
1776         if (val) {
1777                 if (strcasecmp(val, "capture") == 0)
1778                         *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1779                 else if (strcasecmp(val, "icon") == 0)
1780                         *type = PMINFO_RECENTIMAGE_USE_ICON;
1781                 else
1782                         *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1783         }
1784
1785         return PMINFO_R_OK;
1786 }
1787
1788 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h  handle, char **preview_img)
1789 {
1790         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1791         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1792
1793         char *val = NULL;
1794         image_x *ptr = NULL;
1795         image_x *start = NULL;
1796         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1797
1798         start = info->uiapp_info->image;
1799
1800         for(ptr = start; ptr != NULL; ptr = ptr->next)
1801         {
1802                 if (ptr->section) {
1803                         val = (char *)ptr->section;
1804
1805                         if (strcmp(val, "preview") == 0)
1806                                 *preview_img = (char *)ptr->text;
1807
1808                         break;
1809                 }
1810         }
1811         return PMINFO_R_OK;
1812 }
1813
1814 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_permission_type *permission)
1815 {
1816         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1817         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1818
1819         char *val = NULL;
1820         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1821
1822         val = (char*)info->uiapp_info->permission_type;
1823
1824         if (strcmp(val, "signature") == 0)
1825                 *permission = PMINFO_PERMISSION_SIGNATURE;
1826         else if (strcmp(val, "privilege") == 0)
1827                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1828         else
1829                 *permission = PMINFO_PERMISSION_NORMAL;
1830
1831         return PMINFO_R_OK;
1832 }
1833
1834 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h  handle, char **component_type)
1835 {
1836         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1837         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1838         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1839
1840         *component_type = (char *)info->uiapp_info->component_type;
1841
1842         return PMINFO_R_OK;
1843 }
1844
1845 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1846 {
1847         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1848         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1849         char *val = NULL;
1850         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1851         val = (char *)info->uiapp_info->hwacceleration;
1852         if (val) {
1853                 if (strcasecmp(val, "off") == 0)
1854                         *hwacceleration = PMINFO_HWACCELERATION_OFF;
1855                 else if (strcasecmp(val, "on") == 0)
1856                         *hwacceleration = PMINFO_HWACCELERATION_ON;
1857                 else
1858                         *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1859         }
1860         return PMINFO_R_OK;
1861 }
1862
1863 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_screenreader *screenreader)
1864 {
1865         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1866         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1867         char *val = NULL;
1868         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1869         val = (char *)info->uiapp_info->screenreader;
1870         if (val) {
1871                 if (strcasecmp(val, "screenreader-off") == 0)
1872                         *screenreader = PMINFO_SCREENREADER_OFF;
1873                 else if (strcasecmp(val, "screenreader-on") == 0)
1874                         *screenreader = PMINFO_SCREENREADER_ON;
1875                 else
1876                         *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1877         }
1878         return PMINFO_R_OK;
1879 }
1880
1881 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h  handle, char **portrait_img, char **landscape_img)
1882 {
1883         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1884         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1885         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1886         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1887
1888         *portrait_img = (char *)info->uiapp_info->portraitimg;
1889         *landscape_img = (char *)info->uiapp_info->landscapeimg;
1890
1891         return PMINFO_R_OK;
1892 }
1893
1894 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h  handle, char **effectimg_type)
1895 {
1896         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1897         retvm_if(effectimg_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1898         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1899
1900         *effectimg_type = (char *)info->uiapp_info->effectimage_type;
1901
1902         return PMINFO_R_OK;
1903 }
1904
1905 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
1906 {
1907         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1908         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1909         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1910
1911         *submode_mainid = (char *)info->uiapp_info->submode_mainid;
1912
1913         return PMINFO_R_OK;
1914 }
1915
1916 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1917 {
1918         int col = 0;
1919         int cols = 0;
1920         int ret = -1;
1921         char *val = NULL;
1922         char *localed_label = NULL;
1923         char *query = NULL;
1924
1925         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1926
1927         sqlite3_stmt *stmt = NULL;
1928         sqlite3 *pkgmgr_parser_db = NULL;
1929         char *alias_id = NULL;
1930
1931         ret = db_util_open(MANIFEST_DB, &pkgmgr_parser_db, 0);
1932         if (ret != SQLITE_OK) {
1933                 _LOGE("DB open fail\n");
1934                 return -1;
1935         }
1936
1937         /*Get the alias id*/
1938         alias_id = __get_aliasid_from_db(pkgmgr_parser_db,appid);
1939
1940         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", alias_id, locale);
1941
1942
1943         ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
1944         if (ret != SQLITE_OK) {
1945                 _LOGE("prepare_v2 fail\n");
1946                 sqlite3_close(pkgmgr_parser_db);
1947                 sqlite3_free(query);
1948                 FREE_AND_NULL(alias_id);
1949                 return -1;
1950         }
1951
1952         cols = sqlite3_column_count(stmt);
1953         while(1)
1954         {
1955                 ret = sqlite3_step(stmt);
1956                 if(ret == SQLITE_ROW) {
1957                         for(col = 0; col < cols; col++)
1958                         {
1959                                 val = (char*)sqlite3_column_text(stmt, col);
1960                                 if (val == NULL)
1961                                         break;
1962
1963                                 _LOGE("success find localed_label[%s]\n", val);
1964                                 FREE_AND_NULL(localed_label);
1965                                 localed_label = strdup(val);
1966                                 if (localed_label == NULL)
1967                                         break;
1968
1969                                 *label = localed_label;
1970
1971
1972                         }
1973                         ret = 0;
1974                 } else {
1975                         break;
1976                 }
1977         }
1978
1979         /*find default label when exact matching failed*/
1980         if (localed_label == NULL) {
1981                 sqlite3_free(query);
1982                 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", alias_id, DEFAULT_LOCALE);
1983                 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
1984                 if (ret != SQLITE_OK) {
1985                         _LOGE("prepare_v2 fail\n");
1986                         sqlite3_close(pkgmgr_parser_db);
1987                         sqlite3_free(query);
1988                         FREE_AND_NULL(alias_id);
1989                         return -1;
1990                 }
1991
1992                 cols = sqlite3_column_count(stmt);
1993                 while(1)
1994                 {
1995                         ret = sqlite3_step(stmt);
1996                         if(ret == SQLITE_ROW) {
1997                                 for(col = 0; col < cols; col++)
1998                                 {
1999                                         val = (char*)sqlite3_column_text(stmt, col);
2000                                         if (val == NULL)
2001                                                 break;
2002                                         _LOGE("success find default localed_label[%s]\n", val);
2003                                         FREE_AND_NULL(localed_label);
2004                                         localed_label = strdup(val);
2005                                         if (localed_label == NULL)
2006                                                 break;
2007                                         *label = localed_label;
2008                                 }
2009                                 ret = 0;
2010                         } else {
2011                                 break;
2012                         }
2013                 }
2014
2015         }
2016
2017         FREE_AND_NULL(alias_id);
2018         sqlite3_finalize(stmt);
2019         sqlite3_close(pkgmgr_parser_db);
2020         sqlite3_free(query);
2021
2022         if (localed_label == NULL) {
2023                 return PMINFO_R_ERROR;
2024         } else {
2025                 return PMINFO_R_OK;
2026         }
2027 }
2028
2029 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
2030 {
2031         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2032         retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
2033         retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
2034
2035         metadata_x *ptr = NULL;
2036         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2037
2038         ptr = info->uiapp_info->metadata;
2039
2040         for (; ptr; ptr = ptr->next) {
2041                 if (ptr->key) {
2042                         if (strcasecmp(ptr->key, metadata_key) == 0)
2043                         {
2044                                 *metadata_value = (char*)ptr->value;
2045                                 return PMINFO_R_OK;
2046                         }
2047                 }
2048         }
2049
2050         return PMINFO_R_EINVAL;
2051 }
2052
2053 API int pkgmgrinfo_appinfo_get_multi_instance_mainid(pkgmgrinfo_appinfo_h  handle, char **multi_instance_mainid)
2054 {
2055         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2056         retvm_if(multi_instance_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2057         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2058
2059         *multi_instance_mainid = (char *)info->uiapp_info->multi_instance_mainid;
2060
2061         return PMINFO_R_OK;
2062 }
2063
2064 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
2065 {
2066         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2067         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2068         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2069         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2070
2071         int ret = PMINFO_R_OK;
2072         char *query = NULL;
2073         sqlite3 *appinfo_db = NULL;
2074         sqlite3_stmt *stmt = NULL;
2075
2076         /*open db*/
2077         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
2078         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2079
2080         /*Start constructing query*/
2081         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2082
2083         /*prepare query*/
2084         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
2085         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2086
2087         /*step query*/
2088         ret = sqlite3_step(stmt);
2089         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2090
2091         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2092         *access = strdup((char *)sqlite3_column_text(stmt, 2));
2093
2094         ret = PMINFO_R_OK;
2095
2096 catch:
2097         sqlite3_free(query);
2098         sqlite3_finalize(stmt);
2099         sqlite3_close(appinfo_db);
2100         return ret;
2101 }
2102
2103 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2104 {
2105         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2106         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2107
2108         int ret = PMINFO_R_OK;
2109         char *query = NULL;
2110         sqlite3 *appinfo_db = NULL;
2111         sqlite3_stmt *stmt = NULL;
2112
2113         /*open db*/
2114         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
2115         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2116
2117         /*Start constructing query*/
2118         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2119
2120         /*prepare query*/
2121         ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
2122         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2123
2124         /*step query*/
2125         ret = sqlite3_step(stmt);
2126         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2127
2128         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2129
2130         ret = PMINFO_R_OK;
2131
2132 catch:
2133         sqlite3_free(query);
2134         sqlite3_finalize(stmt);
2135         sqlite3_close(appinfo_db);
2136         return ret;
2137 }
2138
2139 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h  handle, int *support_mode)
2140 {
2141         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2142         retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2143
2144         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2145         if (info->uiapp_info->support_mode)
2146                 *support_mode = atoi(info->uiapp_info->support_mode);
2147         else
2148                 *support_mode = 0;
2149
2150         return PMINFO_R_OK;
2151 }
2152
2153 API int pkgmgrinfo_appinfo_get_support_feature(pkgmgrinfo_appinfo_h  handle, int *support_feature)
2154 {
2155         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2156         retvm_if(support_feature == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2157
2158         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2159         if (info->uiapp_info->support_feature)
2160                 *support_feature = atoi(info->uiapp_info->support_feature);
2161         else
2162                 *support_feature = 0;
2163
2164         return PMINFO_R_OK;
2165 }
2166
2167 API int pkgmgrinfo_appinfo_get_uginfo(const char *ug_name, pkgmgrinfo_appinfo_h *handle)
2168 {
2169         retvm_if(ug_name == NULL, PMINFO_R_EINVAL, "ug_name is NULL");
2170         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2171
2172         pkgmgr_appinfo_x *appinfo = NULL;
2173         int ret = -1;
2174         char *query = NULL;
2175         sqlite3 *appinfo_db = NULL;
2176
2177         /*open db*/
2178         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
2179         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2180
2181         /*calloc appinfo*/
2182         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
2183         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
2184
2185         /*calloc app_component*/
2186         appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
2187         tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
2188
2189         /*populate app_info from DB*/
2190         query = sqlite3_mprintf("select * from package_app_info where app_ui_gadget='true' and app_exec like '%%%s'", ug_name);
2191         ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
2192         sqlite3_free(query);
2193         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
2194
2195         ret = __appinfo_check_installed_storage(appinfo);
2196         tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "[%s] is installed external, but is not in mmc", appinfo->uiapp_info->package);
2197
2198         ret = PMINFO_R_OK;
2199
2200 catch:
2201         if (ret == PMINFO_R_OK)
2202                 *handle = (void*)appinfo;
2203         else {
2204                 *handle = NULL;
2205                 __cleanup_appinfo(appinfo);
2206         }
2207
2208         sqlite3_close(appinfo_db);
2209
2210         return ret;
2211 }
2212
2213 /*Get the alias id for an appid from pkgmgr DB*/
2214 API int  pkgmgrinfo_appinfo_get_aliasid(const char *appid, char **alias_id)
2215 {
2216
2217         sqlite3 *appinfo_db = NULL;
2218         int ret = PMINFO_R_OK;
2219
2220         retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
2221         retvm_if(alias_id == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2222
2223         /*open db */
2224         ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
2225         tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2226
2227         *alias_id = __get_aliasid_from_db(appinfo_db,appid);
2228 catch:
2229
2230         sqlite3_close(appinfo_db);
2231         return ret;
2232 }
2233
2234 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2235 {
2236         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2237         retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2238         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2239         if (info->uiapp_info->package_installed_time)
2240                 *installed_time = atoi(info->uiapp_info->package_installed_time);
2241         else
2242                 return PMINFO_R_ERROR;
2243
2244         return PMINFO_R_OK;
2245 }
2246
2247 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
2248                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
2249 {
2250         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2251         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2252         int ret = -1;
2253         permission_x *ptr = NULL;
2254         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2255
2256         ptr = info->uiapp_info->permission;
2257
2258         for (; ptr; ptr = ptr->next) {
2259                 if (ptr->value) {
2260                         ret = permission_func(ptr->value, user_data);
2261                         if (ret < 0)
2262                                 break;
2263                 }
2264         }
2265         return PMINFO_R_OK;
2266 }
2267
2268 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2269                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2270 {
2271         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2272         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2273         int ret = -1;
2274         category_x *ptr = NULL;
2275         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2276
2277         ptr = info->uiapp_info->category;
2278
2279         for (; ptr; ptr = ptr->next) {
2280                 if (ptr->name) {
2281                         ret = category_func(ptr->name, user_data);
2282                         if (ret < 0)
2283                                 break;
2284                 }
2285         }
2286         return PMINFO_R_OK;
2287 }
2288
2289 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2290                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2291 {
2292         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2293         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2294         int ret = -1;
2295         metadata_x *ptr = NULL;
2296         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2297
2298         ptr = info->uiapp_info->metadata;
2299
2300         for (; ptr; ptr = ptr->next) {
2301                 if (ptr->key) {
2302                         ret = metadata_func(ptr->key, ptr->value, user_data);
2303                         if (ret < 0)
2304                                 break;
2305                 }
2306         }
2307         return PMINFO_R_OK;
2308 }
2309
2310 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2311                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2312 {
2313         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2314         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2315         int i = 0;
2316         int ret = -1;
2317         int oc = 0;
2318         int mc = 0;
2319         int uc = 0;
2320         int sc = 0;
2321         char *pkgid = NULL;
2322         char *manifest = NULL;
2323         char **operation = NULL;
2324         char **uri = NULL;
2325         char **mime = NULL;
2326         char **subapp = NULL;
2327         appsvc_x *appsvc = NULL;
2328         manifest_x *mfx = NULL;
2329         operation_x *op = NULL;
2330         uri_x *ui = NULL;
2331         mime_x *mi = NULL;
2332         subapp_x *sa = NULL;
2333         pkgmgrinfo_app_component component;
2334         pkgmgrinfo_appcontrol_x *ptr = NULL;
2335         ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
2336         if (ret < 0) {
2337                 _LOGE("Failed to get package name\n");
2338                 return PMINFO_R_ERROR;
2339         }
2340         ret = pkgmgrinfo_appinfo_get_component(handle, &component);
2341         if (ret < 0) {
2342                 _LOGE("Failed to get app component name\n");
2343                 return PMINFO_R_ERROR;
2344         }
2345         manifest = pkgmgr_parser_get_manifest_file(pkgid);
2346         if (manifest == NULL) {
2347                 _LOGE("Failed to fetch package manifest file\n");
2348                 return PMINFO_R_ERROR;
2349         }
2350         mfx = pkgmgr_parser_process_manifest_xml(manifest);
2351         if (mfx == NULL) {
2352                 _LOGE("Failed to parse package manifest file\n");
2353                 FREE_AND_NULL(manifest);
2354                 return PMINFO_R_ERROR;
2355         }
2356         FREE_AND_NULL(manifest);
2357         ptr  = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
2358         if (ptr == NULL) {
2359                 _LOGE("Out of Memory!!!\n");
2360                 pkgmgr_parser_free_manifest_xml(mfx);
2361                 return PMINFO_R_ERROR;
2362         }
2363         /*Get Operation, Uri, Mime*/
2364         if (mfx->uiapplication) {
2365                 if (mfx->uiapplication->appsvc) {
2366                         appsvc = mfx->uiapplication->appsvc;
2367                 }
2368         }
2369
2370         for (; appsvc; appsvc = appsvc->next) {
2371                 op = appsvc->operation;
2372                 for (; op; op = op->next)
2373                         oc = oc + 1;
2374                 op = appsvc->operation;
2375
2376                 ui = appsvc->uri;
2377                 for (; ui; ui = ui->next)
2378                         uc = uc + 1;
2379                 ui = appsvc->uri;
2380
2381                 mi = appsvc->mime;
2382                 for (; mi; mi = mi->next)
2383                         mc = mc + 1;
2384                 mi = appsvc->mime;
2385
2386                 sa = appsvc->subapp;
2387                 for (; sa; sa = sa->next)
2388                         sc = sc + 1;
2389                 sa = appsvc->subapp;
2390
2391                 operation = (char **)calloc(oc, sizeof(char *));
2392                 if (operation == NULL) {
2393                         _LOGE("out of memory");
2394                         break;
2395                 }
2396
2397                 for (i = 0; i < oc; i++) {
2398                         operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
2399                         op = op->next;
2400                 }
2401
2402                 uri = (char **)calloc(uc, sizeof(char *));
2403                 if (uri == NULL) {
2404                         _LOGE("out of memory");
2405                         for (i = 0; i < oc; i++) {
2406                                 FREE_AND_NULL(operation[i]);
2407                         }
2408                         FREE_AND_NULL(operation);
2409                         break;
2410                 }
2411
2412                 for (i = 0; i < uc; i++) {
2413                         uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
2414                         ui = ui->next;
2415                 }
2416
2417                 mime = (char **)calloc(mc, sizeof(char *));
2418                 if (mime == NULL) {
2419                         _LOGE("out of memory");
2420                         for (i = 0; i < uc; i++) {
2421                                 FREE_AND_NULL(uri[i]);
2422                         }
2423                         FREE_AND_NULL(uri);
2424                         for (i = 0; i < oc; i++) {
2425                                 FREE_AND_NULL(operation[i]);
2426                         }
2427                         FREE_AND_NULL(operation);
2428                         break;
2429                 }
2430
2431                 for (i = 0; i < mc; i++) {
2432                         mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
2433                         mi = mi->next;
2434                 }
2435
2436                 subapp = (char **)calloc(sc, sizeof(char *));
2437                 if (subapp == NULL) {
2438                         _LOGE("out of memory");
2439                         for (i = 0; i < mc; i++) {
2440                                 FREE_AND_NULL(mime[i]);
2441                         }
2442                         FREE_AND_NULL(mime);
2443                         for (i = 0; i < uc; i++) {
2444                                 FREE_AND_NULL(uri[i]);
2445                         }
2446                         FREE_AND_NULL(uri);
2447                         for (i = 0; i < oc; i++) {
2448                                 FREE_AND_NULL(operation[i]);
2449                         }
2450                         FREE_AND_NULL(operation);
2451                         break;
2452                 }
2453
2454                 for (i = 0; i < sc; i++) {
2455                         subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
2456                         sa = sa->next;
2457                 }
2458
2459                 /*populate appcontrol handle*/
2460                 ptr->operation_count = oc;
2461                 ptr->uri_count = uc;
2462                 ptr->mime_count = mc;
2463                 ptr->subapp_count = sc;
2464                 ptr->operation = operation;
2465                 ptr->uri = uri;
2466                 ptr->mime = mime;
2467                 ptr->subapp = subapp;
2468
2469                 ret = appcontrol_func((void *)ptr, user_data);
2470                 for (i = 0; i < oc; i++) {
2471                         FREE_AND_NULL(operation[i]);
2472                 }
2473                 FREE_AND_NULL(operation);
2474                 for (i = 0; i < uc; i++) {
2475                         FREE_AND_NULL(uri[i]);
2476                 }
2477                 FREE_AND_NULL(uri);
2478                 for (i = 0; i < mc; i++) {
2479                         FREE_AND_NULL(mime[i]);
2480                 }
2481                 FREE_AND_NULL(mime);
2482                 for (i = 0; i < sc; i++) {
2483                         FREE_AND_NULL(subapp[i]);
2484                 }
2485                 FREE_AND_NULL(subapp);
2486                 if (ret < 0)
2487                         break;
2488                 uc = 0;
2489                 mc = 0;
2490                 oc = 0;
2491                 sc = 0;
2492         }
2493         pkgmgr_parser_free_manifest_xml(mfx);
2494         FREE_AND_NULL(ptr);
2495         return PMINFO_R_OK;
2496 }
2497
2498 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h  handle, bool *nodisplay)
2499 {
2500         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2501         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2502         char *val = NULL;
2503         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2504         val = (char *)info->uiapp_info->nodisplay;
2505         if (val) {
2506                 if (strcasecmp(val, "true") == 0)
2507                         *nodisplay = 1;
2508                 else if (strcasecmp(val, "false") == 0)
2509                         *nodisplay = 0;
2510                 else
2511                         *nodisplay = 0;
2512         }
2513         return PMINFO_R_OK;
2514 }
2515
2516 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h  handle, bool *multiple)
2517 {
2518         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2519         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2520         char *val = NULL;
2521         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2522         val = (char *)info->uiapp_info->multiple;
2523         if (val) {
2524                 if (strcasecmp(val, "true") == 0)
2525                         *multiple = 1;
2526                 else if (strcasecmp(val, "false") == 0)
2527                         *multiple = 0;
2528                 else
2529                         *multiple = 0;
2530         }
2531         return PMINFO_R_OK;
2532 }
2533
2534 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2535 {
2536         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2537         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2538         char *val = NULL;
2539         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2540         val = (char *)info->uiapp_info->indicatordisplay;
2541         if (val) {
2542                 if (strcasecmp(val, "true") == 0){
2543                         *indicator_disp = 1;
2544                 }else if (strcasecmp(val, "false") == 0){
2545                         *indicator_disp = 0;
2546                 }else{
2547                         *indicator_disp = 0;
2548                 }
2549         }
2550         return PMINFO_R_OK;
2551 }
2552
2553 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2554 {
2555         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2556         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2557         char *val = NULL;
2558         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2559         val = (char *)info->uiapp_info->taskmanage;
2560         if (val) {
2561                 if (strcasecmp(val, "true") == 0)
2562                         *taskmanage = 1;
2563                 else if (strcasecmp(val, "false") == 0)
2564                         *taskmanage = 0;
2565                 else
2566                         *taskmanage = 0;
2567         }
2568         return PMINFO_R_OK;
2569 }
2570
2571 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2572 {
2573         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2574         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2575         int ret = 0;
2576         char *val = NULL;
2577         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2578
2579         ret = __sat_ui_is_enabled((char *)info->uiapp_info->appid, enabled);
2580         retvm_if(ret == PMINFO_R_OK, PMINFO_R_OK, "sat ui(%s) is enabled", (char *)info->uiapp_info->appid);
2581
2582         val = (char *)info->uiapp_info->enabled;
2583
2584         if (val) {
2585                 if (strcasecmp(val, "true") == 0)
2586                         *enabled = 1;
2587                 else if (strcasecmp(val, "false") == 0)
2588                         *enabled = 0;
2589                 else
2590                         *enabled = 1;
2591         }
2592         return PMINFO_R_OK;
2593
2594 }
2595
2596 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2597 {
2598         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2599         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2600         char *val = NULL;
2601         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2602
2603         val = (char *)info->uiapp_info->onboot;
2604
2605         if (val) {
2606                 if (strcasecmp(val, "true") == 0)
2607                         *onboot = 1;
2608                 else if (strcasecmp(val, "false") == 0)
2609                         *onboot = 0;
2610                 else
2611                         *onboot = 0;
2612         }
2613         return PMINFO_R_OK;
2614 }
2615
2616 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2617 {
2618         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2619         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2620         char *val = NULL;
2621         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2622
2623         val = (char *)info->uiapp_info->autorestart;
2624
2625         if (val) {
2626                 if (strcasecmp(val, "true") == 0)
2627                         *autorestart = 1;
2628                 else if (strcasecmp(val, "false") == 0)
2629                         *autorestart = 0;
2630                 else
2631                         *autorestart = 0;
2632         }
2633         return PMINFO_R_OK;
2634 }
2635
2636 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2637 {
2638         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2639         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2640         char *val = NULL;
2641         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2642         val = (char *)info->uiapp_info->mainapp;
2643         if (val) {
2644                 if (strcasecmp(val, "true") == 0)
2645                         *mainapp = 1;
2646                 else if (strcasecmp(val, "false") == 0)
2647                         *mainapp = 0;
2648                 else
2649                         *mainapp = 0;
2650         }
2651         return PMINFO_R_OK;
2652 }
2653
2654 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2655 {
2656         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2657         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2658         char *val = NULL;
2659         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2660         val = (char *)info->uiapp_info->preload;
2661         if (val) {
2662                 if (strcasecmp(val, "true") == 0)
2663                         *preload = 1;
2664                 else if (strcasecmp(val, "false") == 0)
2665                         *preload = 0;
2666                 else
2667                         *preload = 0;
2668         }
2669         return PMINFO_R_OK;
2670 }
2671
2672 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2673 {
2674         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2675         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2676         char *val = NULL;
2677         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2678         val = (char *)info->uiapp_info->submode;
2679         if (val) {
2680                 if (strcasecmp(val, "true") == 0)
2681                         *submode = 1;
2682                 else if (strcasecmp(val, "false") == 0)
2683                         *submode = 0;
2684                 else
2685                         *submode = 0;
2686         }
2687         return PMINFO_R_OK;
2688 }
2689
2690 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2691 {
2692         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2693         retvm_if(process_pool == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2694         char *val = NULL;
2695         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2696         val = (char *)info->uiapp_info->process_pool;
2697         if (val) {
2698                 if (strcasecmp(val, "true") == 0)
2699                         *process_pool = 1;
2700                 else if (strcasecmp(val, "false") == 0)
2701                         *process_pool = 0;
2702                 else
2703                         *process_pool = 0;
2704         }
2705         return PMINFO_R_OK;
2706 }
2707
2708 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2709 {
2710         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2711         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2712         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2713
2714         category_x *ptr = NULL;
2715         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2716
2717         *exist = 0;
2718
2719         ptr = info->uiapp_info->category;
2720
2721         for (; ptr; ptr = ptr->next) {
2722                 if (ptr->name) {
2723                         if (strcasecmp(ptr->name, category) == 0)
2724                         {
2725                                 *exist = 1;
2726                                 break;
2727                         }
2728                 }
2729         }
2730
2731         return PMINFO_R_OK;
2732 }
2733
2734 API int pkgmgrinfo_appinfo_is_multi_instance(pkgmgrinfo_appinfo_h handle, bool *multi_instance)
2735 {
2736         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2737         retvm_if(multi_instance == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2738         char *val = NULL;
2739         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2740         val = (char *)info->uiapp_info->multi_instance;
2741         if (val) {
2742                 if (strcasecmp(val, "true") == 0)
2743                         *multi_instance = 1;
2744                 else if (strcasecmp(val, "false") == 0)
2745                         *multi_instance = 0;
2746                 else
2747                         *multi_instance = 0;
2748         }
2749         return PMINFO_R_OK;
2750 }
2751
2752 API int pkgmgrinfo_appinfo_is_multi_window(pkgmgrinfo_appinfo_h handle, bool *multi_window)
2753 {
2754         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2755         retvm_if(multi_window == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2756         char *val = NULL;
2757         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2758         val = (char *)info->uiapp_info->multi_window;
2759         if (val) {
2760                 if (strcasecmp(val, "true") == 0)
2761                         *multi_window = 1;
2762                 else if (strcasecmp(val, "false") == 0)
2763                         *multi_window = 0;
2764                 else
2765                         *multi_window = 0;
2766         }
2767         return PMINFO_R_OK;
2768 }
2769
2770 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle, bool *support_disable)
2771 {
2772         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2773         retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2774         char *val = NULL;
2775         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2776         val = (char *)info->uiapp_info->support_disable;
2777         if (val) {
2778                 if (strcasecmp(val, "true") == 0)
2779                         *support_disable = 1;
2780                 else if (strcasecmp(val, "false") == 0)
2781                         *support_disable = 0;
2782                 else
2783                         *support_disable = 0;
2784         }
2785         return PMINFO_R_OK;
2786 }
2787
2788 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle, bool *ui_gadget)
2789 {
2790         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2791         retvm_if(ui_gadget == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2792         char *val = NULL;
2793         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2794         val = (char *)info->uiapp_info->ui_gadget;
2795         if (val) {
2796                 if (strcasecmp(val, "true") == 0)
2797                         *ui_gadget = 1;
2798                 else if (strcasecmp(val, "false") == 0)
2799                         *ui_gadget = 0;
2800                 else
2801                         *ui_gadget = 0;
2802         }
2803         return PMINFO_R_OK;
2804 }
2805
2806 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle, bool *removable)
2807 {
2808         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2809         retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2810         char *val = NULL;
2811         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2812         val = (char *)info->uiapp_info->removable;
2813         if (val) {
2814                 if (strcasecmp(val, "true") == 0)
2815                         *removable = 1;
2816                 else if (strcasecmp(val, "false") == 0)
2817                         *removable = 0;
2818                 else
2819                         *removable = 0;
2820         }
2821         return PMINFO_R_OK;
2822 }
2823
2824 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2825 {
2826         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2827         retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2828         char *val = NULL;
2829         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2830         val = (char *)info->uiapp_info->package_system;
2831         if (val) {
2832                 if (strcasecmp(val, "true") == 0)
2833                         *system = 1;
2834                 else if (strcasecmp(val, "false") == 0)
2835                         *system = 0;
2836                 else
2837                         *system = 0;
2838         }
2839         return PMINFO_R_OK;
2840 }
2841
2842 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
2843 {
2844         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2845         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2846         __cleanup_appinfo(info);
2847         return PMINFO_R_OK;
2848 }
2849
2850 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2851 {
2852         return (pkgmgrinfo_pkginfo_filter_create(handle));
2853 }
2854
2855 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2856 {
2857         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2858 }
2859
2860 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2861                                 const char *property, const int value)
2862 {
2863         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2864         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2865         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2866         char *val = NULL;
2867         GSList *link = NULL;
2868         int prop = -1;
2869         prop = _pminfo_appinfo_convert_to_prop_int(property);
2870         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2871                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2872                 _LOGE("Invalid Integer Property\n");
2873                 return PMINFO_R_EINVAL;
2874         }
2875         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2876         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2877         if (node == NULL) {
2878                 _LOGE("Out of Memory!!!\n");
2879                 return PMINFO_R_ERROR;
2880         }
2881         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2882         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2883         if (val == NULL) {
2884                 _LOGE("Out of Memory\n");
2885                 FREE_AND_NULL(node);
2886                 return PMINFO_R_ERROR;
2887         }
2888         node->prop = prop;
2889         node->value = val;
2890         /*If API is called multiple times for same property, we should override the previous values.
2891         Last value set will be used for filtering.*/
2892         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2893         if (link)
2894                 filter->list = g_slist_delete_link(filter->list, link);
2895         filter->list = g_slist_append(filter->list, (gpointer)node);
2896         return PMINFO_R_OK;
2897
2898 }
2899
2900 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2901                                 const char *property, const bool value)
2902 {
2903         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2904         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2905         char *val = NULL;
2906         GSList *link = NULL;
2907         int prop = -1;
2908         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2909         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2910                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2911                 _LOGE("Invalid Boolean Property\n");
2912                 return PMINFO_R_EINVAL;
2913         }
2914         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2915         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2916         if (node == NULL) {
2917                 _LOGE("Out of Memory!!!\n");
2918                 return PMINFO_R_ERROR;
2919         }
2920         if (value)
2921                 val = strndup("('true','True')", 15);
2922         else
2923                 val = strndup("('false','False')", 17);
2924         if (val == NULL) {
2925                 _LOGE("Out of Memory\n");
2926                 FREE_AND_NULL(node);
2927                 return PMINFO_R_ERROR;
2928         }
2929         node->prop = prop;
2930         node->value = val;
2931         /*If API is called multiple times for same property, we should override the previous values.
2932         Last value set will be used for filtering.*/
2933         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2934         if (link)
2935                 filter->list = g_slist_delete_link(filter->list, link);
2936         filter->list = g_slist_append(filter->list, (gpointer)node);
2937         return PMINFO_R_OK;
2938
2939 }
2940
2941 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2942                                 const char *property, const char *value)
2943 {
2944         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2945         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2946         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2947         char *val = NULL;
2948         pkgmgrinfo_node_x *ptr = NULL;
2949         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2950         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2951         GSList *link = NULL;
2952         int prop = -1;
2953         prop = _pminfo_appinfo_convert_to_prop_str(property);
2954         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2955                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2956                 _LOGE("Invalid String Property\n");
2957                 return PMINFO_R_EINVAL;
2958         }
2959         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2960         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2961         if (node == NULL) {
2962                 _LOGE("Out of Memory!!!\n");
2963                 return PMINFO_R_ERROR;
2964         }
2965         node->prop = prop;
2966         switch (prop) {
2967         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2968                 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
2969                 node->value = val;
2970                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2971                 if (link)
2972                         filter->list = g_slist_delete_link(filter->list, link);
2973                 filter->list = g_slist_append(filter->list, (gpointer)node);
2974                 break;
2975         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2976         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2977         case E_PMINFO_APPINFO_PROP_APP_URI:
2978         case E_PMINFO_APPINFO_PROP_APP_MIME:
2979                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2980                 if (val == NULL) {
2981                         _LOGE("Out of Memory\n");
2982                         FREE_AND_NULL(node);
2983                         return PMINFO_R_ERROR;
2984                 }
2985                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2986                 if (link) {
2987                         ptr = (pkgmgrinfo_node_x *)link->data;
2988                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2989                         _LOGS("Previous value is %s\n", prev);
2990                         filter->list = g_slist_delete_link(filter->list, link);
2991                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2992                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2993                         _LOGS("New value is %s\n", val);
2994                         node->value = val;
2995                         filter->list = g_slist_append(filter->list, (gpointer)node);
2996                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2997                 } else {
2998                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2999                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3000                         _LOGS("First value is %s\n", val);
3001                         node->value = val;
3002                         filter->list = g_slist_append(filter->list, (gpointer)node);
3003                         memset(temp, '\0', PKG_STRING_LEN_MAX);
3004                 }
3005                 break;
3006         default:
3007                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3008                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3009                 if (link)
3010                         filter->list = g_slist_delete_link(filter->list, link);
3011                 filter->list = g_slist_append(filter->list, (gpointer)node);
3012                 break;
3013         }
3014         return PMINFO_R_OK;
3015 }
3016
3017 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3018 {
3019         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3020         retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3021
3022         int ret = 0;
3023         int filter_count = 0;
3024
3025         char *locale = NULL;
3026         char *condition = NULL;
3027         char query[MAX_QUERY_LEN] = {'\0'};
3028         char where[MAX_QUERY_LEN] = {'\0'};
3029
3030         uiapplication_x *ptr1 = NULL;
3031         pkgmgr_pkginfo_x *info = NULL;
3032         pkgmgr_appinfo_x *appinfo = NULL;
3033         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3034
3035         sqlite3 *pkginfo_db = NULL;
3036         sqlite3_stmt *stmt = NULL;
3037         GSList *list;
3038
3039
3040         /*open db*/
3041         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3042         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
3043
3044         /*calloc*/
3045         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3046         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3047
3048         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3049         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3050
3051         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3052         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3053
3054         /*Start constructing query*/
3055         locale = __convert_system_locale_to_manifest_locale();
3056         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
3057
3058         /*Get where clause*/
3059         for (list = filter->list; list; list = g_slist_next(list)) {
3060                 __get_filter_condition(list->data, &condition);
3061                 if (condition) {
3062                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3063                         where[sizeof(where) - 1] = '\0';
3064                         FREE_AND_NULL(condition);
3065                 }
3066                 if (g_slist_next(list)) {
3067                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3068                         where[sizeof(where) - 1] = '\0';
3069                 }
3070         }
3071
3072         if (strstr(where, "package_app_info.app_disable") == NULL) {
3073                 if (strlen(where) > 0) {
3074                         strncat(where, " and package_app_info.app_disable IN ('false','False')", sizeof(where) - strlen(where) - 1);
3075                         where[sizeof(where) - 1] = '\0';
3076                 }
3077         }
3078         _LOGS("where = %s\n", where);
3079
3080         if (strlen(where) > 0) {
3081                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3082                 query[sizeof(query) - 1] = '\0';
3083         }
3084         _LOGS("query = %s\n", query);
3085
3086         /*prepare query*/
3087         ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
3088         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
3089
3090         /*step query*/
3091         while(1) {
3092                 ret = sqlite3_step(stmt);
3093                 if(ret == SQLITE_ROW) {
3094                         __get_appinfo_for_list(stmt, info);
3095                 } else {
3096                         break;
3097                 }
3098         }
3099
3100         /*head up*/
3101         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
3102
3103         /*If the callback func return < 0 we break and no more call back is called*/
3104         while(ptr1 != NULL)
3105         {
3106                 appinfo->uiapp_info = ptr1;
3107                 ret = __appinfo_check_installed_storage(appinfo);
3108                 if(ret < 0) {
3109                         ptr1 = ptr1->next;
3110                         continue;
3111                 }
3112                 ptr1 = ptr1->next;
3113                 filter_count++;
3114         }
3115
3116         *count = filter_count;
3117
3118         ret = PMINFO_R_OK;
3119 catch:
3120         FREE_AND_NULL(locale);
3121         sqlite3_finalize(stmt);
3122         sqlite3_close(pkginfo_db);
3123         FREE_AND_NULL(appinfo);
3124         __cleanup_pkginfo(info);
3125         return ret;
3126 }
3127
3128 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3129                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
3130 {
3131         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3132         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3133
3134         int ret = 0;
3135
3136         char *locale = NULL;
3137         char *condition = NULL;
3138         char query[MAX_QUERY_LEN] = {'\0'};
3139         char where[MAX_QUERY_LEN] = {'\0'};
3140
3141         char appid[MAX_QUERY_LEN] = {0,};
3142         char pre_appid[MAX_QUERY_LEN] = {0,};
3143
3144         pkgmgr_pkginfo_x *info = NULL;
3145         pkgmgr_appinfo_x *appinfo = NULL;
3146         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3147         uiapplication_x *ptr1 = NULL;
3148
3149         sqlite3 *pkginfo_db = NULL;
3150         sqlite3_stmt *stmt = NULL;
3151         GSList *list;
3152
3153         /*open db*/
3154         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3155         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3156
3157         /*calloc*/
3158         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3159         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3160
3161         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3162         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3163
3164         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3165         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3166
3167         /*Start constructing query*/
3168         locale = __convert_system_locale_to_manifest_locale();
3169         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "locale is NULL\n");
3170         snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, DEFAULT_LOCALE, locale);
3171
3172         /*Get where clause*/
3173         for (list = filter->list; list; list = g_slist_next(list)) {
3174                 __get_filter_condition(list->data, &condition);
3175                 if (condition) {
3176                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3177                         where[sizeof(where) - 1] = '\0';
3178                         FREE_AND_NULL(condition);
3179                 }
3180                 if (g_slist_next(list)) {
3181                         strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3182                         where[sizeof(where) - 1] = '\0';
3183                 }
3184         }
3185
3186         if (strstr(where, "package_app_info.app_disable") == NULL) {
3187                 if (strlen(where) > 0) {
3188                         strncat(where, " and package_app_info.app_disable IN ('false','False')", sizeof(where) - strlen(where) - 1);
3189                         where[sizeof(where) - 1] = '\0';
3190                 }
3191         }
3192
3193         _LOGS("where = %s\n", where);
3194
3195         if (strlen(where) > 0) {
3196                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3197                 query[sizeof(query) - 1] = '\0';
3198         }
3199         _LOGS("query = %s\n", query);
3200
3201         /*prepare query*/
3202         ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
3203         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
3204
3205         /*step query*/
3206         while(1) {
3207                 ret = sqlite3_step(stmt);
3208                 if(ret == SQLITE_ROW) {
3209
3210                         memset(appid, 0, MAX_QUERY_LEN);
3211                         strncpy(appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3212
3213                         if (strlen(pre_appid) != 0) {
3214                                 if (strcmp(pre_appid, appid) == 0) {
3215                                         /*if same appid is found, then it is about exact matched locale*/
3216                                         __update_localed_label_for_list(stmt, info);
3217
3218                                         memset(pre_appid, 0, MAX_QUERY_LEN);
3219                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3220
3221                                         continue;
3222                                 } else {
3223                                         memset(pre_appid, 0, MAX_QUERY_LEN);
3224                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3225                                 }
3226                         } else {
3227                                 strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3228                         }
3229
3230                         __get_appinfo_for_list(stmt, info);
3231                 } else {
3232                         break;
3233                 }
3234         }
3235
3236         /*head up*/
3237         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
3238
3239         /*If the callback func return < 0 we break and no more call back is called*/
3240         while(ptr1 != NULL)
3241         {
3242                 appinfo->locale = strdup(locale);
3243                 appinfo->uiapp_info = ptr1;
3244
3245                 ret = __appinfo_check_installed_storage(appinfo);
3246                 if(ret < 0) {
3247                         FREE_AND_NULL(appinfo->locale);
3248                         ptr1 = ptr1->next;
3249                         continue;
3250                 }
3251
3252                 ret = app_cb((void *)appinfo, user_data);
3253                 if (ret < 0){
3254                         FREE_AND_NULL(appinfo->locale);
3255                         break;
3256                 }
3257
3258                 FREE_AND_NULL(appinfo->locale);
3259                 ptr1 = ptr1->next;
3260         }
3261         ret = PMINFO_R_OK;
3262
3263 catch:
3264         FREE_AND_NULL(locale);
3265         sqlite3_finalize(stmt);
3266         sqlite3_close(pkginfo_db);
3267         FREE_AND_NULL(appinfo);
3268         __cleanup_pkginfo(info);
3269         return ret;
3270 }
3271
3272 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3273 {
3274         return (pkgmgrinfo_pkginfo_filter_create(handle));
3275 }
3276
3277 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3278 {
3279         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3280 }
3281
3282 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
3283                 const char *key, const char *value)
3284 {
3285         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
3286         retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
3287         /*value can be NULL. In that case all apps with specified key should be displayed*/
3288         int ret = 0;
3289         char *k = NULL;
3290         char *v = NULL;
3291         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3292         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3293         retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
3294         k = strdup(key);
3295         tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3296         node->key = k;
3297         if (value) {
3298                 v = strdup(value);
3299                 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3300         }
3301         node->value = v;
3302         /*If API is called multiple times, we should OR all conditions.*/
3303         filter->list = g_slist_append(filter->list, (gpointer)node);
3304         /*All memory will be freed in destroy API*/
3305         return PMINFO_R_OK;
3306 catch:
3307         if (node) {
3308                 FREE_AND_NULL(node->key);
3309                 FREE_AND_NULL(node->value);
3310                 FREE_AND_NULL(node);
3311         }
3312         return ret;
3313 }
3314
3315 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
3316                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3317 {
3318         retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
3319         retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
3320         char *locale = NULL;
3321         char *condition = NULL;
3322         char query[MAX_QUERY_LEN] = {'\0'};
3323         char where[MAX_QUERY_LEN] = {'\0'};
3324         char appid[MAX_QUERY_LEN] = {0,};
3325         char pre_appid[MAX_QUERY_LEN] = {0,};
3326         GSList *list;
3327         int ret = 0;
3328         pkgmgr_pkginfo_x *info = NULL;
3329         pkgmgr_appinfo_x *appinfo = NULL;
3330         uiapplication_x *ptr1 = NULL;
3331         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3332         sqlite3 *pkginfo_db = NULL;
3333         sqlite3_stmt *stmt = NULL;
3334
3335         /*open db*/
3336         ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
3337         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3338
3339         /*calloc*/
3340         info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3341         tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3342
3343         info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3344         tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3345
3346         appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3347         tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
3348
3349         /*Get current locale*/
3350         locale = __convert_system_locale_to_manifest_locale();
3351         tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
3352
3353         /*Start constructing query*/
3354         memset(where, '\0', MAX_QUERY_LEN);
3355         memset(query, '\0', MAX_QUERY_LEN);
3356         snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
3357
3358         /*Get where clause*/
3359         for (list = filter->list; list; list = g_slist_next(list)) {
3360                 __get_metadata_filter_condition(list->data, &condition);
3361                 if (condition) {
3362                         strncat(where, condition, sizeof(where) - strlen(where) -1);
3363                         FREE_AND_NULL(condition);
3364                 }
3365                 if (g_slist_next(list)) {
3366                         strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
3367                 }
3368         }
3369
3370         if (strstr(where, "package_app_info.app_disable") == NULL) {
3371                 if (strlen(where) > 0) {
3372                         strncat(where, " and package_app_info.app_disable IN ('false','False')", sizeof(where) - strlen(where) - 1);
3373                         where[sizeof(where) - 1] = '\0';
3374                 }
3375         }
3376
3377         _LOGE("where = %s (%d)\n", where, strlen(where));
3378
3379         if (strlen(where) > 0) {
3380                 strncat(query, where, sizeof(query) - strlen(query) - 1);
3381         }
3382         _LOGE("query = %s (%d)\n", query, strlen(query));
3383
3384         /*prepare query*/
3385         ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
3386         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
3387
3388         /*step query*/
3389         while(1) {
3390                 ret = sqlite3_step(stmt);
3391                 if(ret == SQLITE_ROW) {
3392
3393                         memset(appid, 0, MAX_QUERY_LEN);
3394                         strncpy(appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3395
3396                         if (strlen(pre_appid) != 0) {
3397                                 if (strcmp(pre_appid, appid) == 0) {
3398                                         /*if same appid is found, then it is about exact matched locale*/
3399                                         __update_localed_label_for_list(stmt, info);
3400
3401                                         memset(pre_appid, 0, MAX_QUERY_LEN);
3402                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3403
3404                                         continue;
3405                                 } else {
3406                                         memset(pre_appid, 0, MAX_QUERY_LEN);
3407                                         strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3408                                 }
3409                         } else {
3410                                 strncpy(pre_appid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
3411                         }
3412
3413                         __get_appinfo_for_list(stmt, info);
3414                 } else {
3415                         break;
3416                 }
3417         }
3418
3419         /*head up*/
3420         SAFE_LISTHEAD(info->manifest_info->uiapplication, ptr1);
3421
3422         /*UI Apps*/
3423         while (ptr1 != NULL) {
3424                 appinfo->locale = strdup(locale);
3425                 appinfo->uiapp_info = ptr1;
3426
3427                 ret = __appinfo_check_installed_storage(appinfo);
3428                 if(ret < 0) {
3429                         FREE_AND_NULL(appinfo->locale);
3430                         ptr1 = ptr1->next;
3431                         continue;
3432                 }
3433
3434                 ret = app_cb((void *)appinfo, user_data);
3435                 if (ret < 0) {
3436                         FREE_AND_NULL(appinfo->locale);
3437                         break;
3438                 }
3439
3440                 FREE_AND_NULL(appinfo->locale);
3441                 ptr1 = ptr1->next;
3442         }
3443
3444         ret = PMINFO_R_OK;
3445 catch:
3446         FREE_AND_NULL(locale);
3447         sqlite3_finalize(stmt);
3448         sqlite3_close(pkginfo_db);
3449         FREE_AND_NULL(appinfo);
3450         __cleanup_pkginfo(info);
3451         return ret;
3452 }