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