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