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