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