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