Fix getting appcontrol info in pkg_info.c
[platform/core/appfw/slp-pkgmgr.git] / tool / pkg_info.c
1 /*
2  * slp-pkgmgr
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #define _GNU_SOURCE
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <sys/types.h>
30 #include <vconf.h>
31 //Work around for https://bugs.tizen.org/jira/browse/TC-2399
32 #include <ail_vconf.h>
33 #include <pkgmgr_parser.h>
34 #include <pkgmgr-info.h>
35 #include "package-manager.h"
36 #include "package-manager-types.h"
37 #include "pkgmgr-dbinfo.h"
38 #include "pkgmgr_installer.h"
39
40 #define OWNER_ROOT 0
41
42 static void __print_usage();
43 static int __get_pkg_info(char *pkgid, uid_t uid);
44 static int __get_app_info(char *appid);
45 static int __get_app_list(char *pkgid, uid_t uid);
46 static int __get_app_category_list(char *appid);
47 static int __get_app_metadata_list(char *appid);
48 static int __get_app_control_list(char *appid);
49 static int __get_pkg_list(uid_t uid);
50 static int __get_installed_app_list(uid_t uid);
51 static int __add_app_filter(uid_t uid);
52 static int __add_pkg_filter(uid_t uid);
53 static int __insert_manifest_in_db(char *manifest, uid_t uid);
54 static int __remove_manifest_from_db(char *manifest, uid_t uid);
55 static int __set_pkginfo_in_db(char *pkgid, uid_t uid);
56 static int __set_certinfo_in_db(char *pkgid, uid_t uid);
57 static int __get_certinfo_from_db(char *pkgid, uid_t uid);
58 static int __del_certinfo_from_db(char *pkgid);
59 static int __get_integer_input_data(void);
60 char *__get_string_input_data(void);
61 static int __pkg_list_cb (const pkgmgr_pkginfo_h handle, void *user_data);
62 static int __app_category_list_cb(const char *category_name, void *user_data);
63 static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data);
64 static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data);
65 int app_func(const pkgmgr_appinfo_h handle, void *user_data);
66
67 static void __get_pkgmgrinfo_pkginfo(const pkgmgrinfo_pkginfo_h handle, void *user_data)
68 {
69         int ret = -1;
70         char *type = NULL;
71         char *version = NULL;
72         char *author_name = NULL;
73         char *author_email = NULL;
74         char *author_href = NULL;
75         char *root_path = NULL;
76         char *mainappid = NULL;
77         pkgmgr_install_location location = 0;
78         char *icon = NULL;
79         char *label = NULL;
80         char *desc = NULL;
81         bool removable = 0;
82         bool preload = 0;
83         bool readonly = 0;
84         bool update = 0;
85         bool system = 0;
86         int size = -1;
87         int installed_time = -1;
88
89         ret = pkgmgrinfo_pkginfo_get_type(handle, &type);
90         if (ret < 0) {
91                 printf("Failed to get pkg type\n");
92         }
93         if (type)
94                 printf("Type: %s\n", type);
95
96         ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
97         if (ret < 0) {
98                 printf("Failed to get version\n");
99         }
100         if (version)
101                 printf("Version: %s\n", version);
102
103         ret = pkgmgrinfo_pkginfo_get_install_location(handle, &location);
104         if (ret < 0) {
105                 printf("Failed to get install location\n");
106         }
107         printf("Install Location: %d\n", location);
108
109         ret = pkgmgrinfo_pkginfo_get_package_size(handle, &size);
110         if (ret < 0) {
111                 printf("Failed to get package size \n");
112         }
113         printf("Package Size: %d\n", size);
114
115         ret = pkgmgrinfo_pkginfo_get_icon(handle, &icon);
116         if (ret < 0) {
117                 printf("Failed to get icon\n");
118         }
119         if (icon)
120                 printf("Icon: %s\n", icon);
121
122         ret = pkgmgrinfo_pkginfo_get_label(handle, &label);
123         if (ret < 0) {
124                 printf("Failed to get label\n");
125         }
126         if (label)
127                 printf("Label: %s\n", label);
128
129         ret = pkgmgrinfo_pkginfo_get_description(handle, &desc);
130         if (ret < 0) {
131                 printf("Failed to get description\n");
132         }
133         if (desc)
134                 printf("Description: %s\n", desc);
135
136         ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author_name);
137         if (ret < 0) {
138                 printf("Failed to get author name\n");
139         }
140         if (author_name)
141                 printf("Author Name: %s\n", author_name);
142
143         ret = pkgmgrinfo_pkginfo_get_author_email(handle, &author_email);
144         if (ret < 0) {
145                 printf("Failed to get author email\n");
146         }
147         if (author_email)
148                 printf("Author Email: %s\n", author_email);
149
150         ret = pkgmgrinfo_pkginfo_get_author_href(handle, &author_href);
151         if (ret < 0) {
152                 printf("Failed to get author href\n");
153         }
154         if (author_href)
155                 printf("Author Href: %s\n", author_href);
156
157         ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
158         if (ret < 0) {
159                 printf("Failed to get root_path\n");
160         }
161         if (author_href)
162                 printf("root_path : %s\n", root_path);
163
164         ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid);
165         if (ret < 0) {
166                 printf("Failed to get mainappid\n");
167         }
168         if (author_href)
169                 printf("mainappid : %s\n", mainappid);
170
171         ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
172         if (ret < 0) {
173                 printf("Failed to get install time\n");
174         }
175         printf("Install time: %d\n", installed_time);
176
177         ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable);
178         if (ret < 0) {
179                 printf("Failed to get removable\n");
180         }
181         else
182                 printf("Removable: %d\n", removable);
183
184         ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
185         if (ret < 0) {
186                 printf("Failed to get preload\n");
187         }
188         else
189                 printf("Preload: %d\n", preload);
190
191         ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly);
192         if (ret < 0) {
193                 printf("Failed to get readonly\n");
194         }
195         else
196                 printf("Readonly: %d\n", readonly);
197
198         ret = pkgmgrinfo_pkginfo_is_update(handle, &update);
199         if (ret < 0) {
200                 printf("Failed to get update\n");
201         }
202         else
203                 printf("update: %d\n", update);
204
205         ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
206         if (ret < 0) {
207                 printf("Failed to get system\n");
208         }
209         else
210                 printf("system: %d\n", system);
211
212         return 0;
213 }
214 int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data)
215 {
216         char *appid = NULL;
217         char *apptype = NULL;
218         int ret = -1;
219
220         ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
221         if (ret < 0) {
222                 printf("Failed to get appid\n");
223         }
224
225         ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype);
226         if (ret < 0) {
227                 printf("Failed to get package\n");
228         }
229         printf("apptype [%s]\t appid [%s]\n", apptype, appid);
230
231         return 0;
232 }
233
234 static int __get_integer_input_data(void)
235 {
236         char input_str[32] = { 0, };
237         int data = 0;
238
239         if (fgets(input_str, sizeof(input_str), stdin) == NULL) {
240                 printf("fgets() failed....\n");
241                 return -1;
242         }
243
244         if (sscanf(input_str, "%4d", &data) != 1) {
245                 printf("Input only integer option....\n");
246                 return -1;
247         }
248
249         return data;
250 }
251
252
253 char *__get_string_input_data(void)
254 {
255         char *data = (char *)malloc(1024);
256         if (data == NULL) {
257                 printf("Malloc Failed\n");
258                 return NULL;
259         }
260         if (fgets(data,1024,stdin) == NULL){
261                 printf("Buffer overflow!!! try again\n");
262                 exit(-1);
263         }
264         data[strlen(data) - 1] = '\0';
265         return data;
266 }
267
268 static void __print_usage()
269 {
270         printf("For Getting package|App Info\n");
271         printf("\tpkginfo --[pkg|app] <pkgid|appid>\n\n");
272         printf("For Getting list of installed packages\n");
273         printf("\tpkginfo --listpkg \n\n");
274         printf("For Getting list of installed applications\n");
275         printf("\tpkginfo --listapp \n\n");
276         printf("For Getting app list for a particular package\n");
277         printf("\tpkginfo --list <pkgid>\n\n");
278         printf("For Getting app category list for a particular application\n");
279         printf("\tpkginfo --category <appid>\n\n");
280         printf("For Getting app metadata  list for a particular application\n");
281         printf("\tpkginfo --metadata <appid>\n\n");
282         printf("For Getting app control list for a particular application\n");
283         printf("\tpkginfo --appcontrol <appid>\n\n");
284         printf("To insert|remove manifest info in DB\n");
285         printf("\tpkginfo --[imd|rmd] <manifest file name>\n\n");
286         printf("To set pkginfo in DB\n");
287         printf("\tpkginfo --setdb <pkgid>\n\n");
288         printf("To set manifest validation\n");
289         printf("\tpkginfo --check <manifest file name>\n\n");
290         printf("To set cert info in DB\n");
291         printf("\tpkginfo --setcert <pkgid>\n\n");
292         printf("To get cert info from DB\n");
293         printf("\tpkginfo --getcert <pkgid>\n\n");
294         printf("To compare pkg cert info from DB\n");
295         printf("\tpkginfo --cmp-pkgcert <lhs_pkgid> <rhs_pkgid>\n\n");
296         printf("To compare app cert info from DB\n");
297         printf("\tpkginfo --cmp-appcert <lhs_appid> <rhs_appid>\n\n");
298         printf("To delete all cert info from DB\n");
299         printf("\tpkginfo --delcert <pkgid>\n\n");
300         printf("To add application filter values [Multiple values can be added]\n");
301         printf("\tpkginfo --app-flt\n\n");
302         printf("To add package filter values [Multiple values can be added]\n");
303         printf("\tpkginfo --pkg-flt\n\n");
304         printf("To add metadata filter values\n");
305         printf("\tpkginfo --metadata-flt\n\n");
306 }
307
308 static void __print_arg_filter_usage()
309 {
310         printf("=========================================\n");
311         printf("pkginfo --arg-flt key value\n");
312         printf("ex : pkginfo --arg-flt 6 webapp\n");
313         printf("key list is bellowed\n");
314         printf("2  --> filter by app ID\n");
315         printf("3  --> filter by app component\n");
316         printf("4  --> filter by app exec\n");
317         printf("5  --> filter by app icon\n");
318         printf("6  --> filter by app type\n");
319         printf("7  --> filter by app operation\n");
320         printf("8  --> filter by app uri\n");
321         printf("9  --> filter by app mime\n");
322         printf("10 --> filter by app category\n");
323         printf("11 --> filter by app nodisplay [0|1]\n");
324         printf("12 --> filter by app multiple [0|1]\n");
325         printf("13 --> filter by app onboot [0|1]\n");
326         printf("14 --> filter by app autorestart [0|1]\n");
327         printf("15 --> filter by app taskmanage [0|1]\n");
328         printf("16 --> filter by app hwacceleration\n");
329         printf("17 --> filter by app screenreader\n");
330         printf("=========================================\n");
331 }
332
333 static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
334 {
335         char *appid = NULL;
336         pkgmgrinfo_appinfo_get_appid(handle, &appid);
337         printf("appid : %s\n", appid);
338         return 0;
339 }
340
341 static int __add_metadata_filter()
342 {
343         int ret = 0;
344         pkgmgrinfo_appinfo_metadata_filter_h handle;
345         char *key = NULL;
346         char *value = NULL;
347
348         ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
349         if (ret != PMINFO_R_OK){
350                 printf("pkgmgrinfo_appinfo_metadata_filter_create() failed\n");
351                 return ret;
352         }
353
354         printf("enter metadata - key\n");
355         key = __get_string_input_data();
356         printf("enter metadata - value\n");
357         value = __get_string_input_data();
358
359         printf("filter condition : key=[%s], value=[%s]\n", key, value);
360
361         ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, key, value);
362         if (ret != PMINFO_R_OK){
363                 printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
364                 goto err;
365         }
366
367         ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, __app_list_cb, NULL);
368         if (ret != PMINFO_R_OK){
369                 printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n");
370                 goto err;
371         }
372
373 err:
374         pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
375         if (key) {
376                 free(key);
377                 key = NULL;
378         }
379         if (value) {
380                 free(value);
381                 value = NULL;
382         }
383         return ret;
384 }
385
386 static int __add_app_filter(uid_t uid)
387 {
388         int ret = 0;
389         int choice = -1;
390         char *value = NULL;
391         int val = -1;
392         int count = 0;
393         pkgmgrinfo_appinfo_filter_h handle;
394         ret = pkgmgrinfo_appinfo_filter_create(&handle);
395         if (ret > 0) {
396                 printf("appinfo filter handle create failed\n");
397                 return -1;
398         }
399         while (choice != 0 && choice != 1)
400         {
401                 printf("Enter Choice\n");
402                 printf("0  --> Finalize filter and get count of apps\n");
403                 printf("1  --> Finalize filter and get list of apps\n");
404                 printf("2  --> filter by app ID\n");
405                 printf("3  --> filter by app component\n");
406                 printf("4  --> filter by app exec\n");
407                 printf("5  --> filter by app icon\n");
408                 printf("6  --> filter by app type\n");
409                 printf("7  --> filter by app operation\n");
410                 printf("8  --> filter by app uri\n");
411                 printf("9  --> filter by app mime\n");
412                 printf("10 --> filter by app category\n");
413                 printf("11 --> filter by app nodisplay [0|1]\n");
414                 printf("12 --> filter by app multiple [0|1]\n");
415                 printf("13 --> filter by app onboot [0|1]\n");
416                 printf("14 --> filter by app autorestart [0|1]\n");
417                 printf("15 --> filter by app taskmanage [0|1]\n");
418                 printf("16 --> filter by app hwacceleration\n");
419                 printf("17 --> filter by app screenreader\n");
420                 choice = __get_integer_input_data();
421                 switch (choice) {
422                 case 0:
423                         ret = pkgmgrinfo_appinfo_filter_count(handle, &count);
424                         if (ret < 0) {
425                                 printf("pkgmgrinfo_appinfo_filter_count() failed\n");
426                                 ret = -1;
427                                 goto err;
428                         }
429                         printf("App count = %d\n", count);
430                         break;
431                 case 1:
432                         if (uid != GLOBAL_USER)
433                                 ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_func, NULL, uid);
434                         else
435                                 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, app_func, NULL);
436                         if (ret < 0) {
437                                 printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
438                                 ret = -1;
439                                 goto err;
440                         }
441                         break;
442                 case 2:
443                         value = __get_string_input_data();
444                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
445                                 PMINFO_APPINFO_PROP_APP_ID, value);
446                         if (ret < 0) {
447                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
448                                 ret = -1;
449                                 goto err;
450                         }
451                         free(value);
452                         value = NULL;
453                         break;
454                 case 3:
455                         value = __get_string_input_data();
456                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
457                                 PMINFO_APPINFO_PROP_APP_COMPONENT, value);
458                         if (ret < 0) {
459                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
460                                 ret = -1;
461                                 goto err;
462                         }
463                         free(value);
464                         value = NULL;
465                         break;
466                 case 4:
467                         value = __get_string_input_data();
468                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
469                                 PMINFO_APPINFO_PROP_APP_EXEC, value);
470                         if (ret < 0) {
471                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
472                                 ret = -1;
473                                 goto err;
474                         }
475                         free(value);
476                         value = NULL;
477                         break;
478                 case 5:
479                         value = __get_string_input_data();
480                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
481                                 PMINFO_APPINFO_PROP_APP_ICON, value);
482                         if (ret < 0) {
483                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
484                                 ret = -1;
485                                 goto err;
486                         }
487                         free(value);
488                         value = NULL;
489                         break;
490                 case 6:
491                         value = __get_string_input_data();
492                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
493                                 PMINFO_APPINFO_PROP_APP_TYPE, value);
494                         if (ret < 0) {
495                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
496                                 ret = -1;
497                                 goto err;
498                         }
499                         free(value);
500                         value = NULL;
501                         break;
502                 case 7:
503                         value = __get_string_input_data();
504                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
505                                 PMINFO_APPINFO_PROP_APP_OPERATION, value);
506                         if (ret < 0) {
507                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
508                                 ret = -1;
509                                 goto err;
510                         }
511                         free(value);
512                         value = NULL;
513                         break;
514                 case 8:
515                         value = __get_string_input_data();
516                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
517                                 PMINFO_APPINFO_PROP_APP_URI, value);
518                         if (ret < 0) {
519                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
520                                 ret = -1;
521                                 goto err;
522                         }
523                         free(value);
524                         value = NULL;
525                         break;
526                 case 9:
527                         value = __get_string_input_data();
528                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
529                                 PMINFO_APPINFO_PROP_APP_MIME, value);
530                         if (ret < 0) {
531                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
532                                 ret = -1;
533                                 goto err;
534                         }
535                         free(value);
536                         value = NULL;
537                         break;
538                 case 10:
539                         value = __get_string_input_data();
540                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
541                                 PMINFO_APPINFO_PROP_APP_CATEGORY, value);
542                         if (ret < 0) {
543                                 printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
544                                 ret = -1;
545                                 goto err;
546                         }
547                         free(value);
548                         value = NULL;
549                         break;
550                 case 11:
551                         val = __get_integer_input_data();
552                         ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
553                                 PMINFO_APPINFO_PROP_APP_NODISPLAY, val);
554                         if (ret < 0) {
555                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
556                                 ret = -1;
557                                 goto err;
558                         }
559                         break;
560                 case 12:
561                         val = __get_integer_input_data();
562                         ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
563                                 PMINFO_APPINFO_PROP_APP_MULTIPLE, val);
564                         if (ret < 0) {
565                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
566                                 ret = -1;
567                                 goto err;
568                         }
569                         break;
570                 case 13:
571                         val = __get_integer_input_data();
572                         ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
573                                 PMINFO_APPINFO_PROP_APP_ONBOOT, val);
574                         if (ret < 0) {
575                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
576                                 ret = -1;
577                                 goto err;
578                         }
579                         break;
580                 case 14:
581                         val = __get_integer_input_data();
582                         ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
583                                 PMINFO_APPINFO_PROP_APP_AUTORESTART, val);
584                         if (ret < 0) {
585                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
586                                 ret = -1;
587                                 goto err;
588                         }
589                         break;
590                 case 15:
591                         val = __get_integer_input_data();
592                         ret = pkgmgrinfo_appinfo_filter_add_bool(handle,
593                                 PMINFO_APPINFO_PROP_APP_TASKMANAGE, val);
594                         if (ret < 0) {
595                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
596                                 ret = -1;
597                                 goto err;
598                         }
599                         break;
600                 case 16:
601                         value = __get_string_input_data();
602                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
603                                 PMINFO_APPINFO_PROP_APP_HWACCELERATION, value);
604                         if (ret < 0) {
605                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
606                                 ret = -1;
607                                 goto err;
608                         }
609                         free(value);
610                         value = NULL;
611                         break;
612                 case 17:
613                         value = __get_string_input_data();
614                         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
615                                 PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
616                         if (ret < 0) {
617                                 printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
618                                 ret = -1;
619                                 goto err;
620                         }
621                         free(value);
622                         value = NULL;
623                         break;
624                 default:
625                         printf("Invalid filter property\n");
626                                 pkgmgrinfo_appinfo_filter_destroy(handle);
627                         ret = -1;
628                         goto err;
629                 }
630         }
631         ret = 0;
632 err:
633         pkgmgrinfo_appinfo_filter_destroy(handle);
634         if (value) {
635                 free(value);
636                 value = NULL;
637         }
638         return ret;
639 }
640
641 static int __add_pkg_filter(uid_t uid)
642 {
643         int ret = 0;
644         int choice = -1;
645         char *value = NULL;
646         int val = -1;
647         int count = 0;
648         pkgmgrinfo_pkginfo_filter_h handle;
649
650         ret = pkgmgrinfo_pkginfo_filter_create(&handle);
651         if (ret > 0) {
652                 printf("pkginfo filter handle create failed\n");
653                 return -1;
654         }
655         while (choice != 0 && choice !=1)
656         {
657                 printf("Enter Choice\n");
658                 printf("0  --> Finalize filter and get count of packages\n");
659                 printf("1  --> Finalize filter and get list of packages\n");
660                 printf("2  --> filter by package ID\n");
661                 printf("3  --> filter by package version\n");
662                 printf("4  --> filter by package type\n");
663                 printf("5  --> filter by package install location\n");
664                 printf("6  --> filter by author name\n");
665                 printf("7  --> filter by author email\n");
666                 printf("8  --> filter by author href\n");
667                 printf("9  --> filter by package removable [0|1]\n");
668                 printf("10 --> filter by package readonly [0|1]\n");
669                 printf("11 --> filter by package preload [0|1]\n");
670                 printf("12 --> filter by package update [0|1]\n");
671                 printf("13 --> filter by package appsetting [0|1]\n");
672                 printf("14 --> filter by package size\n");
673                 printf("15 --> filter by package installed storage[installed_internal | installed_external]\n");
674                 choice = __get_integer_input_data();
675                 switch (choice) {
676                 case 0:
677                         if (uid != GLOBAL_USER)
678                                 ret = pkgmgrinfo_pkginfo_usr_filter_count(handle, &count, uid);
679                         else
680                                 ret = pkgmgrinfo_pkginfo_filter_count(handle, &count);
681                         if (ret < 0) {
682                                 printf("pkgmgrinfo_pkginfo_filter_count() failed\n");
683                                 ret = -1;
684                                 goto err;
685                         }
686                         printf("Package count = %d\n", count);
687                         break;
688                 case 1:
689                         if (uid != GLOBAL_USER)
690                                 ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL, uid);
691                         else
692                                 ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL);
693                         if (ret < 0) {
694                                 printf("pkgmgrinfo_pkginfo_(usr)_filter_foreach_pkginfo() failed\n");
695                                 ret = -1;
696                                 goto err;
697                         }
698                         break;
699                 case 2:
700                         value = __get_string_input_data();
701                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
702                                 PMINFO_PKGINFO_PROP_PACKAGE_ID, value);
703                         if (ret < 0) {
704                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
705                                 ret = -1;
706                                 goto err;
707                         }
708                         free(value);
709                         value = NULL;
710                         break;
711                 case 3:
712                         value = __get_string_input_data();
713                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
714                                 PMINFO_PKGINFO_PROP_PACKAGE_VERSION, value);
715                         if (ret < 0) {
716                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
717                                 ret = -1;
718                                 goto err;
719                         }
720                         free(value);
721                         value = NULL;
722                         break;
723                 case 4:
724                         value = __get_string_input_data();
725                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
726                                 PMINFO_PKGINFO_PROP_PACKAGE_TYPE, value);
727                         if (ret < 0) {
728                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
729                                 ret = -1;
730                                 goto err;
731                         }
732                         free(value);
733                         value = NULL;
734                         break;
735                 case 5:
736                         value = __get_string_input_data();
737                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
738                                 PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, value);
739                         if (ret < 0) {
740                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
741                                 ret = -1;
742                                 goto err;
743                         }
744                         free(value);
745                         value = NULL;
746                         break;
747                 case 6:
748                         value = __get_string_input_data();
749                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
750                                 PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, value);
751                         if (ret < 0) {
752                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
753                                 ret = -1;
754                                 goto err;
755                         }
756                         free(value);
757                         value = NULL;
758                         break;
759                 case 7:
760                         value = __get_string_input_data();
761                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
762                                 PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, value);
763                         if (ret < 0) {
764                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
765                                 ret = -1;
766                                 goto err;
767                         }
768                         free(value);
769                         value = NULL;
770                         break;
771                 case 8:
772                         value = __get_string_input_data();
773                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
774                                 PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, value);
775                         if (ret < 0) {
776                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
777                                 ret = -1;
778                                 goto err;
779                         }
780                         free(value);
781                         value = NULL;
782                         break;
783                 case 9:
784                         val = __get_integer_input_data();
785                         ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
786                                 PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, val);
787                         if (ret < 0) {
788                                 printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
789                                 ret = -1;
790                                 goto err;
791                         }
792                         break;
793                 case 10:
794                         val = __get_integer_input_data();
795                         ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
796                                 PMINFO_PKGINFO_PROP_PACKAGE_READONLY, val);
797                         if (ret < 0) {
798                                 printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
799                                 ret = -1;
800                                 goto err;
801                         }
802                         break;
803                 case 11:
804                         val = __get_integer_input_data();
805                         ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
806                                 PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, val);
807                         if (ret < 0) {
808                                 printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
809                                 ret = -1;
810                                 goto err;
811                         }
812                         break;
813                 case 12:
814                         val = __get_integer_input_data();
815                         ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
816                                 PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, val);
817                         if (ret < 0) {
818                                 printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
819                                 ret = -1;
820                                 goto err;
821                         }
822                         break;
823                 case 13:
824                         val = __get_integer_input_data();
825                         ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
826                                 PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, val);
827                         if (ret < 0) {
828                                 printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n");
829                                 ret = -1;
830                                 goto err;
831                         }
832                         break;
833                 case 14:
834                         val = __get_integer_input_data();
835                         ret = pkgmgrinfo_pkginfo_filter_add_int(handle,
836                                 PMINFO_PKGINFO_PROP_PACKAGE_SIZE, val);
837                         if (ret < 0) {
838                                 printf("pkgmgrinfo_pkginfo_filter_add_int() failed\n");
839                                 ret = -1;
840                                 goto err;
841                         }
842                         break;
843                 case 15:
844                         value = __get_string_input_data();
845                         ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
846                                 PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, value);
847                         if (ret < 0) {
848                                 printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n");
849                                 ret = -1;
850                                 goto err;
851                         }
852                         free(value);
853                         value = NULL;
854                         break;
855                 default:
856                         printf("Invalid filter property\n");
857                                 pkgmgrinfo_pkginfo_filter_destroy(handle);
858                         ret = -1;
859                         goto err;
860                 }
861         }
862         ret = 0;
863 err:
864         pkgmgrinfo_pkginfo_filter_destroy(handle);
865         if (value) {
866                 free(value);
867                 value = NULL;
868         }
869         return ret;
870 }
871
872 static int __add_arg_filter(char *key, char *value, uid_t uid)
873 {
874         int ret = 0;
875         int choice = -1;
876         int val = -1;
877         pkgmgrinfo_appinfo_filter_h handle;
878         ret = pkgmgrinfo_appinfo_filter_create(&handle);
879         if (ret > 0) {
880                 printf("appinfo filter handle create failed\n");
881                 return -1;
882         }
883         choice = atoi(key);
884
885         switch (choice) {
886         case 2:
887                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ID, value);
888                 if (ret < 0) {
889                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
890                         ret = -1;
891                         goto err;
892                 }
893                 break;
894         case 3:
895                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_COMPONENT, value);
896                 if (ret < 0) {
897                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
898                         ret = -1;
899                         goto err;
900                 }
901                 break;
902         case 4:
903                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_EXEC, value);
904                 if (ret < 0) {
905                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
906                         ret = -1;
907                         goto err;
908                 }
909                 break;
910         case 5:
911                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ICON, value);
912                 if (ret < 0) {
913                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
914                         ret = -1;
915                         goto err;
916                 }
917                 break;
918         case 6:
919                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, value);
920                 if (ret < 0) {
921                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
922                         ret = -1;
923                         goto err;
924                 }
925                 break;
926         case 7:
927                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_OPERATION, value);
928                 if (ret < 0) {
929                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
930                         ret = -1;
931                         goto err;
932                 }
933                 break;
934         case 8:
935                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_URI, value);
936                 if (ret < 0) {
937                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
938                         ret = -1;
939                         goto err;
940                 }
941                 break;
942         case 9:
943                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_MIME, value);
944                 if (ret < 0) {
945                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
946                         ret = -1;
947                         goto err;
948                 }
949                 free(value);
950                 value = NULL;
951                 break;
952         case 10:
953                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, value);
954                 if (ret < 0) {
955                         printf("pkgmgrinfo_appinfo_filter_add_string() failed\n");
956                         ret = -1;
957                         goto err;
958                 }
959                 break;
960         case 11:
961                 val = atoi(value);
962                 ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, val);
963                 if (ret < 0) {
964                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
965                         ret = -1;
966                         goto err;
967                 }
968                 break;
969         case 12:
970                 val = atoi(value);
971                 ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_MULTIPLE, val);
972                 if (ret < 0) {
973                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
974                         ret = -1;
975                         goto err;
976                 }
977                 break;
978         case 13:
979                 val = atoi(value);
980                 ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, val);
981                 if (ret < 0) {
982                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
983                         ret = -1;
984                         goto err;
985                 }
986                 break;
987         case 14:
988                 val = atoi(value);
989                 ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, val);
990                 if (ret < 0) {
991                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
992                         ret = -1;
993                         goto err;
994                 }
995                 break;
996         case 15:
997                 val = atoi(value);
998                 ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, val);
999                 if (ret < 0) {
1000                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
1001                         ret = -1;
1002                         goto err;
1003                 }
1004                 break;
1005         case 16:
1006                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_HWACCELERATION, value);
1007                 if (ret < 0) {
1008                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
1009                         ret = -1;
1010                         goto err;
1011                 }
1012                 break;
1013         case 17:
1014                 ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_SCREENREADER, value);
1015                 if (ret < 0) {
1016                         printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n");
1017                         ret = -1;
1018                         goto err;
1019                 }
1020                 break;
1021
1022         default:
1023                 __print_arg_filter_usage();
1024                 goto err;
1025         }
1026         if (uid != GLOBAL_USER)
1027                 ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __get_app_id, NULL, uid);
1028         else
1029                 ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_app_id, NULL);
1030         if (ret < 0) {
1031                 printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
1032                 ret = -1;
1033                 goto err;
1034         }
1035
1036 err:
1037         pkgmgrinfo_appinfo_filter_destroy(handle);
1038         return ret;
1039 }
1040 static int __del_certinfo_from_db(char *pkgid)
1041 {
1042         int ret = 0;
1043         if (pkgid == NULL) {
1044                 printf("pkgid is NULL\n");
1045                 return -1;
1046         }
1047         ret = pkgmgr_installer_delete_certinfo(pkgid);
1048         if (ret < 0) {
1049                 printf("pkgmgr_installer_delete_certinfo failed\n");
1050                 return -1;
1051         }
1052         return 0;
1053 }
1054
1055 static int __get_certinfo_from_db(char *pkgid, uid_t uid)
1056 {
1057         if (pkgid == NULL) {
1058                 printf("pkgid is NULL\n");
1059                 return -1;
1060         }
1061         int ret = 0;
1062         int choice = -1;
1063         int i = 0;
1064         const char *value = NULL;
1065         pkgmgr_certinfo_h handle = NULL;
1066         ret = pkgmgr_pkginfo_create_certinfo(&handle);
1067         if (ret < 0) {
1068                 printf("pkgmgr_pkginfo_create_certinfo failed\n");
1069                 return -1;
1070         }
1071         ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle, uid);
1072         if (ret < 0) {
1073                 printf("pkgmgr_pkginfo_load_certinfo failed\n");
1074                 return -1;
1075         }
1076         while (choice != 10)
1077         {
1078                 printf("Enter the choice to get\n");
1079                 printf("0 --> to get all cert values\n");
1080                 printf("1 --> author root certificate\n");
1081                 printf("2 --> author intermediate certificate\n");
1082                 printf("3 --> author signer certificate\n");
1083                 printf("4 --> distributor root certificate\n");
1084                 printf("5 --> distributor intermediate certificate\n");
1085                 printf("6 --> distributor signer certificate\n");
1086                 printf("7 --> distributor2 root certificate\n");
1087                 printf("8 --> distributor2 intermediate certificate\n");
1088                 printf("9 --> distributor2 signer certificate\n");
1089                 printf("10 --> exit\n");
1090                 choice = __get_integer_input_data();
1091                 switch (choice) {
1092                 case 0:
1093                         for (i = 0; i < 9; i++)
1094                         {
1095                                 pkgmgr_pkginfo_get_cert_value(handle, i, &value);
1096                                 if (value)
1097                                         printf("cert type[%d] value = %s\n", i, value);
1098                         }
1099                         ret = pkgmgr_pkginfo_destroy_certinfo(handle);
1100                         if (ret < 0) {
1101                                 printf("pkgmgr_pkginfo_destroy_certinfo failed\n");
1102                                 return -1;
1103                         }
1104                         return 0;
1105                 case 1:
1106                 case 2:
1107                 case 3:
1108                 case 4:
1109                 case 5:
1110                 case 6:
1111                 case 7:
1112                 case 8:
1113                 case 9:
1114                         ret = pkgmgr_pkginfo_get_cert_value(handle, choice - 1, &value);
1115                         if (value)
1116                                 printf("cert type[%d] value = %s\n", choice - 1, value);
1117                         break;
1118                 case 10:
1119                         ret = pkgmgr_pkginfo_destroy_certinfo(handle);
1120                         if (ret < 0) {
1121                                 printf("pkgmgr_pkginfo_destroy_certinfo failed\n");
1122                                 return -1;
1123                         }
1124                         return 0;
1125                 default:
1126                         printf("Invalid choice entered\n");
1127                         return -1;
1128                 }
1129         }
1130
1131         return -1;
1132 }
1133
1134 static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid, uid_t uid)
1135 {
1136         if (lhs_pkgid == NULL || rhs_pkgid == NULL) {
1137                 printf("pkgid is NULL\n");
1138                 return -1;
1139         }
1140
1141         int ret = 0;
1142         pkgmgrinfo_cert_compare_result_type_e result;
1143         if (uid != GLOBAL_USER)
1144                 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_pkgid, rhs_pkgid, uid, &result);
1145         else
1146                 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lhs_pkgid, rhs_pkgid, &result);
1147         if (ret != PMINFO_R_OK) {
1148                 return -1;
1149         }
1150
1151         printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
1152         printf("pkgid =[%s] and [%s] compare result = [%d] \n", lhs_pkgid, rhs_pkgid, result);
1153         return 0;
1154 }
1155
1156 static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_t uid)
1157 {
1158         if (lhs_appid == NULL || rhs_appid == NULL) {
1159                 printf("appid is NULL\n");
1160                 return -1;
1161         }
1162
1163         int ret = 0;
1164         pkgmgrinfo_cert_compare_result_type_e result;
1165         if (uid != GLOBAL_USER)
1166                 ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_appid, rhs_appid, uid, &result);
1167         else
1168                 ret = pkgmgrinfo_pkginfo_compare_app_cert_info(lhs_appid, rhs_appid, &result);
1169         if (ret != PMINFO_R_OK) {
1170                 return -1;
1171         }
1172
1173         printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n");
1174         printf("appid =[%s] and [%s] compare result = [%d] \n", lhs_appid, rhs_appid, result);
1175         return 0;
1176 }
1177
1178 static int __set_certinfo_in_db(char *pkgid, uid_t uid)
1179 {
1180         if (pkgid == NULL) {
1181                 printf("pkgid is NULL\n");
1182                 return -1;
1183         }
1184         int ret = 0;
1185         int choice = -1;
1186         char *value = NULL;
1187         pkgmgr_instcertinfo_h handle = NULL;
1188         ret = pkgmgr_installer_create_certinfo_set_handle(&handle);
1189         if (ret < 0) {
1190                 printf("pkgmgr_installer_create_certinfo_set_handle failed\n");
1191                 return -1;
1192         }
1193         while (choice != 0)
1194         {
1195                 printf("Enter the choice you want to set\n");
1196                 printf("0 --> to set data in DB\n");
1197                 printf("1 --> author root certificate\n");
1198                 printf("2 --> author intermediate certificate\n");
1199                 printf("3 --> author signer certificate\n");
1200                 printf("4 --> distributor root certificate\n");
1201                 printf("5 --> distributor intermediate certificate\n");
1202                 printf("6 --> distributor signer certificate\n");
1203                 printf("7 --> distributor2 root certificate\n");
1204                 printf("8 --> distributor2 intermediate certificate\n");
1205                 printf("9 --> distributor2 signer certificate\n");
1206                 choice = __get_integer_input_data();
1207                 switch (choice) {
1208                 case 0:
1209                         ret = pkgmgr_installer_save_certinfo(pkgid, handle, uid);
1210                         if (ret < 0) {
1211                                 printf("pkgmgr_installer_save_certinfo failed\n");
1212                                 pkgmgr_installer_destroy_certinfo_set_handle(handle);
1213                                 return -1;
1214                         }
1215                         ret = pkgmgr_installer_destroy_certinfo_set_handle(handle);
1216                         if (ret < 0) {
1217                                 printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n");
1218                                 return -1;
1219                         }
1220                         return 0;
1221                 case 1:
1222                         printf("Enter Author Root Certificate Value: \n");
1223                         value = __get_string_input_data();
1224                         ret = pkgmgr_installer_set_cert_value(handle, 0, value);
1225                         if (ret < 0) {
1226                                 printf("pkgmgr_installer_set_cert_value failed\n");
1227                                 ret = -1;
1228                                 goto err;
1229                         }
1230                         free(value);
1231                         value = NULL;
1232                         break;
1233                 case 2:
1234                         printf("Enter Author Intermediate Certificate Value: \n");
1235                         value = __get_string_input_data();
1236                         ret = pkgmgr_installer_set_cert_value(handle, 1, value);
1237                         if (ret < 0) {
1238                                 printf("pkgmgr_installer_set_cert_value failed\n");
1239                                 ret = -1;
1240                                 goto err;
1241                         }
1242                         free(value);
1243                         value = NULL;
1244                         break;
1245                 case 3:
1246                         printf("Enter Author Signer Certificate Value: \n");
1247                         value = __get_string_input_data();
1248                         ret = pkgmgr_installer_set_cert_value(handle, 2, value);
1249                         if (ret < 0) {
1250                                 printf("pkgmgr_installer_set_cert_value failed\n");
1251                                 ret = -1;
1252                                 goto err;
1253                         }
1254                         free(value);
1255                         value = NULL;
1256                         break;
1257                 case 4:
1258                         printf("Enter Distributor Root Certificate Value: \n");
1259                         value = __get_string_input_data();
1260                         ret = pkgmgr_installer_set_cert_value(handle, 3, value);
1261                         if (ret < 0) {
1262                                 printf("pkgmgr_installer_set_cert_value failed\n");
1263                                 ret = -1;
1264                                 goto err;
1265                         }
1266                         free(value);
1267                         value = NULL;
1268                         break;
1269                 case 5:
1270                         printf("Enter Distributor Intermediate Certificate Value: \n");
1271                         value = __get_string_input_data();
1272                         ret = pkgmgr_installer_set_cert_value(handle, 4, value);
1273                         if (ret < 0) {
1274                                 printf("pkgmgr_installer_set_cert_value failed\n");
1275                                 ret = -1;
1276                                 goto err;
1277                         }
1278                         free(value);
1279                         value = NULL;
1280                         break;
1281                 case 6:
1282                         printf("Enter Distributor Signer Certificate Value: \n");
1283                         value = __get_string_input_data();
1284                         ret = pkgmgr_installer_set_cert_value(handle, 5, value);
1285                         if (ret < 0) {
1286                                 printf("pkgmgr_installer_set_cert_value failed\n");
1287                                 ret = -1;
1288                                 goto err;
1289                         }
1290                         free(value);
1291                         value = NULL;
1292                         break;
1293                 case 7:
1294                         printf("Enter Distributor2 Root Certificate Value: \n");
1295                         value = __get_string_input_data();
1296                         ret = pkgmgr_installer_set_cert_value(handle, 6, value);
1297                         if (ret < 0) {
1298                                 printf("pkgmgr_installer_set_cert_value failed\n");
1299                                 ret = -1;
1300                                 goto err;
1301                         }
1302                         free(value);
1303                         value = NULL;
1304                         break;
1305                 case 8:
1306                         printf("Enter Distributor2 Intermediate Certificate Value: \n");
1307                         value = __get_string_input_data();
1308                         ret = pkgmgr_installer_set_cert_value(handle, 7, value);
1309                         if (ret < 0) {
1310                                 printf("pkgmgr_installer_set_cert_value failed\n");
1311                                 ret = -1;
1312                                 goto err;
1313                         }
1314                         free(value);
1315                         value = NULL;
1316                         break;
1317                 case 9:
1318                         printf("Enter Distributor2 Signer Certificate Value: \n");
1319                         value = __get_string_input_data();
1320                         ret = pkgmgr_installer_set_cert_value(handle, 8, value);
1321                         if (ret < 0) {
1322                                 printf("pkgmgr_installer_set_cert_value failed\n");
1323                                 ret = -1;
1324                                 goto err;
1325                         }
1326                         free(value);
1327                         value = NULL;
1328                         break;
1329                 default:
1330                         printf("Invalid Number Entered\n");
1331                         choice = 0;
1332                         ret = pkgmgr_installer_destroy_certinfo_set_handle(handle);
1333                         if (ret < 0) {
1334                                 printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n");
1335                                 return -1;
1336                         }
1337                         break;
1338                 }
1339         }
1340 err:
1341         if (value) {
1342                 free(value);
1343                 value = NULL;
1344         }
1345         pkgmgr_installer_destroy_certinfo_set_handle(handle);
1346         return ret;
1347 }
1348
1349 static int __set_pkginfo_in_db(char *pkgid, uid_t uid)
1350 {
1351         if (pkgid == NULL) {
1352                 printf("pkgid is NULL\n");
1353                 return -1;
1354         }
1355         int ret = 0;
1356         int choice = -1;
1357         int preload = -1;
1358         int removable = -1;
1359         int location = -1;
1360         char *locale = NULL;
1361         pkgmgr_pkgdbinfo_h handle = NULL;
1362         INSTALL_LOCATION storage = 0;
1363
1364         if(uid != GLOBAL_USER)
1365                 ret = pkgmgrinfo_create_pkgusrdbinfo(pkgid, uid, &handle);
1366         else
1367                 ret = pkgmgrinfo_create_pkgdbinfo(pkgid, &handle);
1368         if (ret < 0) {
1369                 printf("pkgmgrinfo_create_pkgdbinfo failed\n");
1370                 return -1;
1371         }
1372         while (choice != 0)
1373         {
1374                 printf("Enter the choice you want to set\n");
1375                 printf("0 --> to set data in DB\n");
1376                 printf("1 --> pkg type\n");
1377                 printf("2 --> pkg version\n");
1378                 printf("3 --> pkg instal location\n");
1379                 printf("4 --> pkg label\n");
1380                 printf("5 --> pkg icon\n");
1381                 printf("6 --> pkg description\n");
1382                 printf("7 --> pkg author\n");
1383                 printf("8 --> pkg removable\n");
1384                 printf("9 --> pkg preload\n");
1385                 printf("10 --> pkg size\n");
1386                 printf("11 --> pkg installed storage\n");
1387                 choice = __get_integer_input_data();
1388                 switch (choice) {
1389                 case 0:
1390                         ret = pkgmgrinfo_save_pkgdbinfo(handle);
1391                         if (ret < 0) {
1392                                 printf("pkgmgrinfo_save_pkgdbinfo failed\n");
1393                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1394                                 return -1;
1395                         }
1396                         ret = pkgmgrinfo_destroy_pkgdbinfo(handle);
1397                         if (ret < 0) {
1398                                 printf("pkgmgrinfo_destroy_pkgdbinfo failed\n");
1399                                 return -1;
1400                         }
1401                         break;
1402                 case 1:
1403                         printf("Enter type: \n");
1404                         char *type = __get_string_input_data();
1405                         ret = pkgmgrinfo_set_type_to_pkgdbinfo(handle, type);
1406                         if (ret < 0) {
1407                                 printf("pkgmgrinfo_set_type_to_pkgdbinfo failed\n");
1408                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1409                                 free(type);
1410                                 return -1;
1411                         }
1412                         free(type);
1413                         break;
1414                 case 2:
1415                         printf("Enter version: \n");
1416                         char *version = __get_string_input_data();
1417                         ret = pkgmgrinfo_set_version_to_pkgdbinfo(handle, version);
1418                         if (ret < 0) {
1419                                 printf("pkgmgrinfo_set_version_to_pkgdbinfo failed\n");
1420                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1421                                 free(version);
1422                                 return -1;
1423                         }
1424                         free(version);
1425                         break;
1426                 case 3:
1427                         printf("Enter install location [0:internal | 1:external]: \n");
1428                         location = __get_integer_input_data();
1429                         ret = pkgmgrinfo_set_install_location_to_pkgdbinfo(handle, location);
1430                         if (ret < 0) {
1431                                 printf("pkgmgrinfo_set_install_location_to_pkgdbinfo failed\n");
1432                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1433                                 return -1;
1434                         }
1435                         break;
1436                 case 4:
1437                         printf("Enter label :\n");
1438                         char *label = __get_string_input_data();
1439                         printf("Enter locale ['def' for default]: \n");
1440                         locale = __get_string_input_data();
1441                         if (strcmp(locale, "def") == 0)
1442                                 ret = pkgmgrinfo_set_label_to_pkgdbinfo(handle, label, NULL);
1443                         else
1444                                 ret = pkgmgrinfo_set_label_to_pkgdbinfo(handle, label, locale);
1445                         if (ret < 0) {
1446                                 printf("pkgmgrinfo_set_label_to_pkgdbinfo failed\n");
1447                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1448                                 free(locale);
1449                                 free(label);
1450                                 return -1;
1451                         }
1452                         free(locale);
1453                         free(label);
1454                         break;
1455                 case 5:
1456                         printf("Enter icon: \n");
1457                         char *icon = __get_string_input_data();
1458                         printf("Enter locale ['def' for default]: \n");
1459                         locale = __get_string_input_data();
1460                         if (strcmp(locale, "def") == 0)
1461                                 ret = pkgmgrinfo_set_icon_to_pkgdbinfo(handle, icon, NULL);
1462                         else
1463                                 ret = pkgmgrinfo_set_icon_to_pkgdbinfo(handle, icon, locale);
1464                         if (ret < 0) {
1465                                 printf("pkgmgrinfo_set_icon_to_pkgdbinfo failed\n");
1466                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1467                                 free(locale);
1468                                 free(icon);
1469                                 return -1;
1470                         }
1471                         free(locale);
1472                         free(icon);
1473                         break;
1474                 case 6:
1475                         printf("Enter description: \n");
1476                         char *description = __get_string_input_data();
1477                         printf("Enter locale ['def' for default]: \n");
1478                         locale = __get_string_input_data();
1479                         if (strcmp(locale, "def") == 0)
1480                                 ret = pkgmgrinfo_set_description_to_pkgdbinfo(handle, description, NULL);
1481                         else
1482                                 ret = pkgmgrinfo_set_description_to_pkgdbinfo(handle, description, locale);
1483                         if (ret < 0) {
1484                                 printf("pkgmgrinfo_set_description_to_pkgdbinfo failed\n");
1485                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1486                                 free(locale);
1487                                 free(description);
1488                                 return -1;
1489                         }
1490                         free(locale);
1491                         free(description);
1492                         break;
1493                 case 7:
1494                         printf("Enter author name: \n");
1495                         char *author_name = __get_string_input_data();
1496                         printf("Enter locale ['def' for default]: \n");
1497                         locale = __get_string_input_data();
1498                         printf("Enter author email: \n");
1499                         char *author_email = __get_string_input_data();
1500                         printf("Enter author href: \n");
1501                         char *author_href = __get_string_input_data();
1502                         if (strcmp(locale, "def") == 0)
1503                                 ret = pkgmgrinfo_set_author_to_pkgdbinfo(handle, author_name, author_email, author_href, NULL);
1504                         else
1505                                 ret = pkgmgrinfo_set_author_to_pkgdbinfo(handle, author_name, author_email, author_href, locale);
1506                         if (ret < 0) {
1507                                 printf("pkgmgrinfo_set_author_to_pkgdbinfo failed\n");
1508                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1509                                 free(locale);
1510                                 free(author_name);
1511                                 free(author_email);
1512                                 free(author_href);
1513                                 return -1;
1514                         }
1515                         free(locale);
1516                         free(author_name);
1517                         free(author_email);
1518                         free(author_href);
1519                         break;
1520                 case 8:
1521                         printf("Enter removable [0:false | 1:true]: \n");
1522                         removable = __get_integer_input_data();
1523                         ret = pkgmgrinfo_set_removable_to_pkgdbinfo(handle, removable);
1524                         if (ret < 0) {
1525                                 printf("pkgmgrinfo_set_removable_to_pkgdbinfo failed\n");
1526                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1527                                 return -1;
1528                         }
1529                         break;
1530                 case 9:
1531                         printf("Enter preload [0:false | 1:true]: \n");
1532                         preload = __get_integer_input_data();
1533                         ret = pkgmgrinfo_set_preload_to_pkgdbinfo(handle, preload);
1534                         if (ret < 0) {
1535                                 printf("pkgmgrinfo_set_preload_to_pkgdbinfo failed\n");
1536                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1537                                 return -1;
1538                         }
1539                         break;
1540                 case 10:
1541                         printf("Enter size in MB \n");
1542                         char *size = __get_string_input_data();
1543                         ret = pkgmgrinfo_set_size_to_pkgdbinfo(handle, size);
1544                         if (ret < 0) {
1545                                 printf("pkgmgrinfo_set_size_to_pkgdbinfo failed\n");
1546                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1547                                 free(size);
1548                                 return -1;
1549                         }
1550                         free(size);
1551                         break;
1552                 case 11:
1553                         printf("Enter insatlled storage [ 0:INTERNAL | 1:EXTERNAL ] \n");
1554                         storage = __get_integer_input_data();
1555                         ret = pkgmgrinfo_set_installed_storage_to_pkgdbinfo(handle, storage);
1556                         if (ret < 0) {
1557                                 printf("pkgmgrinfo_set_installed_storage_to_pkgdbinfo failed\n");
1558                                 pkgmgrinfo_destroy_pkgdbinfo(handle);
1559                                 return -1;
1560                         }
1561                         break;
1562                 default:
1563                         printf("Invalid number entered\n");
1564                         continue;
1565                 }
1566         }
1567         return 0;
1568 }
1569
1570 static int __insert_manifest_in_db(char *manifest, uid_t uid)
1571 {
1572         int ret = 0;
1573         if (manifest == NULL) {
1574                 printf("Manifest file is NULL\n");
1575                 return -1;
1576         }
1577         if (uid != GLOBAL_USER)
1578                 ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, uid, NULL);
1579         else
1580                 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
1581         if (ret < 0) {
1582                 printf("insert in db failed\n");
1583                 return -1;
1584         }
1585         return 0;
1586 }
1587
1588 static int __fota_insert_manifest_in_db(char *manifest, uid_t uid)
1589 {
1590         int ret = 0;
1591         char *temp[] = {"fota=true", NULL};
1592
1593         if (manifest == NULL) {
1594                 printf("Manifest file is NULL\n");
1595                 return -1;
1596         }
1597         if (uid != GLOBAL_USER)
1598                 ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, uid, NULL);
1599         else
1600                 ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
1601         if (ret < 0) {
1602                 printf("insert in db failed\n");
1603                 return -1;
1604         }
1605         return 0;
1606 }
1607
1608 static int __remove_manifest_from_db(char *manifest, uid_t uid)
1609 {
1610         int ret = 0;
1611         if (manifest == NULL) {
1612                 printf("Manifest file is NULL\n");
1613                 return -1;
1614         }
1615         if (uid != GLOBAL_USER)
1616                 ret = pkgmgr_parser_parse_usr_manifest_for_uninstallation(manifest, uid, NULL);
1617         else
1618                 ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
1619         if (ret < 0) {
1620                 printf("remove from db failed\n");
1621                 return -1;
1622         }
1623         return 0;
1624 }
1625
1626 int app_func(const pkgmgr_appinfo_h handle, void *user_data)
1627 {
1628         char *appid;
1629         char *data = NULL;
1630         if (user_data) {
1631                 data = (char *)user_data;
1632         }
1633         int ret = -1;
1634         char *exec = NULL;
1635         char *icon = NULL;
1636         char *label = NULL;
1637         pkgmgr_app_component component = 0;
1638         char *apptype = NULL;
1639         bool nodisplay = 0;
1640         bool multiple = 0;
1641         bool taskmanage = 0;
1642         pkgmgr_hwacceleration_type hwacceleration;
1643         pkgmgrinfo_app_screenreader screenreader;
1644         bool onboot = 0;
1645         bool autorestart = 0;
1646         char *package = NULL;
1647
1648         ret = pkgmgr_appinfo_get_appid(handle, &appid);
1649         if (ret < 0) {
1650                 printf("Failed to get appid\n");
1651         }
1652         if (appid)
1653                 printf("Appid: %s\n", appid);
1654
1655         ret = pkgmgr_appinfo_get_pkgid(handle, &package);
1656         if (ret < 0) {
1657                 printf("Failed to get package\n");
1658         }
1659         if (package)
1660                 printf("Package: %s\n", package);
1661
1662         ret = pkgmgr_appinfo_get_exec(handle, &exec);
1663         if (ret < 0) {
1664                 printf("Failed to get exec\n");
1665         }
1666         if (exec)
1667                 printf("Exec: %s\n", exec);
1668
1669         ret = pkgmgr_appinfo_get_icon(handle, &icon);
1670         if (ret < 0) {
1671                 printf("Failed to get icon\n");
1672         }
1673         if (icon)
1674                 printf("Icon: %s\n", icon);
1675
1676         ret = pkgmgr_appinfo_get_label(handle, &label);
1677         if (ret < 0) {
1678                 printf("Failed to get label\n");
1679         }
1680         if (label)
1681                 printf("Label: %s\n", label);
1682
1683         ret = pkgmgr_appinfo_get_component(handle, &component);
1684         if (ret < 0) {
1685                 printf("Failed to get component\n");
1686         }
1687
1688         ret = pkgmgr_appinfo_get_apptype(handle, &apptype);
1689         if (ret < 0) {
1690                 printf("Failed to get apptype\n");
1691         }
1692         if (apptype)
1693                 printf("Apptype: %s\n", apptype);
1694
1695         if (component == PM_UI_APP) {
1696                 printf("component: uiapp\n");
1697                 ret = pkgmgr_appinfo_is_multiple(handle, &multiple);
1698                 if (ret < 0) {
1699                         printf("Failed to get multiple\n");
1700                 } else {
1701                         printf("Multiple: %d\n", multiple);
1702                 }
1703
1704                 ret = pkgmgr_appinfo_is_nodisplay(handle, &nodisplay);
1705                 if (ret < 0) {
1706                         printf("Failed to get nodisplay\n");
1707                 } else {
1708                         printf("Nodisplay: %d \n", nodisplay);
1709                 }
1710
1711                 ret = pkgmgr_appinfo_is_taskmanage(handle, &taskmanage);
1712                 if (ret < 0) {
1713                         printf("Failed to get taskmanage\n");
1714                 } else {
1715                         printf("Taskmanage: %d\n", taskmanage);
1716                 }
1717
1718                 ret = pkgmgr_appinfo_get_hwacceleration(handle, &hwacceleration);
1719                 if (ret < 0) {
1720                         printf("Failed to get hwacceleration\n");
1721                 } else {
1722                         printf("hw-acceleration: %d\n", hwacceleration);
1723                 }
1724
1725                 ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
1726                 if (ret < 0) {
1727                         printf("Failed to get screenreader\n");
1728                 } else {
1729                         printf("screenreader: %d\n", screenreader);
1730                 }
1731
1732         }
1733         if (component == PM_SVC_APP) {
1734                 printf("component: svcapp\n");
1735                 ret = pkgmgr_appinfo_is_onboot(handle, &onboot);
1736                 if (ret < 0) {
1737                         printf("Failed to get onboot\n");
1738                 } else {
1739                         printf("Onboot: %d\n", onboot);
1740                 }
1741
1742                 ret = pkgmgr_appinfo_is_autorestart(handle, &autorestart);
1743                 if (ret < 0) {
1744                         printf("Failed to get autorestart\n");
1745                 } else {
1746                         printf("Autorestart: %d \n", autorestart);
1747                 }
1748         }
1749         if (data)
1750                 printf("user_data : %s\n\n", data);
1751
1752         return 0;
1753 }
1754
1755
1756 static int __pkg_list_cb (const pkgmgr_pkginfo_h handle, void *user_data)
1757 {
1758         char *test_data = "test data";
1759         int ret = -1;
1760         char *pkgid;
1761         char *pkg_type;
1762         char *pkg_version;
1763         bool preload = 0;
1764         int installed_time = -1;
1765
1766         pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle;
1767         ret = pkgmgr_pkginfo_get_pkgid(handle, &pkgid);
1768         if(ret < 0) {
1769                 printf("pkgmgr_pkginfo_get_pkgid() failed\n");
1770         }
1771         ret = pkgmgr_pkginfo_get_type(handle, &pkg_type);
1772         if(ret < 0) {
1773                 printf("pkgmgr_pkginfo_get_type() failed\n");
1774         }
1775         ret = pkgmgr_pkginfo_get_version(handle, &pkg_version);
1776         if(ret < 0) {
1777                 printf("pkgmgr_pkginfo_get_version() failed\n");
1778         }
1779         ret = pkgmgr_pkginfo_is_preload(handle, &preload);
1780         if(ret < 0) {
1781                 printf("pkgmgr_pkginfo_is_preload() failed\n");
1782         }
1783         ret = pkgmgr_pkginfo_get_installed_time(handle, &installed_time);
1784         if(ret < 0) {
1785                 printf("pkgmgr_pkginfo_get_installed_time() failed\n");
1786         }
1787
1788
1789         printf("---------------------------------------\n");
1790         printf("pkg_type [%s]\tpkgid [%s]\tversion [%s]\tpreload [%d]\tinstalled_time [%d]\n", pkg_type,
1791                pkgid, pkg_version, preload, installed_time);
1792
1793         if (uid_info->uid != GLOBAL_USER) {
1794                 printf("**List of Ui-Apps**\n");
1795                 ret = pkgmgr_appinfo_get_usr_list(handle, PM_UI_APP, app_func, (void *)test_data, uid_info->uid);
1796                 if (ret < 0) {
1797                         printf("pkgmgr_get_info_app() failed\n");
1798                 }
1799                 printf("**List of Svc-Apps**\n");
1800                 ret = pkgmgr_appinfo_get_usr_list(handle, PM_SVC_APP, app_func, (void *)test_data, uid_info->uid);
1801                 if (ret < 0) {
1802                         printf("pkgmgr_get_info_app() failed\n");
1803                 }
1804         } else {
1805                 printf("**List of Ui-Apps**\n");
1806                 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, app_func, (void *)test_data);
1807                 if (ret < 0) {
1808                         printf("pkgmgr_get_info_app() failed\n");
1809                 }
1810                 printf("**List of Svc-Apps**\n");
1811                 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, app_func, (void *)test_data);
1812                 if (ret < 0) {
1813                         printf("pkgmgr_get_info_app() failed\n");
1814                 }
1815         }
1816         printf("---------------------------------------\n");
1817
1818         return 0;
1819 }
1820
1821 static int __get_pkg_list(uid_t uid)
1822 {
1823         int ret = -1;
1824         if (uid != GLOBAL_USER)
1825                 ret = pkgmgr_pkginfo_get_usr_list(__pkg_list_cb, NULL, uid);
1826         else
1827                 ret = pkgmgr_pkginfo_get_list(__pkg_list_cb, NULL);
1828         if (ret < 0) {
1829                 printf("pkgmgr_pkginfo_get_list() failed\n");
1830                 return -1;
1831         }
1832         return 0;
1833 }
1834
1835 static int __get_installed_app_list(uid_t uid)
1836 {
1837         int ret = -1;
1838         if(uid != GLOBAL_USER)
1839                 ret = pkgmgrinfo_appinfo_get_usr_installed_list(app_func, uid, NULL);
1840         else
1841                 ret = pkgmgrinfo_appinfo_get_installed_list(app_func, NULL);
1842         if (ret < 0) {
1843                 printf("pkgmgrinfo_appinfo_get_installed_list() failed\n");
1844                 return -1;
1845         }
1846         return 0;
1847 }
1848
1849
1850 static int __app_category_list_cb(const char *category_name, void *user_data)
1851 {
1852         if (category_name)
1853                 printf("Category: %s\n", category_name);
1854         return 0;
1855 }
1856
1857 static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data)
1858 {
1859         if (metadata_name && metadata_value) {
1860                 printf("Name: %s\n", metadata_name);
1861                 printf("Value: %s\n",   metadata_value);
1862                 printf("\n");
1863         }
1864         return 0;
1865 }
1866
1867 static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data)
1868 {
1869         printf("-------------------------------------------------------\n");
1870         printf("Operation: %s\n", operation);
1871         printf("Uri: %s\n", uri);
1872         printf("Mime: %s\n", mime);
1873         printf("-------------------------------------------------------\n\n");
1874         return 0;
1875 }
1876
1877
1878 static int __get_app_category_list(char *appid)
1879 {
1880         int ret = -1;
1881         pkgmgr_appinfo_h handle;
1882         ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
1883         if (ret < 0) {
1884                 printf("Failed to get handle\n");
1885                 return -1;
1886         }
1887         ret = pkgmgr_appinfo_foreach_category(handle, __app_category_list_cb, NULL);
1888         if (ret < 0) {
1889                 printf("pkgmgr_appinfo_foreach_category() failed\n");
1890                 pkgmgr_appinfo_destroy_appinfo(handle);
1891                 return -1;
1892         }
1893         pkgmgr_appinfo_destroy_appinfo(handle);
1894         return 0;
1895 }
1896
1897 static int __get_app_metadata_list(char *appid)
1898 {
1899         int ret = -1;
1900         pkgmgr_appinfo_h handle;
1901         ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
1902         if (ret < 0) {
1903                 printf("Failed to get handle\n");
1904                 return -1;
1905         }
1906         ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __app_metadata_list_cb, NULL);
1907         if (ret < 0) {
1908                 printf("pkgmgrinfo_appinfo_foreach_metadata() failed\n");
1909                 pkgmgr_appinfo_destroy_appinfo(handle);
1910                 return -1;
1911         }
1912         pkgmgr_appinfo_destroy_appinfo(handle);
1913         return 0;
1914 }
1915
1916 static int __get_app_control_list(char *appid)
1917 {
1918         int ret = -1;
1919         pkgmgr_appinfo_h handle;
1920         ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
1921         if (ret < 0) {
1922                 printf("Failed to get handle\n");
1923                 return -1;
1924         }
1925         ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __app_control_list_cb, NULL);
1926         if (ret < 0) {
1927                 printf("pkgmgrinfo_appinfo_foreach_appcontrol() failed\n");
1928                 pkgmgr_appinfo_destroy_appinfo(handle);
1929                 return -1;
1930         }
1931         pkgmgr_appinfo_destroy_appinfo(handle);
1932         return 0;
1933 }
1934
1935 static int __set_app_enabled(char *appid, bool enabled)
1936 {
1937         int ret = -1;
1938         ret = pkgmgrinfo_appinfo_set_state_enabled(appid, enabled);
1939         if (ret < 0) {
1940                 printf("Failed to get handle\n");
1941                 return -1;
1942         }
1943         return 0;
1944 }
1945
1946 static int __get_app_list(char *pkgid, uid_t uid)
1947 {
1948         pkgmgr_pkginfo_h handle;
1949         int ret = -1;
1950         char *test_data = "test data";
1951         if(uid != GLOBAL_USER)
1952                 ret = pkgmgr_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1953         else
1954                 ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &handle);
1955         if (ret < 0) {
1956                 printf("Failed to get handle\n");
1957                 return -1;
1958         }
1959         if (uid != GLOBAL_USER) {
1960                 printf("List of Ui-Apps\n\n");
1961                 ret = pkgmgr_appinfo_get_usr_list(handle, PM_UI_APP, app_func, (void *)test_data, uid);
1962                 if (ret < 0) {
1963                         printf("pkgmgr_appinfo_get_list() failed\n");
1964                 }
1965                 printf("List of Svc-Apps\n\n");
1966                 ret = pkgmgr_appinfo_get_usr_list(handle, PM_SVC_APP, app_func, (void *)test_data, uid);
1967                 if (ret < 0) {
1968                         printf("pkgmgr_appinfo_get_list() failed\n");
1969                 }
1970         } else {
1971                 printf("List of Ui-Apps\n\n");
1972                 ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, app_func, (void *)test_data);
1973                 if (ret < 0) {
1974                         printf("pkgmgr_appinfo_get_list() failed\n");
1975                 }
1976                 printf("List of Svc-Apps\n\n");
1977                 ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, app_func, (void *)test_data);
1978                 if (ret < 0) {
1979                         printf("pkgmgr_appinfo_get_list() failed\n");
1980                 }
1981         }
1982         pkgmgr_pkginfo_destroy_pkginfo(handle);
1983         return 0;
1984 }
1985
1986 static int __get_pkg_info(char *pkgid, uid_t uid)
1987 {
1988         pkgmgrinfo_pkginfo_h handle;
1989         int ret = -1;
1990
1991         printf("Get Pkg Info Called [%s]\n", pkgid);
1992         if(uid != GLOBAL_USER)
1993                 ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle);
1994         else
1995                 ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
1996         if (ret < 0) {
1997                 printf("Failed to get handle\n");
1998                 return -1;
1999         }
2000
2001         __get_pkgmgrinfo_pkginfo(handle, NULL);
2002
2003         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
2004         return 0;
2005 }
2006
2007 static int __get_app_info(char *appid)
2008 {
2009         printf("Get App Info Called [%s]\n", appid);
2010         char *exec = NULL;
2011         char *app_id = NULL;
2012         char *apptype = NULL;
2013         char *icon = NULL;
2014         char *label = NULL;
2015         char *package = NULL;
2016         pkgmgr_app_component component = 0;
2017         bool nodisplay = 0;
2018         bool multiple = 0;
2019         bool taskmanage = 0;
2020         pkgmgr_hwacceleration_type hwacceleration;
2021         pkgmgrinfo_app_screenreader screenreader;
2022         bool onboot = 0;
2023         bool autorestart = 0;
2024         bool enabled = 0;
2025         bool preload = 0;
2026         pkgmgr_appinfo_h handle;
2027         int ret = -1;
2028
2029         ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
2030         if (ret < 0) {
2031                 printf("Failed to get handle\n");
2032                 return -1;
2033         }
2034
2035         ret = pkgmgr_appinfo_get_pkgid(handle, &package);
2036         if (ret < 0) {
2037                 printf("Failed to get package\n");
2038         }
2039
2040         ret = pkgmgr_appinfo_get_appid(handle, &app_id);
2041         if (ret < 0) {
2042                 printf("Failed to get exec\n");
2043         }
2044
2045         ret = pkgmgr_appinfo_get_label(handle, &label);
2046         if (ret < 0) {
2047                 printf("Failed to get label\n");
2048         }
2049         ret = pkgmgr_appinfo_get_icon(handle, &icon);
2050         if (ret < 0) {
2051                 printf("Failed to get icon\n");
2052         }
2053
2054         ret = pkgmgr_appinfo_get_exec(handle, &exec);
2055         if (ret < 0) {
2056                 printf("Failed to get exec\n");
2057         }
2058         ret = pkgmgr_appinfo_get_component(handle, &component);
2059         if (ret < 0) {
2060                 printf("Failed to get component\n");
2061         }
2062         ret = pkgmgr_appinfo_get_apptype(handle, &apptype);
2063         if (ret < 0) {
2064                 printf("Failed to get apptype\n");
2065         }
2066         ret = pkgmgr_appinfo_is_nodisplay(handle, &nodisplay);
2067         if (ret < 0) {
2068                 printf("Failed to get nodisplay\n");
2069         }
2070         ret = pkgmgr_appinfo_is_multiple(handle, &multiple);
2071         if (ret < 0) {
2072                 printf("Failed to get multiple\n");
2073         }
2074         ret = pkgmgr_appinfo_is_taskmanage(handle, &taskmanage);
2075         if (ret < 0) {
2076                 printf("Failed to get taskmanage\n");
2077         }
2078         ret = pkgmgr_appinfo_get_hwacceleration(handle, &hwacceleration);
2079         if (ret < 0) {
2080                 printf("Failed to get hwacceleration\n");
2081         }
2082         ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader);
2083         if (ret < 0) {
2084                 printf("Failed to get screenreader\n");
2085         }
2086         ret = pkgmgr_appinfo_is_onboot(handle, &onboot);
2087         if (ret < 0) {
2088                 printf("Failed to get onboot\n");
2089         }
2090         ret = pkgmgr_appinfo_is_autorestart(handle, &autorestart);
2091         if (ret < 0) {
2092                 printf("Failed to get autorestart\n");
2093         }
2094         ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled);
2095         if (ret < 0) {
2096                 printf("Failed to get enabled\n");
2097         }
2098         ret = pkgmgrinfo_appinfo_is_preload(handle, &preload);
2099         if (ret < 0) {
2100                 printf("Failed to get preload\n");
2101         }
2102
2103         if (app_id)
2104                 printf("Appid: %s\n", app_id);
2105
2106         if (package)
2107                 printf("Package: %s\n", package);
2108
2109         if (exec)
2110                 printf("Exec: %s\n", exec);
2111         if (apptype)
2112                 printf("Apptype: %s\n", apptype);
2113
2114         if (component == PM_UI_APP) {
2115                 printf("component: uiapp\n");
2116
2117                 if (icon)
2118                         printf("Icon: %s\n", icon);
2119                 if (label)
2120                         printf("Label: %s\n", label);
2121
2122                 printf("Nodisplay: %d\n", nodisplay);
2123                 printf("Multiple: %d\n", multiple);
2124                 printf("Taskmanage: %d\n", taskmanage);
2125                 printf("Hw-Acceleration: %d\n", hwacceleration);
2126                 printf("Screenreader: %d\n", screenreader);
2127         } else if (component == PM_SVC_APP) {
2128                 printf("component: svcapp\n");
2129
2130                 if (icon)
2131                         printf("Icon: %s\n", icon);
2132                 if (label)
2133                         printf("Label: %s\n", label);
2134
2135                 printf("Autorestart: %d\n", autorestart);
2136                 printf("Onboot: %d\n", onboot);
2137         } else {
2138                 printf("Invalid Component Type\n");
2139         }
2140
2141         printf("Enabled: %d\n", enabled);
2142         printf("Preload: %d\n", preload);
2143
2144         pkgmgr_appinfo_destroy_appinfo(handle);
2145         return 0;
2146
2147 }
2148
2149 static int __check_manifest_validation(char *manifest)
2150 {
2151         int ret = 0;
2152         if (manifest == NULL) {
2153                 printf("Manifest file is NULL\n");
2154                 return -1;
2155         }
2156         ret = pkgmgr_parser_check_manifest_validation(manifest);
2157         if (ret < 0) {
2158                 printf("check manifest validation failed\n");
2159                 return -1;
2160         }
2161         return 0;
2162 }
2163
2164 int main(int argc, char *argv[])
2165 {
2166         int ret = 0;
2167         char *locale = NULL;
2168         long starttime;
2169         long endtime;
2170         struct timeval tv;
2171
2172         gettimeofday(&tv, NULL);
2173         starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
2174
2175         locale = ail_vconf_get_str(VCONFKEY_LANGSET); 
2176         //Work around for https://bugs.tizen.org/jira/browse/TC-2399
2177         if (locale == NULL) {
2178                 printf("locale is NULL\n");
2179                 ret = -1;
2180                 goto end;
2181         }
2182         else
2183                 printf("Locale is %s\n", locale);
2184
2185
2186         if(getuid() == OWNER_ROOT) {
2187                 printf("User is Root! : Only tizenglobalapp or regular user are allowed\n");
2188                 return -1;
2189         }
2190         
2191         free(locale);
2192         locale = NULL;
2193         if (argc == 2) {
2194                 if (strcmp(argv[1], "--listpkg") == 0) {
2195                         ret = __get_pkg_list(getuid());
2196                         if (ret == -1) {
2197                                 printf("get pkg list failed\n");
2198                                 goto end;
2199                         } else {
2200                                 goto end;
2201                         }
2202                 } else if (strcmp(argv[1], "--app-flt") == 0) {
2203                         ret = __add_app_filter(getuid());
2204                         if (ret == -1) {
2205                                 printf("Adding app filter failed\n");
2206                                 goto end;
2207                         } else {
2208                                 goto end;
2209                         }
2210                 } else if (strcmp(argv[1], "--pkg-flt") == 0) {
2211                         ret = __add_pkg_filter(getuid());
2212                         if (ret == -1) {
2213                                 printf("Adding pkg filter failed\n");
2214                                 goto end;
2215                         } else {
2216                                 goto end;
2217                         }
2218                 } else if (strcmp(argv[1], "--metadata-flt") == 0) {
2219                         ret = __add_metadata_filter();
2220                         if (ret == -1) {
2221                                 printf("Adding pkg filter failed\n");
2222                                 goto end;
2223                         } else {
2224                                 goto end;
2225                         }
2226                 } else if (strcmp(argv[1], "--listapp") == 0) {
2227                         ret = __get_installed_app_list(getuid());
2228                         if (ret == -1) {
2229                                 printf("get installed app list failed\n");
2230                                 goto end;
2231                         } else {
2232                                 goto end;
2233                         }
2234                 } else {
2235                         __print_usage();
2236                         ret = -1;
2237                         goto end;
2238                 }
2239         }else if (argc == 4) {
2240                 if (strcmp(argv[1], "--setappenabled") == 0) {
2241                         ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true);
2242                         if (ret == -1) {
2243                                 printf("set app enabled failed\n");
2244                                 goto end;
2245                         }
2246                         goto end;
2247                 } else if(strcmp(argv[1], "--setpkgenabled") == 0) {
2248                         ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true);
2249                         if (ret == -1) {
2250                                 printf("set pkg enabled failed\n");
2251                                 goto end;
2252                         }
2253                         goto end;
2254                 } else if (strcmp(argv[1], "--cmp-pkgcert") == 0) {
2255                         ret = __compare_pkg_certinfo_from_db(argv[2], argv[3], getuid());
2256                         if (ret == -1) {
2257                                 printf("compare certinfo from db failed\n");
2258                                 goto end;
2259                         }
2260                         goto end;
2261                 } else if (strcmp(argv[1], "--cmp-appcert") == 0) {
2262                         ret = __compare_app_certinfo_from_db(argv[2], argv[3], getuid());
2263                         if (ret == -1) {
2264                                 printf("compare certinfo from db failed\n");
2265                                 goto end;
2266                         }
2267                         goto end;
2268                 } else if (strcmp(argv[1], "--arg-flt") == 0) {
2269                         ret = __add_arg_filter(argv[2], argv[3], getuid());
2270                         if (ret == -1) {
2271                                 printf("compare certinfo from db failed\n");
2272                                 goto end;
2273                         }
2274                         goto end;
2275                 } else {
2276                         __print_usage();
2277                         ret = -1;
2278                         goto end;
2279                 }
2280         }
2281
2282         if (argc != 3) {
2283                 __print_usage();
2284                 ret = -1;
2285                 goto end;
2286         }
2287         if (!argv[1] || !argv[2]) {
2288                         __print_usage();
2289                         ret = -1;
2290                         goto end;
2291         }
2292
2293         if (strcmp(argv[1], "--pkg") == 0) {
2294                 ret = __get_pkg_info(argv[2], getuid());
2295                 if (ret == -1) {
2296                         printf("get pkg info failed\n");
2297                         goto end;
2298                 }
2299         } else if (strcmp(argv[1], "--app") == 0) {
2300                 ret = __get_app_info(argv[2]);
2301                 if (ret == -1) {
2302                         printf("get app info failed\n");
2303                         goto end;
2304                 }
2305         } else if (strcmp(argv[1], "--list") == 0) {
2306                 ret = __get_app_list(argv[2], getuid());
2307                 if (ret == -1) {
2308                         printf("get app list failed\n");
2309                         goto end;
2310                 }
2311         } else if (strcmp(argv[1], "--imd") == 0) {
2312                 ret = __insert_manifest_in_db(argv[2], getuid());
2313                 if (ret == -1) {
2314                         printf("insert in db failed\n");
2315                         goto end;
2316                 }
2317         } else if (strcmp(argv[1], "--fota") == 0) {
2318                 ret = __fota_insert_manifest_in_db(argv[2], getuid());
2319                 if (ret == -1) {
2320                         printf("insert in db failed\n");
2321                         goto end;
2322                 }
2323         } else if (strcmp(argv[1], "--rmd") == 0) {
2324                 ret = __remove_manifest_from_db(argv[2], getuid());
2325                 if (ret == -1) {
2326                         printf("remove from db failed\n");
2327                         goto end;
2328                 }
2329         } else if (strcmp(argv[1], "--setdb") == 0) {
2330                 ret = __set_pkginfo_in_db(argv[2], getuid());
2331                 if (ret == -1) {
2332                         printf("set pkginfo in db failed\n");
2333                         goto end;
2334                 }
2335         } else if (strcmp(argv[1], "--setcert") == 0) {
2336                 ret = __set_certinfo_in_db(argv[2], getuid());
2337                 if (ret == -1) {
2338                         printf("set certinfo in db failed\n");
2339                         goto end;
2340                 }
2341         } else if (strcmp(argv[1], "--getcert") == 0) {
2342                 ret = __get_certinfo_from_db(argv[2], getuid());
2343                 if (ret == -1) {
2344                         printf("get certinfo from db failed\n");
2345                         goto end;
2346                 }
2347         } else if (strcmp(argv[1], "--delcert") == 0) {
2348                 ret = __del_certinfo_from_db(argv[2]);
2349                 if (ret == -1) {
2350                         printf("del certinfo from db failed\n");
2351                         goto end;
2352                 }
2353         } else if (strcmp(argv[1], "--check") == 0) {
2354                 ret = __check_manifest_validation(argv[2]);
2355                 if (ret == -1) {
2356                         printf("check manifest failed\n");
2357                         goto end;
2358                 }
2359         } else if (strcmp(argv[1], "--category") == 0) {
2360                 ret = __get_app_category_list(argv[2]);
2361                 if (ret == -1) {
2362                         printf("get app category list failed\n");
2363                         goto end;
2364                 }
2365         } else if (strcmp(argv[1], "--metadata") == 0) {
2366                 ret = __get_app_metadata_list(argv[2]);
2367                 if (ret == -1) {
2368                         printf("get app metadata list failed\n");
2369                         goto end;
2370                 }
2371         }  else if (strcmp(argv[1], "--appcontrol") == 0) {
2372                 ret = __get_app_control_list(argv[2]);
2373                 if (ret == -1) {
2374                         printf("get app control list failed\n");
2375                         goto end;
2376                 }
2377         } else
2378                 __print_usage();
2379
2380 end:
2381
2382         gettimeofday(&tv, NULL);
2383         endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
2384
2385         printf("spend time for pkginfo is [%d]ms\n", (int)(endtime - starttime));
2386
2387         return ret;
2388 }