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