implement app screen reader
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgr-info.c
index eadaaf1..b0568ee 100755 (executable)
@@ -28,6 +28,7 @@
 #include <sqlite3.h>
 #include <vconf.h>
 #include <glib.h>
+#include <ctype.h>
 #include <assert.h>
 
 #include <libxml/parser.h>
@@ -36,7 +37,9 @@
 
 #include "pkgmgr_parser.h"
 #include "pkgmgr-info-internal.h"
+#include "pkgmgr-info-debug.h"
 #include "pkgmgr-info.h"
+#include "pkgmgr_parser_db.h"
 #include <dirent.h>
 #include <sys/stat.h>
 
@@ -45,6 +48,7 @@
 
 #define MANIFEST_DB    "/opt/dbspace/.pkgmgr_parser.db"
 #define MAX_QUERY_LEN  4096
+#define MAX_CERT_TYPE  9
 #define CERT_DB                "/opt/dbspace/.pkgmgr_cert.db"
 #define DATACONTROL_DB "/opt/usr/dbspace/.app-package.db"
 #define PKG_TYPE_STRING_LEN_MAX                128
                                "LEFT OUTER JOIN package_app_app_category " \
                                "ON package_app_info.app_id=package_app_app_category.app_id where "
 
+#define METADATA_FILTER_QUERY_SELECT_CLAUSE    "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
+                               "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
+                               "ON package_app_info.app_id=package_app_app_metadata.app_id where "
+
+#define METADATA_FILTER_QUERY_UNION_CLAUSE     " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
+
 #define LANGUAGE_LENGTH 2
 
 typedef struct _pkgmgr_instcertinfo_x {
        char *pkgid;
-       char *auth_signer_cert;
-       char *auth_im_cert;
-       char *auth_root_cert;
-       char *dist_signer_cert;
-       char *dist_im_cert;
-       char *dist_root_cert;
-       char *dist2_signer_cert;
-       char *dist2_im_cert;
-       char *dist2_root_cert;
+       char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
+       int is_new[MAX_CERT_TYPE];              /*whether already exist in table or not*/
+       int ref_count[MAX_CERT_TYPE];           /*reference count of certificate data*/
+       int cert_id[MAX_CERT_TYPE];             /*certificate ID in index table*/
 } pkgmgr_instcertinfo_x;
 
-sqlite3 *cert_db = NULL;
+typedef struct _pkgmgr_certindexinfo_x {
+       int cert_id;
+       int cert_ref_count;
+} pkgmgr_certindexinfo_x;
 
 typedef struct _pkgmgr_pkginfo_x {
        manifest_x *manifest_info;
-       char *tmp;
-       char *tmp_dup;
+       char *locale;
 
        struct _pkgmgr_pkginfo_x *prev;
        struct _pkgmgr_pkginfo_x *next;
 } pkgmgr_pkginfo_x;
 
 typedef struct _pkgmgr_cert_x {
-       const char *pkgid;
-       const char *certvalue;
+       char *pkgid;
+       int cert_id;
 } pkgmgr_cert_x;
 
 typedef struct _pkgmgr_datacontrol_x {
@@ -138,6 +145,7 @@ typedef struct _pkgmgr_locale_x {
 
 typedef struct _pkgmgr_appinfo_x {
        const char *package;
+       char *locale;
        pkgmgrinfo_app_component app_component;
        union {
                uiapplication_x *uiapp_info;
@@ -147,15 +155,9 @@ typedef struct _pkgmgr_appinfo_x {
 
 typedef struct _pkgmgr_certinfo_x {
        char *pkgid;
-       char *auth_signer_cert;
-       char *auth_im_cert;
-       char *auth_root_cert;
-       char *dist_signer_cert;
-       char *dist_im_cert;
-       char *dist_root_cert;
-       char *dist2_signer_cert;
-       char *dist2_im_cert;
-       char *dist2_root_cert;
+       char *cert_value;
+       char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
+       int cert_id[MAX_CERT_TYPE];             /*certificate ID in index table*/
 } pkgmgr_certinfo_x;
 
 /*For filter APIs*/
@@ -165,6 +167,7 @@ typedef struct _pkgmgrinfo_filter_x {
 
 typedef struct _pkgmgrinfo_node_x {
        int prop;
+       char *key;
        char *value;
 } pkgmgrinfo_node_x;
 
@@ -172,42 +175,43 @@ typedef struct _pkgmgrinfo_appcontrol_x {
        int operation_count;
        int uri_count;
        int mime_count;
+       int subapp_count;
        char **operation;
        char **uri;
        char **mime;
+       char **subapp;
 } pkgmgrinfo_appcontrol_x;
 
 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
 
 char *pkgtype = "rpm";
-static char glocale[PKG_LOCALE_STRING_LEN_MAX];
 __thread sqlite3 *manifest_db = NULL;
 __thread sqlite3 *datacontrol_db = NULL;
-__thread int gflag[9];/*one for each cert type*/
-__thread char *gpkgcert[9];/*To store pkg cert values*/
+__thread sqlite3 *cert_db = NULL;
 
 static int __open_manifest_db();
 static int __exec_pkginfo_query(char *query, void *data);
-static int __exec_appinfo_query(char *query, void *data);
 static int __exec_certinfo_query(char *query, void *data);
+static int __exec_certindexinfo_query(char *query, void *data);
 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
+static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
-static int __delete_certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
+static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
-static int __pkgmgr_appinfo_new_handle_id();
-static int __pkgmgr_pkginfo_new_handle_id();
 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
 static void __destroy_each_node(gpointer data, gpointer user_data);
 static void __get_filter_condition(gpointer data, char **condition);
+static void __get_metadata_filter_condition(gpointer data, char **condition);
 static gint __compare_func(gconstpointer data1, gconstpointer data2);
+static int __delete_certinfo(const char *pkgid);
 
 static gint __compare_func(gconstpointer data1, gconstpointer data2)
 {
@@ -237,10 +241,32 @@ static void __destroy_each_node(gpointer data, gpointer user_data)
                free(node->value);
                node->value = NULL;
        }
+       if (node->key) {
+               free(node->key);
+               node->key = NULL;
+       }
        free(node);
        node = NULL;
 }
 
+static void __get_metadata_filter_condition(gpointer data, char **condition)
+{
+       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
+       char key[MAX_QUERY_LEN] = {'\0'};
+       char value[MAX_QUERY_LEN] = {'\0'};
+       if (node->key) {
+               snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
+       }
+       if (node->value) {
+               snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
+               strcat(key, value);
+       } else {
+               strcat(key, ")");
+       }
+       *condition = strdup(key);
+       return;
+}
+
 static void __get_filter_condition(gpointer data, char **condition)
 {
        pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
@@ -289,6 +315,10 @@ static void __get_filter_condition(gpointer data, char **condition)
        case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
                snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
                break;
+       case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
+               snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
+               break;
+
        case E_PMINFO_APPINFO_PROP_APP_ID:
                snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
                break;
@@ -338,6 +368,12 @@ static void __get_filter_condition(gpointer data, char **condition)
        case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
                snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
                break;
+       case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
+               snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
+               break;
+       case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
+               snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
+               break;
        default:
                _LOGE("Invalid Property Type\n");
                *condition = NULL;
@@ -365,9 +401,9 @@ static char* __convert_system_locale_to_manifest_locale(char *syslocale)
 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
 {
        ret_if(data == NULL);
-       if (data->tmp_dup){
-               free((void *)data->tmp_dup);
-               data->tmp_dup = NULL;
+       if (data->locale){
+               free((void *)data->locale);
+               data->locale = NULL;
        }
 
        pkgmgr_parser_free_manifest_xml(data->manifest_info);
@@ -383,6 +419,10 @@ static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
                free((void *)data->package);
                data->package = NULL;
        }
+       if (data->locale){
+               free((void *)data->locale);
+               data->locale = NULL;
+       }
 
        manifest_x *mfx = calloc(1, sizeof(manifest_x));
        if (data->app_component == PMINFO_UI_APP)
@@ -455,7 +495,8 @@ static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
        serviceapplication_x *svcapp = NULL;
        for(i = 0; i < ncols; i++)
        {
-               if (strcmp(colname[i], "app_component") == 0) {
+               if ((strcmp(colname[i], "app_component") == 0) ||
+                       (strcmp(colname[i], "package_app_info.app_component") == 0)) {
                        if (coltxt[i]) {
                                if (strcmp(coltxt[i], "uiapp") == 0) {
                                        uiapp = calloc(1, sizeof(uiapplication_x));
@@ -466,7 +507,8 @@ static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                        LISTADD(info->manifest_info->uiapplication, uiapp);
                                        for(j = 0; j < ncols; j++)
                                        {
-                                               if (strcmp(colname[j], "app_id") == 0) {
+                                               if ((strcmp(colname[j], "app_id") == 0) ||
+                                                       (strcmp(colname[j], "package_app_info.app_id") == 0)) {
                                                        if (coltxt[j])
                                                                info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
                                                } else if (strcmp(colname[j], "package") == 0) {
@@ -484,7 +526,8 @@ static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                        LISTADD(info->manifest_info->serviceapplication, svcapp);
                                        for(j = 0; j < ncols; j++)
                                        {
-                                               if (strcmp(colname[j], "app_id") == 0) {
+                                               if ((strcmp(colname[j], "app_id") == 0) ||
+                                                       (strcmp(colname[j], "package_app_info.app_id") == 0)) {
                                                        if (coltxt[j])
                                                                info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
                                                } else if (strcmp(colname[j], "package") == 0) {
@@ -555,6 +598,11 @@ static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
                        else
                                info->manifest_info->uiapplication->hwacceleration = NULL;
+               } else if (strcmp(colname[i], "app_screenreader") == 0 ){
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->screenreader = NULL;
                } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
                        if (coltxt[i])
                                info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
@@ -585,6 +633,11 @@ static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
                        else
                                info->manifest_info->uiapplication->icon->text = NULL;
+               } else if (strcmp(colname[i], "app_enabled") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->enabled = NULL;
                } else if (strcmp(colname[i], "app_label") == 0 ) {
                        if (coltxt[i])
                                info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
@@ -609,6 +662,31 @@ static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->uiapplication->icon->lang = NULL;
                                info->manifest_info->uiapplication->label->lang = NULL;
                        }
+               } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->permission_type = NULL;
+               } else if (strcmp(colname[i], "component_type") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->component_type = NULL;
+               } else if (strcmp(colname[i], "app_preload") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->preload = NULL;
+               } else if (strcmp(colname[i], "app_submode") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->submode = NULL;
+               } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->submode_mainid = NULL;
                } else
                        continue;
        }
@@ -622,6 +700,7 @@ static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname
        serviceapplication_x *svcapp = NULL;
        icon_x *icon = NULL;
        label_x *label = NULL;
+
        svcapp = calloc(1, sizeof(serviceapplication_x));
        LISTADD(info->manifest_info->serviceapplication, svcapp);
        icon = calloc(1, sizeof(icon_x));
@@ -679,6 +758,11 @@ static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname
                                info->manifest_info->serviceapplication->icon->lang = NULL;
                                info->manifest_info->serviceapplication->label->lang = NULL;
                        }
+               } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->serviceapplication->permission_type = NULL;
                } else
                        continue;
        }
@@ -740,6 +824,11 @@ static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname
                                                                info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
                                                        else
                                                                info->manifest_info->uiapplication->hwacceleration = NULL;
+                                               } else if (strcmp(colname[i], "app_screenreader") == 0 ){
+                                                       if (coltxt[i])
+                                                               info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
+                                                       else
+                                                               info->manifest_info->uiapplication->screenreader = NULL;
                                                } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
                                                        if (coltxt[i])
                                                                info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
@@ -794,6 +883,11 @@ static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname
                                                                info->manifest_info->uiapplication->icon->lang = NULL;
                                                                info->manifest_info->uiapplication->label->lang = NULL;
                                                        }
+                                               } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                                                       if (coltxt[i])
+                                                               info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
+                                                       else
+                                                               info->manifest_info->uiapplication->permission_type = NULL;
                                                } else
                                                        continue;
                                        }
@@ -855,6 +949,11 @@ static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname
                                                                info->manifest_info->serviceapplication->icon->lang = NULL;
                                                                info->manifest_info->serviceapplication->label->lang = NULL;
                                                        }
+                                               } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                                                       if (coltxt[i])
+                                                               info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
+                                                       else
+                                                               info->manifest_info->serviceapplication->permission_type = NULL;
                                                } else
                                                        continue;
                                        }
@@ -876,6 +975,14 @@ static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
        return 0;
 }
 
+static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
+{
+       int *p = (int*)data;
+       if (coltxt[0])
+               *p = atoi(coltxt[0]);
+       return 0;
+}
+
 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
 {
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
@@ -884,6 +991,7 @@ static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
        icon_x *icon = NULL;
        label_x *label = NULL;
        description_x *description = NULL;
+       privilege_x *privilege = NULL;
 
        author = calloc(1, sizeof(author_x));
        LISTADD(info->manifest_info->author, author);
@@ -893,6 +1001,8 @@ static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
        LISTADD(info->manifest_info->label, label);
        description = calloc(1, sizeof(description_x));
        LISTADD(info->manifest_info->description, description);
+       privilege = calloc(1, sizeof(privilege_x));
+       LISTADD(info->manifest_info->privileges->privilege, privilege);
        for(i = 0; i < ncols; i++)
        {
                if (strcmp(colname[i], "package_version") == 0) {
@@ -975,6 +1085,11 @@ static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->installed_time = strdup(coltxt[i]);
                        else
                                info->manifest_info->installed_time = NULL;
+               } else if (strcmp(colname[i], "installed_storage") == 0 ){
+                       if (coltxt[i])
+                               info->manifest_info->installed_storage = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->installed_storage = NULL;
                } else if (strcmp(colname[i], "mainapp_id") == 0 ){
                        if (coltxt[i])
                                info->manifest_info->mainapp_id = strdup(coltxt[i]);
@@ -985,7 +1100,16 @@ static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->root_path = strdup(coltxt[i]);
                        else
                                info->manifest_info->root_path = NULL;
-
+               } else if (strcmp(colname[i], "csc_path") == 0 ){
+                       if (coltxt[i])
+                               info->manifest_info->csc_path = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->csc_path = NULL;
+               } else if (strcmp(colname[i], "privilege") == 0 ){
+                       if (coltxt[i])
+                               info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->privileges->privilege->text = NULL;
                } else if (strcmp(colname[i], "package_locale") == 0 ){
                        if (coltxt[i]) {
                                info->manifest_info->author->lang = strdup(coltxt[i]);
@@ -999,6 +1123,11 @@ static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->label->lang = NULL;
                                info->manifest_info->description->lang = NULL;
                        }
+               } else if (strcmp(colname[i], "package_url") == 0 ){
+                       if (coltxt[i])
+                               info->manifest_info->package_url = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->package_url = NULL;
                } else
                        continue;
        }
@@ -1016,286 +1145,26 @@ static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
                return -1;
 }
 
-static int __delete_certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
+static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
 {
-       const char *pkgid = (const char *)data;
+       pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
        int i = 0;
-       char *error_message = NULL;
-       int ret =0;
-       char query[MAX_QUERY_LEN] = {'\0'};
-       pkgmgr_instcertinfo_x *certinfo = NULL;
-       certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
-       if (certinfo == NULL) {
-               _LOGE("Out of Memory!!!\n");
-               return PMINFO_R_ERROR;
-       }
-       for (i  = 0; i < ncols; i++) {
-               if (strcmp(colname[i], "package") == 0) {
+       for(i = 0; i < ncols; i++) {
+               if (strcmp(colname[i], "cert_id") == 0) {
                        if (coltxt[i])
-                               certinfo->pkgid = coltxt[i];
-               } else if (strcmp(colname[i], "author_signer_cert") == 0) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_AUTHOR_SIGNER_CERT] && gpkgcert[PMINFO_AUTHOR_SIGNER_CERT]) {
-                                               certinfo->auth_signer_cert = strdup(gpkgcert[PMINFO_AUTHOR_SIGNER_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_AUTHOR_SIGNER_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_AUTHOR_SIGNER_CERT] = 1;
-                               } else {
-                                       certinfo->auth_signer_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "author_im_cert") == 0) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_AUTHOR_INTERMEDIATE_CERT] && gpkgcert[PMINFO_AUTHOR_INTERMEDIATE_CERT]) {
-                                               certinfo->auth_im_cert = strdup(gpkgcert[PMINFO_AUTHOR_INTERMEDIATE_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select author_im_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_AUTHOR_INTERMEDIATE_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 1;
-                               } else {
-                                       certinfo->auth_im_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "author_root_cert") == 0) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_AUTHOR_ROOT_CERT] && gpkgcert[PMINFO_AUTHOR_ROOT_CERT]) {
-                                               certinfo->auth_root_cert = strdup(gpkgcert[PMINFO_AUTHOR_ROOT_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select author_root_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_AUTHOR_ROOT_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_AUTHOR_ROOT_CERT] = 1;
-                               } else {
-                                       certinfo->auth_root_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "dist_signer_cert") == 0 ) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_DISTRIBUTOR_SIGNER_CERT] && gpkgcert[PMINFO_DISTRIBUTOR_SIGNER_CERT]) {
-                                               certinfo->dist_signer_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR_SIGNER_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select dist_signer_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_DISTRIBUTOR_SIGNER_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 1;
-                               } else {
-                                       certinfo->dist_signer_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "dist_im_cert") == 0 ) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] && gpkgcert[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT]) {
-                                               certinfo->dist_im_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select dist_im_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 1;
-                               } else {
-                                       certinfo->dist_im_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "dist_root_cert") == 0 ) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_DISTRIBUTOR_ROOT_CERT] && gpkgcert[PMINFO_DISTRIBUTOR_ROOT_CERT]) {
-                                               certinfo->dist_root_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR_ROOT_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select dist_root_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_DISTRIBUTOR_ROOT_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_DISTRIBUTOR_ROOT_CERT] = 1;
-                               } else {
-                                       certinfo->dist_root_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_DISTRIBUTOR2_SIGNER_CERT] && gpkgcert[PMINFO_DISTRIBUTOR2_SIGNER_CERT]) {
-                                               certinfo->dist2_signer_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR2_SIGNER_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select dist2_signer_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 1;
-                               } else {
-                                       certinfo->dist2_signer_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "dist2_im_cert") == 0 ) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] && gpkgcert[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT]) {
-                                               certinfo->dist2_im_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select dist2_im_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 1;
-                               } else {
-                                       certinfo->dist2_im_cert = strdup(coltxt[i]);
-                               }
-                       }
-                       continue;
-               } else if (strcmp(colname[i], "dist2_root_cert") == 0 ) {
-                       if (coltxt[i]) {
-                               if (strcmp(coltxt[i], pkgid) == 0) {
-                                       if (gflag[PMINFO_DISTRIBUTOR2_ROOT_CERT] && gpkgcert[PMINFO_DISTRIBUTOR2_ROOT_CERT]) {
-                                               certinfo->dist2_root_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR2_ROOT_CERT]);
-                                               continue;
-                                       }
-                                       snprintf(query, MAX_QUERY_LEN, "select dist2_root_cert from package_cert_info " \
-                                               "where package='%s'", pkgid);
-                                       if (SQLITE_OK !=
-                                           sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
-                                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                                      error_message);
-                                               sqlite3_free(error_message);
-                                               ret = PMINFO_R_ERROR;
-                                               goto err;
-                                       }
-                                       gpkgcert[PMINFO_DISTRIBUTOR2_ROOT_CERT] = strdup(certinfo->pkgid);
-                                       gflag[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 1;
-                               } else {
-                                       certinfo->dist2_root_cert = strdup(coltxt[i]);
-                               }
-                       }
+                               info->cert_id = atoi(coltxt[i]);
+                       else
+                               info->cert_id = 0;
+               } else if (strcmp(colname[i], "cert_ref_count") == 0) {
+                       if (coltxt[i])
+                               info->cert_ref_count = atoi(coltxt[i]);
+                       else
+                               info->cert_ref_count = 0;
+               } else
                        continue;
-               }
-       }
-       /*Update cert info db*/
-       pkgmgrinfo_save_certinfo(certinfo->pkgid, (void *)certinfo);
-       ret = PMINFO_R_OK;
-err:
-       if (certinfo->auth_signer_cert) {
-               free(certinfo->auth_signer_cert);
-               certinfo->auth_signer_cert = NULL;
-       }
-       if (certinfo->auth_im_cert) {
-               free(certinfo->auth_im_cert);
-               certinfo->auth_im_cert = NULL;
-       }
-       if (certinfo->auth_root_cert) {
-               free(certinfo->auth_root_cert);
-               certinfo->auth_root_cert = NULL;
-       }
-       if (certinfo->dist_signer_cert) {
-               free(certinfo->dist_signer_cert);
-               certinfo->dist_signer_cert = NULL;
-       }
-       if (certinfo->dist_im_cert) {
-               free(certinfo->dist_im_cert);
-               certinfo->dist_im_cert = NULL;
        }
-       if (certinfo->dist_root_cert) {
-               free(certinfo->dist_root_cert);
-               certinfo->dist_root_cert = NULL;
-       }
-       if (certinfo->dist2_signer_cert) {
-               free(certinfo->dist2_signer_cert);
-               certinfo->dist2_signer_cert = NULL;
-       }
-       if (certinfo->dist2_im_cert) {
-               free(certinfo->dist2_im_cert);
-               certinfo->dist2_im_cert = NULL;
-       }
-       if (certinfo->dist2_root_cert) {
-               free(certinfo->dist2_root_cert);
-               certinfo->dist2_root_cert = NULL;
-       }
-       free(certinfo);
-       certinfo = NULL;
-       return ret;
+       return 0;
 }
-
 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
 {
        pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
@@ -1309,52 +1178,194 @@ static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->pkgid = NULL;
                } else if (strcmp(colname[i], "author_signer_cert") == 0) {
                        if (coltxt[i])
-                               info->auth_signer_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
                        else
-                               info->auth_signer_cert = NULL;
+                               (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
                } else if (strcmp(colname[i], "author_im_cert") == 0) {
                        if (coltxt[i])
-                               info->auth_im_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
                        else
-                               info->auth_im_cert = NULL;
+                               (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
                } else if (strcmp(colname[i], "author_root_cert") == 0) {
                        if (coltxt[i])
-                               info->auth_root_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
                        else
-                               info->auth_root_cert = NULL;
+                               (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
                } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
                        if (coltxt[i])
-                               info->dist_signer_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
                        else
-                               info->dist_signer_cert = NULL;
+                               (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
                } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
                        if (coltxt[i])
-                               info->dist_im_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
                        else
-                               info->dist_im_cert = NULL;
+                               (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
                } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
                        if (coltxt[i])
-                               info->dist_root_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
                        else
-                               info->dist_root_cert = NULL;
+                               (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
                } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
                        if (coltxt[i])
-                               info->dist2_signer_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
                        else
-                               info->dist2_signer_cert = NULL;
+                               (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
                } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
                        if (coltxt[i])
-                               info->dist2_im_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
                        else
-                               info->dist2_im_cert = NULL;
+                               (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
                } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
                        if (coltxt[i])
-                               info->dist2_root_cert = strdup(coltxt[i]);
+                               (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
+                       else
+                               (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
+               } else if (strcmp(colname[i], "cert_info") == 0 ){
+                       if (coltxt[i])
+                               info->cert_value = strdup(coltxt[i]);
+                       else
+                               info->cert_value = NULL;
+               } else
+                       continue;
+       }
+       return 0;
+}
+
+static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
+       int i = 0;
+       uiapplication_x *uiapp = NULL;
+       uiapp = calloc(1, sizeof(uiapplication_x));
+       if (uiapp == NULL) {
+               _LOGE("Out of Memory!!!\n");
+               return -1;
+       }
+
+       LISTADD(info->uiapp_info, uiapp);
+
+       for(i = 0; i < ncols; i++)
+       {
+               if (strcmp(colname[i], "app_id") == 0) {
+                       /*appid being foreign key, is column in every table
+                       Hence appid gets strduped every time leading to memory leak.
+                       If appid is already set, just continue.*/
+                       if (info->uiapp_info->appid)
+                               continue;
+                       if (coltxt[i])
+                               info->uiapp_info->appid = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->appid = NULL;
+               } else if (strcmp(colname[i], "app_exec") == 0) {
+                       if (coltxt[i])
+                               info->uiapp_info->exec = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->exec = NULL;
+               } else if (strcmp(colname[i], "app_nodisplay") == 0) {
+                       if (coltxt[i])
+                               info->uiapp_info->nodisplay = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->nodisplay = NULL;
+               } else if (strcmp(colname[i], "app_type") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->type = strdup(coltxt[i]);
                        else
-                               info->dist2_root_cert = NULL;
+                               info->uiapp_info->type = NULL;
+               } else if (strcmp(colname[i], "app_multiple") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->multiple = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->multiple = NULL;
+               } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->taskmanage = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->taskmanage = NULL;
+               } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->hwacceleration = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->hwacceleration = NULL;
+               } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->screenreader = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->screenreader = NULL;
+               } else if (strcmp(colname[i], "app_enabled") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->enabled= strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->enabled = NULL;
+               } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
+                       if (coltxt[i])
+                               info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->indicatordisplay = NULL;
+               } else if (strcmp(colname[i], "app_portraitimg") == 0){
+                       if (coltxt[i])
+                               info->uiapp_info->portraitimg = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->portraitimg = NULL;
+               } else if (strcmp(colname[i], "app_landscapeimg") == 0){
+                       if (coltxt[i])
+                               info->uiapp_info->landscapeimg = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->landscapeimg = NULL;
+               } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
+                       if (coltxt[i])
+                               info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->guestmode_visibility = NULL;
+               } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->recentimage = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->recentimage = NULL;
+               } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->mainapp = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->mainapp = NULL;
+               } else if (strcmp(colname[i], "package") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->package = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->package = NULL;
+               } else if (strcmp(colname[i], "app_component") == 0) {
+                       if (coltxt[i])
+                               info->uiapp_info->app_component = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->app_component = NULL;
+               } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->permission_type = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->permission_type = NULL;
+               } else if (strcmp(colname[i], "component_type") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->component_type = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->component_type = NULL;
+               } else if (strcmp(colname[i], "app_preload") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->preload = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->preload = NULL;
+               } else if (strcmp(colname[i], "app_submode") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->submode = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->submode = NULL;
+               } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
+                       if (coltxt[i])
+                               info->uiapp_info->submode_mainid = strdup(coltxt[i]);
+                       else
+                               info->uiapp_info->submode_mainid = NULL;
                } else
                        continue;
        }
+
        return 0;
 }
 
@@ -1387,6 +1398,11 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                for(i = 0; i < ncols; i++)
                {
                        if (strcmp(colname[i], "app_id") == 0) {
+                               /*appid being foreign key, is column in every table
+                               Hence appid gets strduped every time leading to memory leak.
+                               If appid is already set, just continue.*/
+                               if (info->uiapp_info->appid)
+                                       continue;
                                if (coltxt[i])
                                        info->uiapp_info->appid = strdup(coltxt[i]);
                                else
@@ -1436,6 +1452,11 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                        info->uiapp_info->hwacceleration = strdup(coltxt[i]);
                                else
                                        info->uiapp_info->hwacceleration = NULL;
+                       } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->screenreader = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->screenreader = NULL;
                        } else if (strcmp(colname[i], "app_enabled") == 0 ) {
                                if (coltxt[i])
                                        info->uiapp_info->enabled= strdup(coltxt[i]);
@@ -1466,11 +1487,11 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                        info->uiapp_info->category->name = strdup(coltxt[i]);
                                else
                                        info->uiapp_info->category->name = NULL;
-                       } else if (strcmp(colname[i], "md_name") == 0 ) {
+                       } else if (strcmp(colname[i], "md_key") == 0 ) {
                                if (coltxt[i])
-                                       info->uiapp_info->metadata->name = strdup(coltxt[i]);
+                                       info->uiapp_info->metadata->key = strdup(coltxt[i]);
                                else
-                                       info->uiapp_info->metadata->name = NULL;
+                                       info->uiapp_info->metadata->key = NULL;
                        } else if (strcmp(colname[i], "md_value") == 0 ) {
                                if (coltxt[i])
                                        info->uiapp_info->metadata->value = strdup(coltxt[i]);
@@ -1515,6 +1536,31 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                                info->uiapp_info->image->section= strdup(coltxt[i]);
                                        else
                                                info->uiapp_info->image->section = NULL;
+                       } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->permission_type = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->permission_type = NULL;
+                       } else if (strcmp(colname[i], "component_type") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->component_type = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->component_type = NULL;
+                       } else if (strcmp(colname[i], "app_preload") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->preload = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->preload = NULL;
+                       } else if (strcmp(colname[i], "app_submode") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->submode = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->submode = NULL;
+                       } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->submode_mainid = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->submode_mainid = NULL;
                        } else
                                continue;
                }
@@ -1528,9 +1574,16 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                LISTADD(info->svcapp_info->category, category);
                metadata = calloc(1, sizeof(metadata_x));
                LISTADD(info->svcapp_info->metadata, metadata);
+               permission = calloc(1, sizeof(permission_x));
+               LISTADD(info->svcapp_info->permission, permission);
                for(i = 0; i < ncols; i++)
                {
                        if (strcmp(colname[i], "app_id") == 0) {
+                               /*appid being foreign key, is column in every table
+                               Hence appid gets strduped every time leading to memory leak.
+                               If appid is already set, just continue.*/
+                               if (info->svcapp_info->appid)
+                                       continue;
                                if (coltxt[i])
                                        info->svcapp_info->appid = strdup(coltxt[i]);
                                else
@@ -1575,11 +1628,11 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                        info->svcapp_info->category->name = strdup(coltxt[i]);
                                else
                                        info->svcapp_info->category->name = NULL;
-                       } else if (strcmp(colname[i], "md_name") == 0 ) {
+                       } else if (strcmp(colname[i], "md_key") == 0 ) {
                                if (coltxt[i])
-                                       info->svcapp_info->metadata->name = strdup(coltxt[i]);
+                                       info->svcapp_info->metadata->key = strdup(coltxt[i]);
                                else
-                                       info->svcapp_info->metadata->name = NULL;
+                                       info->svcapp_info->metadata->key = NULL;
                        } else if (strcmp(colname[i], "md_value") == 0 ) {
                                if (coltxt[i])
                                        info->svcapp_info->metadata->value = strdup(coltxt[i]);
@@ -1604,6 +1657,11 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                        info->svcapp_info->icon->lang = NULL;
                                        info->svcapp_info->label->lang = NULL;
                                }
+                       } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
+                               if (coltxt[i])
+                                       info->svcapp_info->permission_type = strdup(coltxt[i]);
+                               else
+                                       info->svcapp_info->permission_type = NULL;
                        } else
                                continue;
                }
@@ -1654,52 +1712,18 @@ static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname
        return 0;
 }
 
-static int __icon_name_cb(void *data, int ncols, char **coltxt, char **colname)
+static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
 {
-       pkgmgr_iconpath_x *icon_name = (pkgmgr_iconpath_x *)data;
+       pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
        int i = 0;
+
        for(i = 0; i < ncols; i++)
        {
-               if (strcmp(colname[i], "app_icon") == 0) {
+               if (strcmp(colname[i], "author_signer_cert") == 0) {
                        if (coltxt[i])
-                               icon_name->iconpath = strdup(coltxt[i]);
+                               info->cert_id = atoi(coltxt[i]);
                        else
-                               icon_name->iconpath = NULL;
-               } else
-                       continue;
-       }
-       return 0;
-}
-
-static int __image_path_cb(void *data, int ncols, char **coltxt, char **colname)
-{
-       pkgmgr_image_x *image_path = (pkgmgr_image_x *)data;
-       int i = 0;
-       for(i = 0; i < ncols; i++)
-       {
-               if (strcmp(colname[i], "app_image") == 0) {
-                       if (coltxt[i])
-                               image_path->imagepath = strdup(coltxt[i]);
-                       else
-                               image_path->imagepath = NULL;
-               } else
-                       continue;
-       }
-       return 0;
-}
-
-static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
-{
-       pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
-       int i = 0;
-
-       for(i = 0; i < ncols; i++)
-       {
-               if (strcmp(colname[i], "author_signer_cert") == 0) {
-                       if (coltxt[i])
-                               info->certvalue= strdup(coltxt[i]);
-                       else
-                               info->certvalue = NULL;
+                               info->cert_id = 0;
                } else if (strcmp(colname[i], "package") == 0) {
                        if (coltxt[i])
                                info->pkgid= strdup(coltxt[i]);
@@ -1752,26 +1776,11 @@ static int __exec_certinfo_query(char *query, void *data)
        return 0;
 }
 
-static int __exec_appcomponent_query(char *query, void *data)
-{
-       char *error_message = NULL;
-       if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __appcomponent_cb, data, &error_message)) {
-               _LOGE("Don't execute query = %s error message = %s\n", query,
-                      error_message);
-               sqlite3_free(error_message);
-               return -1;
-       }
-       sqlite3_free(error_message);
-       return 0;
-}
-
-
-static int __exec_appinfo_query(char *query, void *data)
+static int __exec_certindexinfo_query(char *query, void *data)
 {
        char *error_message = NULL;
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __appinfo_cb, data, &error_message)) {
+           sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
@@ -1827,98 +1836,6 @@ static int __child_element(xmlTextReaderPtr reader, int depth)
        return ret;
 }
 
-static char *__get_package_from_icon(char *icon)
-{
-       char *package;
-       char *extension;
-
-       retv_if(!icon, NULL);
-
-       package = strdup(icon);
-       retv_if(!package, NULL);
-       extension = rindex(package, '.');
-       if (extension) {
-               *extension = '\0';
-       } else {
-               _LOGE("cannot extract from icon [%s] to package.", icon);
-       }
-
-       return package;
-}
-
-static char *__get_icon_with_path(char *icon)
-{
-       retv_if(!icon, NULL);
-
-       if (index(icon, '/') == NULL) {
-               char *package;
-               char *theme = NULL;
-               char *icon_with_path = NULL;
-               int len;
-
-               package = __get_package_from_icon(icon);
-               retv_if(!package, NULL);
-
-               theme = vconf_get_str("db/setting/theme");
-               if (!theme) {
-                       theme = strdup("default");
-                       if(!theme) {
-                               free(package);
-                               return NULL;
-                       }
-               }
-
-               len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
-               icon_with_path = malloc(len);
-               if(icon_with_path == NULL) {
-                       _LOGE("(icon_with_path == NULL) return\n");
-                       free(package);
-                       free(theme);
-                       return NULL;
-               }
-
-               memset(icon_with_path, 0, len);
-
-               sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
-               do {
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       _LOGE("cannot find icon %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-
-                       #if 1 /* this will be remove when finish the work for moving icon path */
-                       _LOGE("icon file must be moved to %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path,  "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       _LOGE("cannot find icon %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       #endif
-               } while (0);
-
-               free(theme);
-               free(package);
-
-               _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
-
-               return icon_with_path;
-       } else {
-               char* confirmed_icon = NULL;
-
-               confirmed_icon = strdup(icon);
-               retv_if(!confirmed_icon, NULL);
-               return confirmed_icon;
-       }
-}
-
 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
 {
        int *p = (int*)data;
@@ -1929,30 +1846,33 @@ static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt,
 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
 {
        int result_query = -1;
+       int ret = 0;
        char query[MAX_QUERY_LEN];
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select app_locale from package_app_localized_info where app_id='%s' and app_locale='%s')", appid, locale);
-       __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
-
+       ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
+       retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
        return result_query;
 }
 
 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
 {
        int result_query = -1;
+       int ret = 0;
        char wildcard[2] = {'%','\0'};
        char query[MAX_QUERY_LEN];
        char lang[3] = {'\0'};
        strncpy(lang, locale, LANGUAGE_LENGTH);
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select app_locale from package_app_localized_info where app_id='%s' and app_locale like '%s%s')", appid, lang, wildcard);
-       __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
-
+       ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
+       retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
        return result_query;
 }
 
 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
 {
+       int ret = 0;
        char wildcard[2] = {'%','\0'};
        char lang[3] = {'\0'};
        char query[MAX_QUERY_LEN];
@@ -1964,15 +1884,21 @@ static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, c
                _LOGE("Out of Memory!!!\n");
                return NULL;
        }
-       memset(info, NULL, sizeof(*info));
+       memset(info, '\0', sizeof(*info));
 
        strncpy(lang, locale, 2);
        snprintf(query, MAX_QUERY_LEN, "select app_locale from package_app_localized_info where app_id='%s' and app_locale like '%s%s'", appid, lang, wildcard);
-       __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
+       ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
+       tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
        locale_new = info->locale;
        free(info);
-
        return locale_new;
+catch:
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+       return NULL;
 }
 
 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
@@ -1996,7 +1922,7 @@ static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const
        char *locale_new = NULL;
        int check_result = 0;
 
-       locale = __convert_syslocale_to_manifest_locale(syslocale);
+       locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
 
        /*check exact matching */
        check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
@@ -2011,7 +1937,6 @@ static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const
        check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
        if(check_result == 1) {
                   locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
-                  _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
                   free(locale);
                   if (locale_new == NULL)
                           locale_new =  strdup(DEFAULT_LOCALE);
@@ -2020,7 +1945,6 @@ static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const
 
        /* default locale */
        free(locale);
-       _LOGD("%s DEFAULT_LOCALE)\n", appid);
        return  strdup(DEFAULT_LOCALE);
 }
 
@@ -2079,12 +2003,107 @@ long long _pkgmgr_calculate_dir_size(char *dirname)
 
 }
 
-API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
+static int __delete_certinfo(const char *pkgid)
 {
-       if (pkg_list_cb == NULL) {
-               _LOGE("callback function is NULL\n");
-               return PMINFO_R_EINVAL;
+       int ret = -1;
+       int i = 0;
+       int j = 0;
+       int c = 0;
+       int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+       char *error_message = NULL;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       pkgmgr_certinfo_x *certinfo = NULL;
+       pkgmgr_certindexinfo_x *indexinfo = NULL;
+       certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
+       retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
+       indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
+       if (indexinfo == NULL) {
+               _LOGE("Out of Memory!!!");
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       /*populate certinfo from DB*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
+       ret = __exec_certinfo_query(query, (void *)certinfo);
+       if (ret == -1) {
+               _LOGE("Package Cert Info DB Information retrieval failed\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       /*Update cert index table*/
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((certinfo->cert_id)[i]) {
+                       for (j = 0; j < MAX_CERT_TYPE; j++) {
+                               if ((certinfo->cert_id)[i] == unique_id[j]) {
+                                       /*Ref count has already been updated. Just continue*/
+                                       break;
+                               }
+                       }
+                       if (j == MAX_CERT_TYPE)
+                               unique_id[c++] = (certinfo->cert_id)[i];
+                       else
+                               continue;
+                       memset(query, '\0', MAX_QUERY_LEN);
+                       snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
+                       ret = __exec_certindexinfo_query(query, (void *)indexinfo);
+                       if (ret == -1) {
+                               _LOGE("Cert Info DB Information retrieval failed\n");
+                               ret = PMINFO_R_ERROR;
+                               goto err;
+                       }
+                       memset(query, '\0', MAX_QUERY_LEN);
+                       if (indexinfo->cert_ref_count > 1) {
+                               /*decrease ref count*/
+                               snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
+                               indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
+                       } else {
+                               /*delete this certificate as ref count is 1 and it will become 0*/
+                               snprintf(query, MAX_QUERY_LEN, "delete from  package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
+                       }
+                       if (SQLITE_OK !=
+                           sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
+                               _LOGE("Don't execute query = %s error message = %s\n", query,
+                                      error_message);
+                               sqlite3_free(error_message);
+                               ret = PMINFO_R_ERROR;
+                               goto err;
+                       }
+               }
+       }
+       /*Now delete the entry from db*/
+       snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
+        if (SQLITE_OK !=
+            sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
+                _LOGE("Don't execute query = %s error message = %s\n", query,
+                       error_message);
+               sqlite3_free(error_message);
+               ret = PMINFO_R_ERROR;
+               goto err;
+        }
+       ret = PMINFO_R_OK;
+err:
+       if (indexinfo) {
+               free(indexinfo);
+               indexinfo = NULL;
+       }
+       if (certinfo->pkgid) {
+               free(certinfo->pkgid);
+               certinfo->pkgid = NULL;
+       }
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((certinfo->cert_info)[i]) {
+                       free((certinfo->cert_info)[i]);
+                       (certinfo->cert_info)[i] = NULL;
+               }
        }
+       free(certinfo);
+       certinfo = NULL;
+       return ret;
+}
+
+API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
+{
+       retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
        char *error_message = NULL;
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
@@ -2095,6 +2114,7 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
        icon_x *tmp2 = NULL;
        description_x *tmp3 = NULL;
        author_x *tmp4 = NULL;
+       privilege_x *tmp5 = NULL;
 
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
        if (syslocale == NULL) {
@@ -2108,14 +2128,14 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
                ret = PMINFO_R_EINVAL;
                goto err;
        }
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
+
        ret = __open_manifest_db();
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
                ret = PMINFO_R_ERROR;
                goto err;
        }
-       pkgmgr_pkginfo_x *tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
+       pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
        pkgmgr_pkginfo_x *node = NULL;
        pkgmgr_pkginfo_x *temp_node = NULL;
 
@@ -2134,7 +2154,13 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
 
        for(node = node->next; node ; node = node->next) {
                pkginfo = node;
-
+               pkginfo->locale = strdup(locale);
+               pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
+               if (pkginfo->manifest_info->privileges == NULL) {
+                       _LOGE("Failed to allocate memory for privileges info\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
                /*populate manifest_info from DB*/
                snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
                ret = __exec_pkginfo_query(query, (void *)pkginfo);
@@ -2144,6 +2170,15 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
                        goto err;
                }
                memset(query, '\0', MAX_QUERY_LEN);
+               /*populate privilege_info from DB*/
+               snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
+               ret = __exec_pkginfo_query(query, (void *)pkginfo);
+               if (ret == -1) {
+                       _LOGE("Package Privilege Info DB Information retrieval failed\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               memset(query, '\0', MAX_QUERY_LEN);
                snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
                        " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
                ret = __exec_pkginfo_query(query, (void *)pkginfo);
@@ -2178,6 +2213,10 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
                        LISTHEAD(pkginfo->manifest_info->author, tmp4);
                        pkginfo->manifest_info->author = tmp4;
                }
+               if (pkginfo->manifest_info->privileges->privilege) {
+                       LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
+                       pkginfo->manifest_info->privileges->privilege = tmp5;
+               }
        }
 
        LISTHEAD(tmphead, node);
@@ -2216,16 +2255,9 @@ err:
 
 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
 {
-       if (pkgid == NULL) {
-               _LOGE("package name is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (handle == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *pkginfo = NULL;
-       char *error_message = NULL;
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *syslocale = NULL;
@@ -2235,82 +2267,63 @@ API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *
        icon_x *tmp2 = NULL;
        description_x *tmp3 = NULL;
        author_x *tmp4 = NULL;
+       privilege_x *tmp5 = NULL;
+       sqlite3 *pkginfo_db = NULL;
 
        /*validate pkgid*/
-       ret = __open_manifest_db();
-       if (ret == -1) {
-               _LOGE("Fail to open manifest DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+
+       /*check pkgid exist on db*/
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
-       if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
-               _LOGE("Don't execute query = %s error message = %s\n", query,
-                      error_message);
-               sqlite3_free(error_message);
-               sqlite3_close(manifest_db);
-               return PMINFO_R_ERROR;
-       }
-       if (exist == 0) {
-               _LOGE("Package not found in DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
+       tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
 
+       /*get system locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
-       if (syslocale == NULL) {
-               _LOGE("current locale is NULL\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
+
+       /*get locale on db*/
        locale = __convert_system_locale_to_manifest_locale(syslocale);
-       if (locale == NULL) {
-               _LOGE("manifest locale is NULL\n");
-               ret = PMINFO_R_EINVAL;
-               goto err;
-       }
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX  - 1);
+       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
+
        pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
-       if (pkginfo == NULL) {
-               _LOGE("Failed to allocate memory for pkginfo\n");
-               return PMINFO_R_ERROR;
-       }
+       tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
+
+       pkginfo->locale = strdup(locale);
 
        pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
-       if (pkginfo->manifest_info == NULL) {
-               _LOGE("Failed to allocate memory for manifest info\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
+
        pkginfo->manifest_info->package = strdup(pkgid);
+       pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
+       tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
+
        /*populate manifest_info from DB*/
        snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
-       ret = __exec_pkginfo_query(query, (void *)pkginfo);
-       if (ret == -1) {
-               _LOGE("Package Info DB Information retrieval failed\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       /*populate privilege_info from DB*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
+
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
                " package='%s' and package_locale='%s'", pkgid, locale);
-       ret = __exec_pkginfo_query(query, (void *)pkginfo);
-       if (ret == -1) {
-               _LOGE("Package Info DB Information retrieval failed\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
        /*Also store the values corresponding to default locales*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
                " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
-       ret = __exec_pkginfo_query(query, (void *)pkginfo);
-       if (ret == -1) {
-               _LOGE("Package Info DB Information retrieval failed\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
-       }
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
        if (pkginfo->manifest_info->label) {
                LISTHEAD(pkginfo->manifest_info->label, tmp1);
                pkginfo->manifest_info->label = tmp1;
@@ -2327,22 +2340,20 @@ API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *
                LISTHEAD(pkginfo->manifest_info->author, tmp4);
                pkginfo->manifest_info->author = tmp4;
        }
-       *handle = (void *)pkginfo;
-       sqlite3_close(manifest_db);
-       if (syslocale) {
-               free(syslocale);
-               syslocale = NULL;
+       if (pkginfo->manifest_info->privileges->privilege) {
+               LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
+               pkginfo->manifest_info->privileges->privilege = tmp5;
        }
-       if (locale) {
-               free(locale);
-               locale = NULL;
+
+catch:
+       if (ret == PMINFO_R_OK)
+               *handle = (void*)pkginfo;
+       else {
+               *handle = NULL;
+               __cleanup_pkginfo(pkginfo);
        }
-       return PMINFO_R_OK;
+       sqlite3_close(pkginfo_db);
 
-err:
-       *handle = NULL;
-       __cleanup_pkginfo(pkginfo);
-       sqlite3_close(manifest_db);
        if (syslocale) {
                free(syslocale);
                syslocale = NULL;
@@ -2357,17 +2368,11 @@ err:
 
 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (pkg_name == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        if (info->manifest_info->package)
-               *pkg_name = info->manifest_info->package;
+               *pkg_name = (char *)info->manifest_info->package;
        else
                return PMINFO_R_ERROR;
 
@@ -2376,17 +2381,11 @@ API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_n
 
 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (pkgid == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        if (info->manifest_info->package)
-               *pkgid = info->manifest_info->package;
+               *pkgid = (char *)info->manifest_info->package;
        else
                return PMINFO_R_ERROR;
 
@@ -2395,17 +2394,11 @@ API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
 
 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (type == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        if (info->manifest_info->type)
-               *type = info->manifest_info->type;
+               *type = (char *)info->manifest_info->type;
        else
                *type = pkgtype;
        return PMINFO_R_OK;
@@ -2413,14 +2406,8 @@ API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
 
 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (version == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        *version = (char *)info->manifest_info->version;
        return PMINFO_R_OK;
@@ -2428,14 +2415,8 @@ API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **versi
 
 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (location == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *val = NULL;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        val = (char *)info->manifest_info->installlocation;
@@ -2452,44 +2433,27 @@ API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkg
 
 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (size == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *val = NULL;
        char *location = NULL;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        location = (char *)info->manifest_info->installlocation;
-       if (strcmp(location, "prefer-external") == 0)
-       {
-               val = (char *)info->manifest_info->package_size;
-               if (val) {
-                       *size = atoi(val);
-               } else {
-                       *size = 0;
-                       _LOGE("package size is not specified\n");
-                       return PMINFO_R_ERROR;
-               }
+       val = (char *)info->manifest_info->package_size;
+       if (val) {
+               *size = atoi(val);
        } else {
                *size = 0;
+               _LOGE("package size is not specified\n");
+               return PMINFO_R_ERROR;
        }
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (size == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        char *pkgid = NULL;
        char device_path[PKG_STRING_LEN_MAX] = { '\0', };
@@ -2623,14 +2587,8 @@ API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size
 
 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (size == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        char *pkgid = NULL;
        char device_path[PKG_STRING_LEN_MAX] = { '\0', };
@@ -2656,58 +2614,33 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
        retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-
-       pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
-       pkgmgrinfo_appinfo_h apphandle;
-       bool ismainapp = 0;
        int ret = PMINFO_R_OK;
+       char *locale = NULL;
+       icon_x *ptr = NULL;
+       *icon = NULL;
 
-       ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
-       retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
-
-       ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
-       tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
-
-       if (ismainapp){
-               ret = pkgmgrinfo_appinfo_get_icon(apphandle, &info_tmp->tmp);
-               tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_icon fail");
-               tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "icon is NULL");
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
-               if (info_tmp->tmp_dup){
-                       free((void *)info_tmp->tmp_dup);
-                       info_tmp->tmp_dup = NULL;
-               }
+       locale = info->locale;
+       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-               info_tmp->tmp_dup= strdup(info_tmp->tmp);
-               *icon = info_tmp->tmp_dup;
-       } else {
-               char *locale = NULL;
-               icon_x *ptr = NULL;
-               *icon = NULL;
-               locale = glocale;
-               tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
-               pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
-               for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
-               {
-                       if (ptr->lang) {
-                               if (strcmp(ptr->lang, locale) == 0) {
-                                       *icon = (char *)ptr->text;
-                                       if (strcasecmp(*icon, "(null)") == 0) {
-                                               locale = DEFAULT_LOCALE;
-                                               continue;
-                                       } else
-                                               break;
-                               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                                       *icon = (char *)ptr->text;
+       for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
+       {
+               if (ptr->lang) {
+                       if (strcmp(ptr->lang, locale) == 0) {
+                               *icon = (char *)ptr->text;
+                               if (strcasecmp(*icon, "(null)") == 0) {
+                                       locale = DEFAULT_LOCALE;
+                                       continue;
+                               } else
                                        break;
-                               }
+                       } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
+                               *icon = (char *)ptr->text;
+                               break;
                        }
                }
-               
        }
 
-catch:
-       pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
        return ret;
 }
 
@@ -2715,76 +2648,47 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
        retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-
-       pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
-       pkgmgrinfo_appinfo_h apphandle;
-       bool ismainapp = 0;
        int ret = PMINFO_R_OK;
+       char *locale = NULL;
+       label_x *ptr = NULL;
+       *label = NULL;
 
-       ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
-       retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
-
-       ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
-       tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
-
-       if (ismainapp){
-               ret = pkgmgrinfo_appinfo_get_label(apphandle, &info_tmp->tmp);
-               tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_label fail");
-               tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "label is NULL");
-
-               if (info_tmp->tmp_dup){
-                       free((void *)info_tmp->tmp_dup);
-                       info_tmp->tmp_dup = NULL;
-               }
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       locale = info->locale;
+       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-               info_tmp->tmp_dup = strdup(info_tmp->tmp);
-               *label = info_tmp->tmp_dup;
-       } else {
-               char *locale = NULL;
-               label_x *ptr = NULL;
-               *label = NULL;
-               locale = glocale;
-               tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
-               pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
-               for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
-               {
-                       if (ptr->lang) {
-                               if (strcmp(ptr->lang, locale) == 0) {
-                                       *label = (char *)ptr->text;
-                                       if (strcasecmp(*label, "(null)") == 0) {
-                                               locale = DEFAULT_LOCALE;
-                                               continue;
-                                       } else
-                                               break;
-                               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                                       *label = (char *)ptr->text;
+       for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
+       {
+               if (ptr->lang) {
+                       if (strcmp(ptr->lang, locale) == 0) {
+                               *label = (char *)ptr->text;
+                               if (strcasecmp(*label, "(null)") == 0) {
+                                       locale = DEFAULT_LOCALE;
+                                       continue;
+                               } else
                                        break;
-                               }
+                       } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
+                               *label = (char *)ptr->text;
+                               break;
                        }
                }
        }
 
-catch:
-       pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
        return ret;
 }
 
 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (description == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *locale = NULL;
        description_x *ptr = NULL;
        *description = NULL;
-       locale = glocale;
-       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       locale = info->locale;
+       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
        for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
        {
                if (ptr->lang) {
@@ -2806,20 +2710,16 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d
 
 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (author_name == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *locale = NULL;
        author_x *ptr = NULL;
        *author_name = NULL;
-       locale = glocale;
-       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       locale = info->locale;
+       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
        for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
        {
                if (ptr->lang) {
@@ -2841,14 +2741,8 @@ API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **a
 
 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (author_email == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        *author_email = (char *)info->manifest_info->author->email;
        return PMINFO_R_OK;
@@ -2856,14 +2750,8 @@ API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **
 
 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (author_href == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        *author_href = (char *)info->manifest_info->author->href;
        return PMINFO_R_OK;
@@ -2871,68 +2759,25 @@ API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **a
 
 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
 {
-       char *pkgid;
-
-       pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
-       if (pkgid == NULL){
-                _LOGE("invalid func parameters\n");
-                return PMINFO_R_ERROR;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       FILE *fp = NULL;
-       char app_mmc_path[FILENAME_MAX] = { 0, };
-       char app_dir_path[FILENAME_MAX] = { 0, };
-       char app_mmc_internal_path[FILENAME_MAX] = { 0, };
-       snprintf(app_dir_path, FILENAME_MAX,
-       "%s%s", PKG_INSTALLATION_PATH, pkgid);
-       snprintf(app_mmc_path, FILENAME_MAX,
-       "%s%s", PKG_SD_PATH, pkgid);
-       snprintf(app_mmc_internal_path, FILENAME_MAX,
-       "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
-       /*check whether application is in external memory or not */
-       fp = fopen(app_mmc_path, "r");
-       if (fp == NULL) {
-               _LOGE(" app path in external memory not accesible\n");
-       } else {
-               fclose(fp);
-               fp = NULL;
-               *storage = PMINFO_EXTERNAL_STORAGE;
-               return PMINFO_R_OK;
-       }
+        if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
+               *storage = PMINFO_INTERNAL_STORAGE;
+        else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
+                *storage = PMINFO_EXTERNAL_STORAGE;
+        else
+                return PMINFO_R_ERROR;
 
-       /*check whether application is in internal or not */
-       fp = fopen(app_dir_path, "r");
-       if (fp == NULL) {
-               _LOGE(" app path in internal memory not accesible\n");
-               *storage = -1;
-               return PMINFO_R_ERROR;
-       } else {
-               fclose(fp);
-               /*check whether the application is installed in SD card
-                       but SD card is not present*/
-               fp = fopen(app_mmc_internal_path, "r");
-               if (fp == NULL) {
-                       *storage = PMINFO_INTERNAL_STORAGE;
-                       return PMINFO_R_OK;
-               } else {
-                       fclose(fp);
-                       *storage = PMINFO_EXTERNAL_STORAGE;
-                       return PMINFO_R_OK;
-               }
-       }
+       return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (installed_time == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        if (info->manifest_info->installed_time)
                *installed_time = atoi(info->manifest_info->installed_time);
@@ -2944,14 +2789,8 @@ API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *
 
 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (storeclientid == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        *storeclientid = (char *)info->manifest_info->storeclient_id;
        return PMINFO_R_OK;
@@ -2959,14 +2798,8 @@ API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char *
 
 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (mainappid == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        *mainappid = (char *)info->manifest_info->mainapp_id;
        return PMINFO_R_OK;
@@ -2974,14 +2807,8 @@ API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mai
 
 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (url == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        *url = (char *)info->manifest_info->package_url;
        return PMINFO_R_OK;
@@ -2989,19 +2816,11 @@ API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
 
 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
 {
-       char *val = NULL;
+       const char *val = NULL;
        const xmlChar *node;
        xmlTextReaderPtr reader;
-
-       if (manifest == NULL) {
-               _LOGE("input argument is NULL\n");
-               return PMINFO_R_ERROR;
-       }
-
-       if (size == NULL) {
-               _LOGE("output argument is NULL\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
+       retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        xmlInitParser();
        reader = xmlReaderForFile(manifest, NULL, 0);
@@ -3050,19 +2869,11 @@ API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
 
 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
 {
-       char *val = NULL;
+       const char *val = NULL;
        const xmlChar *node;
        xmlTextReaderPtr reader;
-
-       if (manifest == NULL) {
-               _LOGE("input argument is NULL\n");
-               return PMINFO_R_ERROR;
-       }
-
-       if (location == NULL) {
-               _LOGE("output argument is NULL\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
+       retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        xmlInitParser();
        reader = xmlReaderForFile(manifest, NULL, 0);
@@ -3111,58 +2922,55 @@ API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinf
 
 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (path == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        if (info->manifest_info->root_path)
-               *path = info->manifest_info->root_path;
+               *path = (char *)info->manifest_info->root_path;
        else
                return PMINFO_R_ERROR;
 
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       if (info->manifest_info->csc_path)
+               *path = (char *)info->manifest_info->csc_path;
+       else
+               *path = (char *)info->manifest_info->csc_path;
+
+       return PMINFO_R_OK;
+}
 
 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
 {
-       if (lhs_package_id == NULL || rhs_package_id == NULL)
-       {
-               _LOGE("pkginfo id is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (compare_result == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
+       retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
+       retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
 
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *error_message = NULL;
        pkgmgr_cert_x *info= NULL;
-       char *lcert = NULL;
-       char *rcert = NULL;
+       int lcert = 0;
+       int rcert = 0;
        int exist = -1;
-
+       *compare_result = PMINFO_CERT_COMPARE_ERROR;
        info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
-       if (info == NULL) {
-               _LOGE("Out of Memory!!!\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
 
        ret = db_util_open_with_options(CERT_DB, &cert_db,
                                        SQLITE_OPEN_READONLY, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("connect db [%s] failed!\n", CERT_DB);
-               free(info);
-               info = NULL;
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
@@ -3175,7 +2983,7 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
        }
 
        if (exist == 0) {
-               lcert = NULL;
+               lcert = 0;
        } else {
                snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
                if (SQLITE_OK !=
@@ -3185,30 +2993,7 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       lcert = info->certvalue;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
-                       free(info->certvalue);
-                       info->certvalue = NULL;
-                       if (SQLITE_OK !=
-                               sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                          error_message);
-                               ret = PMINFO_R_ERROR;
-                               goto err;
-                       }
-                       lcert = info->certvalue;
-               }
+               lcert = info->cert_id;
        }
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
@@ -3221,7 +3006,7 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
        }
 
        if (exist == 0) {
-               rcert = NULL;
+               rcert = 0;
        } else {
                snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
                if (SQLITE_OK !=
@@ -3231,42 +3016,19 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       rcert = info->certvalue;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
-                       free(info->certvalue);
-                       info->certvalue = NULL;
-                       if (SQLITE_OK !=
-                               sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                          error_message);
-                               ret = PMINFO_R_ERROR;
-                               goto err;
-                       }
-                       rcert = info->certvalue;
-               }
+               rcert = info->cert_id;
        }
 
-       if ((lcert == NULL) || (rcert == NULL))
+       if ((lcert == 0) || (rcert == 0))
        {
-               if ((lcert == NULL) && (rcert == NULL))
+               if ((lcert == 0) && (rcert == 0))
                        *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
-               else if (lcert == NULL)
+               else if (lcert == 0)
                        *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
-               else if (rcert == NULL)
+               else if (rcert == 0)
                        *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
        } else {
-               if (strcmp(lcert, rcert) == 0)
+               if (lcert == rcert)
                        *compare_result = PMINFO_CERT_COMPARE_MATCH;
                else
                        *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
@@ -3276,56 +3038,40 @@ err:
        sqlite3_free(error_message);
        sqlite3_close(cert_db);
        if (info) {
+               if (info->pkgid) {
+                       free(info->pkgid);
+                       info->pkgid = NULL;
+               }
                free(info);
                info = NULL;
        }
-
        return ret;
 }
 
 
 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
 {
-       if (lhs_app_id == NULL || rhs_app_id == NULL)
-       {
-               _LOGE("pkginfo id is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (compare_result == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
+       retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
+       retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
 
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *error_message = NULL;
        pkgmgr_cert_x *info= NULL;
-       char *lcert = NULL;
-       char *rcert = NULL;
-       int exist = -1;
+       int exist = -1;
+       char *lpkgid = NULL;
+       char *rpkgid = NULL;
 
        info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
-       if (info == NULL) {
-               _LOGE("Out of Memory!!!\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
 
        ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
                                        SQLITE_OPEN_READONLY, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
-               free(info);
-               info = NULL;
-               return PMINFO_R_ERROR;
-       }
-       ret = db_util_open_with_options(CERT_DB, &cert_db,
-                                       SQLITE_OPEN_READONLY, NULL);
-       if (ret != SQLITE_OK) {
-               _LOGE("connect db [%s] failed!\n", CERT_DB);
-               sqlite3_close(manifest_db);
-               free(info);
-               info = NULL;
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
@@ -3338,7 +3084,7 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        }
 
        if (exist == 0) {
-               lcert = NULL;
+               lpkgid = NULL;
        } else {
                snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
                if (SQLITE_OK !=
@@ -3348,39 +3094,14 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-
-               snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->pkgid);
-               if (SQLITE_OK !=
-                       sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                                  error_message);
+               lpkgid = strdup(info->pkgid);
+               if (lpkgid == NULL) {
+                       _LOGE("Out of Memory\n");
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       lcert = info->certvalue;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
-                       free(info->certvalue);
-                       info->certvalue = NULL;
-                       if (SQLITE_OK !=
-                               sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                          error_message);
-                               ret = PMINFO_R_ERROR;
-                               goto err;
-                       }
-                       lcert = info->certvalue;
-               }
+               free(info->pkgid);
+               info->pkgid = NULL;
        }
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
@@ -3393,7 +3114,7 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        }
 
        if (exist == 0) {
-               rcert = NULL;
+               rpkgid = NULL;
        } else {
                snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
                if (SQLITE_OK !=
@@ -3403,72 +3124,45 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-
-               snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->pkgid);
-               if (SQLITE_OK !=
-                       sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                                  error_message);
+               rpkgid = strdup(info->pkgid);
+               if (rpkgid == NULL) {
+                       _LOGE("Out of Memory\n");
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       rcert = info->certvalue;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
-                       free(info->certvalue);
-                       info->certvalue = NULL;
-                       if (SQLITE_OK !=
-                               sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                               _LOGE("Don't execute query = %s error message = %s\n", query,
-                                          error_message);
-                               ret = PMINFO_R_ERROR;
-                               goto err;
-                       }
-                       rcert = info->certvalue;
-               }
-       }
-
-       if ((lcert == NULL) || (rcert == NULL))
-       {
-               if ((lcert == NULL) && (rcert == NULL))
-                       *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
-               else if (lcert == NULL)
-                       *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
-               else if (rcert == NULL)
-                       *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
-       } else {
-               if (strcmp(lcert, rcert) == 0)
-                       *compare_result = PMINFO_CERT_COMPARE_MATCH;
-               else
-                       *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
+               free(info->pkgid);
+               info->pkgid = NULL;
        }
-
-err:
+       ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
+ err:
        sqlite3_free(error_message);
        sqlite3_close(manifest_db);
-       sqlite3_close(cert_db);
        if (info) {
+               if (info->pkgid) {
+                       free(info->pkgid);
+                       info->pkgid = NULL;
+               }
                free(info);
                info = NULL;
        }
-
+       if (lpkgid) {
+               free(lpkgid);
+               lpkgid = NULL;
+       }
+       if (rpkgid) {
+               free(rpkgid);
+               rpkgid = NULL;
+       }
        return ret;
 }
 
 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
 {
-       char *pkgid;
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
+#if 0 //smack issue occured, check later
+       char *pkgid = NULL;
        pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
        if (pkgid == NULL){
                 _LOGD("invalid func parameters\n");
@@ -3520,19 +3214,16 @@ API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *acce
        }
 
        _LOGD("pkgmgr_get_pkg_external_validation() end\n");
+#endif
+
+       *accessible = 1;
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (removable == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *val = NULL;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        val = (char *)info->manifest_info->removable;
@@ -3547,16 +3238,31 @@ API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *remov
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
+API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (preload == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       char *val = NULL;
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       val = (char *)info->manifest_info->installlocation;
+       if (val) {
+               if (strcmp(val, "internal-only") == 0)
+                       *movable = 0;
+               else if (strcmp(val, "prefer-external") == 0)
+                       *movable = 1;
+               else
+                       *movable = 1;
        }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *val = NULL;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        val = (char *)info->manifest_info->preload;
@@ -3571,16 +3277,29 @@ API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       char *preload = NULL;
+       char *removable = NULL;
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       preload = (char *)info->manifest_info->preload;
+       removable = (char *)info->manifest_info->removable;
+
+       if ((strcasecmp(preload, "true") == 0) && (strcasecmp(removable, "false") == 0))
+               *system = 1;
+       else
+               *system = 0;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (readonly == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *val = NULL;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        val = (char *)info->manifest_info->readonly;
@@ -3616,10 +3335,7 @@ API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
 
 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
 {
-       if (handle == NULL) {
-               _LOGE("pkginfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
        __cleanup_pkginfo(info);
        return PMINFO_R_OK;
@@ -3627,10 +3343,7 @@ API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
 
 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
 {
-       if (handle == NULL) {
-               _LOGE("Filter handle output parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
        *handle = NULL;
        pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
        if (filter == NULL) {
@@ -3643,10 +3356,7 @@ API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
 
 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
 {
-       if (handle == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
        if (filter->list){
                g_slist_foreach(filter->list, __destroy_each_node, NULL);
@@ -3660,10 +3370,8 @@ API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
                                const char *property, const int value)
 {
-       if (handle == NULL || property == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
        char *val = NULL;
        GSList *link = NULL;
@@ -3703,10 +3411,8 @@ API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
                                const char *property, const bool value)
 {
-       if (handle == NULL || property == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *val = NULL;
        GSList *link = NULL;
        int prop = -1;
@@ -3747,10 +3453,9 @@ API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
                                const char *property, const char *value)
 {
-       if (handle == NULL || property == NULL || value == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *val = NULL;
        GSList *link = NULL;
        int prop = -1;
@@ -3798,10 +3503,8 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
 
 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
 {
-       if (handle == NULL || count == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *syslocale = NULL;
        char *locale = NULL;
        char *condition = NULL;
@@ -3824,7 +3527,7 @@ API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int
                free(syslocale);
                return PMINFO_R_ERROR;
        }
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
+
        ret = __open_manifest_db();
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
@@ -3884,10 +3587,8 @@ err:
 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
                                pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
 {
-       if (handle == NULL || pkg_cb == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *syslocale = NULL;
        char *locale = NULL;
        char *condition = NULL;
@@ -3900,6 +3601,7 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
        icon_x *tmp2 = NULL;
        description_x *tmp3 = NULL;
        author_x *tmp4 = NULL;
+       privilege_x *tmp5 = NULL;
        pkgmgr_pkginfo_x *node = NULL;
        pkgmgr_pkginfo_x *tmphead = NULL;
        pkgmgr_pkginfo_x *pkginfo = NULL;
@@ -3917,7 +3619,7 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
                free(syslocale);
                return PMINFO_R_ERROR;
        }
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX  - 1);
+
        ret = __open_manifest_db();
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
@@ -3967,6 +3669,13 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
        LISTHEAD(tmphead, node);
        for(node = node->next ; node ; node = node->next) {
                pkginfo = node;
+               pkginfo->locale = strdup(locale);
+               pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
+               if (pkginfo->manifest_info->privileges == NULL) {
+                       _LOGE("Failed to allocate memory for privileges info\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
 
                /*populate manifest_info from DB*/
                snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
@@ -4011,6 +3720,10 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
                        LISTHEAD(pkginfo->manifest_info->author, tmp4);
                        pkginfo->manifest_info->author = tmp4;
                }
+               if (pkginfo->manifest_info->privileges->privilege) {
+                       LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
+                       pkginfo->manifest_info->privileges->privilege = tmp5;
+               }
        }
 
        LISTHEAD(tmphead, node);
@@ -4037,6 +3750,25 @@ err:
        return ret;
 }
 
+API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
+                       pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+       retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret = -1;
+       privilege_x *ptr = NULL;
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       ptr = info->manifest_info->privileges->privilege;
+       for (; ptr; ptr = ptr->next) {
+               if (ptr->text){
+                       ret = privilege_func(ptr->text, user_data);
+                       if (ret < 0)
+                               break;
+               }
+       }
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
                                                pkgmgrinfo_app_list_cb app_func, void *user_data)
 {
@@ -4053,6 +3785,10 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
        pkgmgr_appinfo_x *appinfo = NULL;
        icon_x *ptr1 = NULL;
        label_x *ptr2 = NULL;
+       category_x *ptr3 = NULL;
+       metadata_x *ptr4 = NULL;
+       permission_x *ptr5 = NULL;
+       image_x *ptr6 = NULL;
        sqlite3 *appinfo_db = NULL;
 
        /*get system locale*/
@@ -4064,8 +3800,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
        tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
 
        /*calloc allinfo*/
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX  - 1);
-       allinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
        tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
 
        /*calloc manifest_info*/
@@ -4110,6 +3845,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                /*If the callback func return < 0 we break and no more call back is called*/
                while(tmp != NULL)
                {
+                       appinfo->locale = strdup(locale);
                        appinfo->uiapp_info = tmp;
                        if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
                                if (locale) {
@@ -4148,6 +3884,22 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->uiapp_info->icon, ptr1);
                                appinfo->uiapp_info->icon = ptr1;
                        }
+                       if (appinfo->uiapp_info->category) {
+                               LISTHEAD(appinfo->uiapp_info->category, ptr3);
+                               appinfo->uiapp_info->category = ptr3;
+                       }
+                       if (appinfo->uiapp_info->metadata) {
+                               LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
+                               appinfo->uiapp_info->metadata = ptr4;
+                       }
+                       if (appinfo->uiapp_info->permission) {
+                               LISTHEAD(appinfo->uiapp_info->permission, ptr5);
+                               appinfo->uiapp_info->permission = ptr5;
+                       }
+                       if (appinfo->uiapp_info->image) {
+                               LISTHEAD(appinfo->uiapp_info->image, ptr6);
+                               appinfo->uiapp_info->image = ptr6;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4168,6 +3920,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                /*If the callback func return < 0 we break and no more call back is called*/
                while(tmp1 != NULL)
                {
+                       appinfo->locale = strdup(locale);
                        appinfo->svcapp_info = tmp1;
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
@@ -4187,6 +3940,18 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->svcapp_info->icon, ptr1);
                                appinfo->svcapp_info->icon = ptr1;
                        }
+                       if (appinfo->svcapp_info->category) {
+                               LISTHEAD(appinfo->svcapp_info->category, ptr3);
+                               appinfo->svcapp_info->category = ptr3;
+                       }
+                       if (appinfo->svcapp_info->metadata) {
+                               LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
+                               appinfo->svcapp_info->metadata = ptr4;
+                       }
+                       if (appinfo->svcapp_info->permission) {
+                               LISTHEAD(appinfo->svcapp_info->permission, ptr5);
+                               appinfo->svcapp_info->permission = ptr5;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4212,6 +3977,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                /*If the callback func return < 0 we break and no more call back is called*/
                while(tmp2 != NULL)
                {
+                       appinfo->locale = strdup(locale);
                        appinfo->uiapp_info = tmp2;
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
@@ -4243,6 +4009,22 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->uiapp_info->icon, ptr1);
                                appinfo->uiapp_info->icon = ptr1;
                        }
+                       if (appinfo->uiapp_info->category) {
+                               LISTHEAD(appinfo->uiapp_info->category, ptr3);
+                               appinfo->uiapp_info->category = ptr3;
+                       }
+                       if (appinfo->uiapp_info->metadata) {
+                               LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
+                               appinfo->uiapp_info->metadata = ptr4;
+                       }
+                       if (appinfo->uiapp_info->permission) {
+                               LISTHEAD(appinfo->uiapp_info->permission, ptr5);
+                               appinfo->uiapp_info->permission = ptr5;
+                       }
+                       if (appinfo->uiapp_info->image) {
+                               LISTHEAD(appinfo->uiapp_info->image, ptr6);
+                               appinfo->uiapp_info->image = ptr6;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4260,6 +4042,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                /*If the callback func return < 0 we break and no more call back is called*/
                while(tmp3 != NULL)
                {
+                       appinfo->locale = strdup(locale);
                        appinfo->svcapp_info = tmp3;
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
@@ -4279,6 +4062,18 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->svcapp_info->icon, ptr1);
                                appinfo->svcapp_info->icon = ptr1;
                        }
+                       if (appinfo->svcapp_info->category) {
+                               LISTHEAD(appinfo->svcapp_info->category, ptr3);
+                               appinfo->svcapp_info->category = ptr3;
+                       }
+                       if (appinfo->svcapp_info->metadata) {
+                               LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
+                               appinfo->svcapp_info->metadata = ptr4;
+                       }
+                       if (appinfo->svcapp_info->permission) {
+                               LISTHEAD(appinfo->svcapp_info->permission, ptr5);
+                               appinfo->svcapp_info->permission = ptr5;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4301,7 +4096,7 @@ catch:
        }
        if (appinfo) {
                if (appinfo->package) {
-                       free(appinfo->package);
+                       free((void *)appinfo->package);
                        appinfo->package = NULL;
                }
                free(appinfo);
@@ -4313,6 +4108,65 @@ catch:
        return ret;
 }
 
+API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+{
+       retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
+
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       pkgmgr_appinfo_x *info = NULL;
+       pkgmgr_appinfo_x *appinfo = NULL;
+       uiapplication_x *ptr1 = NULL;
+       sqlite3 *appinfo_db = NULL;
+
+       /*open db*/
+       ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+
+       /*calloc appinfo*/
+       info = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
+
+       /*calloc uiapplication_x*/
+       info->uiapp_info= (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
+       tryvm_if(info->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
+
+       /*calloc appinfo*/
+       appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
+
+       /*query package_app_info*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
+       ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
+
+       LISTHEAD(info->uiapp_info, ptr1);
+
+       /*call back*/
+       for(ptr1 = ptr1->next ; ptr1 ; ptr1 = ptr1->next)
+       {
+               appinfo->uiapp_info= ptr1;
+               appinfo->package = strdup(ptr1->package);
+               appinfo->app_component = PMINFO_UI_APP;
+
+               ret = app_func((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               free((void *)appinfo->package);
+               appinfo->package = NULL;
+       }
+
+catch:
+       sqlite3_close(appinfo_db);
+
+       if (appinfo) {
+               free(appinfo);
+               appinfo = NULL;
+       }
+       __cleanup_appinfo(info);
+       return ret;
+}
+
 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
 {
        retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
@@ -4326,6 +4180,10 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
        serviceapplication_x *ptr2 = NULL;
        label_x *tmp1 = NULL;
        icon_x *tmp2 = NULL;
+       category_x *tmp3 = NULL;
+       metadata_x *tmp4 = NULL;
+       permission_x *tmp5 = NULL;
+       image_x *tmp6 = NULL;
        sqlite3 *appinfo_db = NULL;
 
        /*get system locale*/
@@ -4341,7 +4199,6 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
        retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
 
        /*calloc pkginfo*/
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX  - 1);
        pkgmgr_pkginfo_x *info = NULL;
        info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
        tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
@@ -4370,6 +4227,7 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
        /*UI Apps*/
        for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
        {
+               appinfo->locale = strdup(locale);
                appinfo->app_component = PMINFO_UI_APP;
                appinfo->package = strdup(ptr1->package);
                appinfo->uiapp_info = ptr1;
@@ -4423,15 +4281,32 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                        LISTHEAD(appinfo->uiapp_info->icon, tmp2);
                        appinfo->uiapp_info->icon= tmp2;
                }
+               if (appinfo->uiapp_info->category) {
+                       LISTHEAD(appinfo->uiapp_info->category, tmp3);
+                       appinfo->uiapp_info->category = tmp3;
+               }
+               if (appinfo->uiapp_info->metadata) {
+                       LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
+                       appinfo->uiapp_info->metadata = tmp4;
+               }
+               if (appinfo->uiapp_info->permission) {
+                       LISTHEAD(appinfo->uiapp_info->permission, tmp5);
+                       appinfo->uiapp_info->permission = tmp5;
+               }
+               if (appinfo->uiapp_info->image) {
+                       LISTHEAD(appinfo->uiapp_info->image, tmp6);
+                       appinfo->uiapp_info->image = tmp6;
+               }
                ret = app_func((void *)appinfo, user_data);
                if (ret < 0)
                        break;
-               free(appinfo->package);
+               free((void *)appinfo->package);
                appinfo->package = NULL;
        }
        /*Service Apps*/
        for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
        {
+               appinfo->locale = strdup(locale);
                appinfo->app_component = PMINFO_SVC_APP;
                appinfo->package = strdup(ptr2->package);
                appinfo->svcapp_info = ptr2;
@@ -4466,10 +4341,22 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                        LISTHEAD(appinfo->svcapp_info->icon, tmp2);
                        appinfo->svcapp_info->icon= tmp2;
                }
+               if (appinfo->svcapp_info->category) {
+                       LISTHEAD(appinfo->svcapp_info->category, tmp3);
+                       appinfo->svcapp_info->category = tmp3;
+               }
+               if (appinfo->svcapp_info->metadata) {
+                       LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
+                       appinfo->svcapp_info->metadata = tmp4;
+               }
+               if (appinfo->svcapp_info->permission) {
+                       LISTHEAD(appinfo->svcapp_info->permission, tmp5);
+                       appinfo->svcapp_info->permission = tmp5;
+               }
                ret = app_func((void *)appinfo, user_data);
                if (ret < 0)
                        break;
-               free(appinfo->package);
+               free((void *)appinfo->package);
                appinfo->package = NULL;
        }
        ret = PMINFO_R_OK;
@@ -4507,6 +4394,7 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        category_x *tmp3 = NULL;
        metadata_x *tmp4 = NULL;
        permission_x *tmp5 = NULL;
+       image_x *tmp6 = NULL;
        char query[MAX_QUERY_LEN] = {'\0'};
        sqlite3 *appinfo_db = NULL;
 
@@ -4518,7 +4406,7 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
        ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
-       tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid not found in DB");
+       tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
 
        /*get system locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
@@ -4529,7 +4417,6 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
 
        /*calloc appinfo*/
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
        appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
        tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
 
@@ -4547,6 +4434,7 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
                appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
                tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
        }
+       appinfo->locale = strdup(locale);
 
        /*populate app_info from DB*/
        memset(query, '\0', MAX_QUERY_LEN);
@@ -4617,6 +4505,10 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
                        LISTHEAD(appinfo->uiapp_info->permission, tmp5);
                        appinfo->uiapp_info->permission = tmp5;
                }
+               if (appinfo->uiapp_info->image) {
+                       LISTHEAD(appinfo->uiapp_info->image, tmp6);
+                       appinfo->uiapp_info->image = tmp6;
+               }
                break;
        case PMINFO_SVC_APP:
                if (appinfo->svcapp_info->label) {
@@ -4669,14 +4561,8 @@ catch:
 
 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (appid == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_component == PMINFO_UI_APP)
@@ -4689,14 +4575,8 @@ API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
 
 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h  handle, char **pkg_name)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (pkg_name == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        *pkg_name = (char *)info->package;
@@ -4706,14 +4586,8 @@ API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h  handle, char **pkg_
 
 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h  handle, char **pkgid)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (pkgid == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        *pkgid = (char *)info->package;
@@ -4723,14 +4597,8 @@ API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h  handle, char **pkgid)
 
 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h  handle, char **exec)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (exec == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_component == PMINFO_UI_APP)
@@ -4744,21 +4612,17 @@ API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h  handle, char **exec)
 
 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
 {
-        if (handle == NULL) {
-                _LOGE("appinfo handle is NULL\n");
-                return PMINFO_R_EINVAL;
-        }
-        if (icon == NULL) {
-                _LOGE("Argument supplied to hold return value is NULL\n");
-                return PMINFO_R_EINVAL;
-        }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
         char *locale = NULL;
         icon_x *ptr = NULL;
         icon_x *start = NULL;
         *icon = NULL;
-       locale= glocale;
-       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+               locale = info->locale;
+               retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
         if (info->app_component == PMINFO_UI_APP)
                 start = info->uiapp_info->icon;
         if (info->app_component == PMINFO_SVC_APP)
@@ -4785,21 +4649,17 @@ API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
 
 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (label == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *locale = NULL;
        label_x *ptr = NULL;
        label_x *start = NULL;
        *label = NULL;
-       locale = glocale;
-       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       locale = info->locale;
+       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+
        if (info->app_component == PMINFO_UI_APP)
                start = info->uiapp_info->label;
        if (info->app_component == PMINFO_SVC_APP)
@@ -4833,14 +4693,8 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
 
 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_component *component)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (component == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_component == PMINFO_UI_APP)
@@ -4855,14 +4709,8 @@ API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinf
 
 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h  handle, char **app_type)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (app_type == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_component == PMINFO_UI_APP)
@@ -4876,14 +4724,9 @@ API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h  handle, char **app_
 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
                                        int *operation_count, char ***operation)
 {
-       if (handle == NULL) {
-               _LOGE("appcontrol handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (operation_count == NULL || operation == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
        *operation_count = data->operation_count;
        *operation = data->operation;
@@ -4893,14 +4736,9 @@ API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
                                        int *uri_count, char ***uri)
 {
-       if (handle == NULL) {
-               _LOGE("appcontrol handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (uri_count == NULL || uri == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
        *uri_count = data->uri_count;
        *uri = data->uri;
@@ -4910,20 +4748,27 @@ API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
                                        int *mime_count, char ***mime)
 {
-       if (handle == NULL) {
-               _LOGE("appcontrol handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (mime_count == NULL || mime == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
        *mime_count = data->mime_count;
        *mime = data->mime;
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
+                                       int *subapp_count, char ***subapp)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
+       *subapp_count = data->subapp_count;
+       *subapp = data->subapp;
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h  handle, char **icon)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
@@ -4979,14 +4824,8 @@ API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h  handle, c
 
 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_recentimage *type)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (type == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->recentimage;
@@ -5020,7 +4859,7 @@ API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h  handle, char
                        val = (char *)ptr->section;
 
                        if (strcmp(val, "preview") == 0)
-                               *preview_img = (char *)info->uiapp_info->image->text;
+                               *preview_img = (char *)ptr->text;
 
                        break;
                }
@@ -5034,46 +4873,120 @@ API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h  handle, pkg
        retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        char *val = NULL;
-       permission_x *ptr = NULL;
-       permission_x *start = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_component == PMINFO_UI_APP)
-               start = info->uiapp_info->permission;
-       else if (info->app_component == PMINFO_SVC_APP)
-               start = info->svcapp_info->permission;
+       val = info->uiapp_info->permission_type;
+
+       if (strcmp(val, "signature") == 0)
+               *permission = PMINFO_PERMISSION_SIGNATURE;
+       else if (strcmp(val, "privilege") == 0)
+               *permission = PMINFO_PERMISSION_PRIVILEGE;
        else
-               return PMINFO_R_EINVAL;
+               *permission = PMINFO_PERMISSION_NORMAL;
 
-       for(ptr = start; ptr != NULL; ptr = ptr->next)
-       {
-               if (ptr->type) {
-                       val = (char *)ptr->type;
+       return PMINFO_R_OK;
+}
 
-                       if (strcmp(val, "signature") == 0)
-                               *permission = PMINFO_PERMISSION_SIGNATURE;
-                       else if (strcmp(val, "privilege") == 0)
-                               *permission = PMINFO_PERMISSION_PRIVILEGE;
-                       else
-                               *permission = PMINFO_PERMISSION_NORMAL;
+API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h  handle, char **component_type)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-                       break;
-               }
+       *component_type = (char *)info->uiapp_info->component_type;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       char *val = NULL;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       val = (char *)info->uiapp_info->hwacceleration;
+       if (val) {
+               if (strcasecmp(val, "not-use-GL") == 0)
+                       *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
+               else if (strcasecmp(val, "use-GL") == 0)
+                       *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
+               else
+                       *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
        }
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
-                       pkgmgrinfo_app_category_list_cb category_func, void *user_data)
+API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_screenreader *screenreader)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       char *val = NULL;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       val = (char *)info->uiapp_info->screenreader;
+       if (val) {
+               if (strcasecmp(val, "screenreader-off") == 0)
+                       *screenreader = PMINFO_SCREENREADER_OFF;
+               else if (strcasecmp(val, "screenreader-on") == 0)
+                       *screenreader = PMINFO_SCREENREADER_ON;
+               else
+                       *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
+       }
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h  handle, char **portrait_img, char **landscape_img)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info->app_component == PMINFO_UI_APP){
+               *portrait_img = (char *)info->uiapp_info->portraitimg;
+               *landscape_img = (char *)info->uiapp_info->landscapeimg;
        }
-       if (category_func == NULL) {
-               _LOGE("Callback function is NULL\n");
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       *submode_mainid = (char *)info->uiapp_info->submode_mainid;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret = -1;
+       permission_x *ptr = NULL;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       if (info->app_component == PMINFO_UI_APP)
+               ptr = info->uiapp_info->permission;
+       else if (info->app_component == PMINFO_SVC_APP)
+               ptr = info->svcapp_info->permission;
+       else
                return PMINFO_R_EINVAL;
+       for (; ptr; ptr = ptr->next) {
+               ret = permission_func(ptr->value, user_data);
+               if (ret < 0)
+                       break;
        }
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_category_list_cb category_func, void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int ret = -1;
        category_x *ptr = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -5094,14 +5007,8 @@ API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (metadata_func == NULL) {
-               _LOGE("Callback function is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int ret = -1;
        metadata_x *ptr = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -5112,9 +5019,11 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
        else
                return PMINFO_R_EINVAL;
        for (; ptr; ptr = ptr->next) {
-               ret = metadata_func(ptr->name, ptr->value, user_data);
-               if (ret < 0)
-                       break;
+               if (ptr->key) {
+                       ret = metadata_func(ptr->key, ptr->value, user_data);
+                       if (ret < 0)
+                               break;
+               }
        }
        return PMINFO_R_OK;
 }
@@ -5122,29 +5031,26 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (appcontrol_func == NULL) {
-               _LOGE("Callback function is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int i = 0;
        int ret = -1;
        int oc = 0;
        int mc = 0;
        int uc = 0;
+       int sc = 0;
        char *pkgid = NULL;
        char *manifest = NULL;
        char **operation = NULL;
        char **uri = NULL;
        char **mime = NULL;
+       char **subapp = NULL;
        appcontrol_x *appcontrol = NULL;
        manifest_x *mfx = NULL;
        operation_x *op = NULL;
        uri_x *ui = NULL;
        mime_x *mi = NULL;
+       subapp_x *sa = NULL;
        pkgmgrinfo_app_component component;
        pkgmgrinfo_appcontrol_x *ptr = NULL;
        ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
@@ -5180,15 +5086,15 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
        switch (component) {
        case PMINFO_UI_APP:
                if (mfx->uiapplication) {
-                       if (mfx->uiapplication->appcontrol) {
-                               appcontrol = mfx->uiapplication->appcontrol;
+                       if (mfx->uiapplication->appsvc) {
+                               appcontrol = mfx->uiapplication->appsvc;
                        }
                }
                break;
        case PMINFO_SVC_APP:
                if (mfx->serviceapplication) {
-                       if (mfx->serviceapplication->appcontrol) {
-                               appcontrol = mfx->serviceapplication->appcontrol;
+                       if (mfx->serviceapplication->appsvc) {
+                               appcontrol = mfx->serviceapplication->appsvc;
                        }
                }
                break;
@@ -5211,6 +5117,11 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        mc = mc + 1;
                mi = appcontrol->mime;
 
+               sa = appcontrol->subapp;
+               for (; sa; sa = sa->next)
+                       sc = sc + 1;
+               sa = appcontrol->subapp;
+
                operation = (char **)calloc(oc, sizeof(char *));
                for (i = 0; i < oc; i++) {
                        operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
@@ -5228,13 +5139,23 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
                        mi = mi->next;
                }
+
+               subapp = (char **)calloc(sc, sizeof(char *));
+               for (i = 0; i < sc; i++) {
+                       subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
+                       sa = sa->next;
+               }
+
                /*populate appcontrol handle*/
                ptr->operation_count = oc;
                ptr->uri_count = uc;
                ptr->mime_count = mc;
+               ptr->subapp_count = sc;
                ptr->operation = operation;
                ptr->uri = uri;
                ptr->mime = mime;
+               ptr->subapp = subapp;
+
                ret = appcontrol_func((void *)ptr, user_data);
                for (i = 0; i < oc; i++) {
                        if (operation[i]) {
@@ -5266,11 +5187,22 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        free(mime);
                        mime = NULL;
                }
+               for (i = 0; i < sc; i++) {
+                       if (subapp[i]) {
+                               free(subapp[i]);
+                               subapp[i] = NULL;
+                       }
+               }
+               if (subapp) {
+                       free(subapp);
+                       subapp = NULL;
+               }
                if (ret < 0)
                        break;
                uc = 0;
                mc = 0;
                oc = 0;
+               sc = 0;
        }
        pkgmgr_parser_free_manifest_xml(mfx);
        if (ptr) {
@@ -5282,14 +5214,8 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
 
 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h  handle, bool *nodisplay)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (nodisplay == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->nodisplay;
@@ -5306,14 +5232,8 @@ API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h  handle, bool *nodi
 
 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h  handle, bool *multiple)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (multiple == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->multiple;
@@ -5330,14 +5250,8 @@ API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h  handle, bool *multi
 
 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (indicator_disp == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->indicatordisplay;
@@ -5353,41 +5267,10 @@ API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h han
        return PMINFO_R_OK;
 }
 
-
-API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h  handle, char **portrait_img, char **landscape_img)
-{
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (portrait_img == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (landscape_img == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
-
-       if (info->app_component == PMINFO_UI_APP){
-               *portrait_img = (char *)info->uiapp_info->portraitimg;
-               *landscape_img = (char *)info->uiapp_info->landscapeimg;
-       }
-
-       return PMINFO_R_OK;
-}
-
 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (taskmanage == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->taskmanage;
@@ -5404,14 +5287,8 @@ API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *tas
 
 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (enabled == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        if (info->app_component == PMINFO_UI_APP)
@@ -5435,40 +5312,10 @@ API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enable
 
 }
 
-API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
-{
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (hwacceleration == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       char *val = NULL;
-       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
-       val = (char *)info->uiapp_info->hwacceleration;
-       if (val) {
-               if (strcasecmp(val, "not-use-GL") == 0)
-                       *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
-               else if (strcasecmp(val, "use-GL") == 0)
-                       *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
-               else
-                       *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
-       }
-       return PMINFO_R_OK;
-}
-
 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (onboot == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->svcapp_info->onboot;
@@ -5485,14 +5332,8 @@ API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
 
 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (autorestart == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->svcapp_info->autorestart;
@@ -5509,14 +5350,8 @@ API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *au
 
 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (mainapp == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->mainapp;
@@ -5531,12 +5366,45 @@ API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainap
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
+API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
+       retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       char *val = NULL;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       val = (char *)info->uiapp_info->preload;
+       if (val) {
+               if (strcasecmp(val, "true") == 0)
+                       *preload = 1;
+               else if (strcasecmp(val, "false") == 0)
+                       *preload = 0;
+               else
+                       *preload = 0;
        }
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
+       retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       char *val = NULL;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       val = (char *)info->uiapp_info->submode;
+       if (val) {
+               if (strcasecmp(val, "true") == 0)
+                       *submode = 1;
+               else if (strcasecmp(val, "false") == 0)
+                       *submode = 0;
+               else
+                       *submode = 0;
+       }
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        __cleanup_appinfo(info);
        return PMINFO_R_OK;
@@ -5555,10 +5423,8 @@ API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
                                const char *property, const int value)
 {
-       if (handle == NULL || property == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
        char *val = NULL;
        GSList *link = NULL;
@@ -5598,10 +5464,8 @@ API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
                                const char *property, const bool value)
 {
-       if (handle == NULL || property == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *val = NULL;
        GSList *link = NULL;
        int prop = -1;
@@ -5642,10 +5506,9 @@ API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                                const char *property, const char *value)
 {
-       if (handle == NULL || property == NULL || value == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *val = NULL;
        pkgmgrinfo_node_x *ptr = NULL;
        char prev[PKG_STRING_LEN_MAX] = {'\0'};
@@ -5722,10 +5585,8 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
 
 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
 {
-       if (handle == NULL || count == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *syslocale = NULL;
        char *locale = NULL;
        char *condition = NULL;
@@ -5748,7 +5609,7 @@ API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int
                free(syslocale);
                return PMINFO_R_ERROR;
        }
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
+
        ret = __open_manifest_db();
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
@@ -5808,10 +5669,8 @@ err:
 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
                                pkgmgrinfo_app_list_cb app_cb, void * user_data)
 {
-       if (handle == NULL || app_cb == NULL) {
-               _LOGE("Filter handle input parameter is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
        char *syslocale = NULL;
        char *locale = NULL;
        char *condition = NULL;
@@ -5835,7 +5694,7 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                free(syslocale);
                return PMINFO_R_ERROR;
        }
-       strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
+
        ret = __open_manifest_db();
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
@@ -5952,6 +5811,7 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
        /*If the callback func return < 0 we break and no more call back is called*/
        while(ptr1 != NULL)
        {
+               appinfo->locale = strdup(locale);
                appinfo->uiapp_info = ptr1;
                appinfo->app_component = PMINFO_UI_APP;
                ret = app_cb((void *)appinfo, user_data);
@@ -5967,6 +5827,7 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
        /*If the callback func return < 0 we break and no more call back is called*/
        while(ptr2 != NULL)
        {
+               appinfo->locale = strdup(locale);
                appinfo->svcapp_info = ptr2;
                appinfo->app_component = PMINFO_SVC_APP;
                ret = app_cb((void *)appinfo, user_data);
@@ -5994,47 +5855,235 @@ err:
        return ret;
 }
 
-API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
+API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       return (pkgmgrinfo_pkginfo_filter_create(handle));
+}
+
+API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
+{
+       return (pkgmgrinfo_pkginfo_filter_destroy(handle));
+}
+
+API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
+               const char *key, const char *value)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
+       retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
+       /*value can be NULL. In that case all apps with specified key should be displayed*/
        int ret = 0;
-       pkgmgr_certinfo_x *certinfo = NULL;
-       certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
-       if (!certinfo) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
-       }
-       *handle = (void *)certinfo;
-       /*Open db. It will be closed in destroy handle API*/
-       ret = db_util_open_with_options(CERT_DB, &cert_db,
-                                       SQLITE_OPEN_READONLY, NULL);
-       if (ret != SQLITE_OK) {
-               _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
-               free(certinfo);
-               return PMINFO_R_ERROR;
-       }
+       char *k = NULL;
+       char *v = NULL;
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
+       retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
+       k = strdup(key);
+       tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+       node->key = k;
+       if (value) {
+               v = strdup(value);
+               tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+       }
+       node->value = v;
+       /*If API is called multiple times, we should OR all conditions.*/
+       filter->list = g_slist_append(filter->list, (gpointer)node);
+       /*All memory will be freed in destroy API*/
        return PMINFO_R_OK;
+catch:
+       if (node) {
+               if (node->key) {
+                       free(node->key);
+                       node->key = NULL;
+               }
+               if (node->value) {
+                       free(node->value);
+                       node->value = NULL;
+               }
+               free(node);
+               node = NULL;
+       }
+       return ret;
 }
 
-API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
+API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
+               pkgmgrinfo_app_list_cb app_cb, void *user_data)
 {
-       if (pkgid == NULL) {
-               _LOGE("package ID is NULL\n");
-               return PMINFO_R_EINVAL;
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
+       retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
+       char *syslocale = NULL;
+       char *locale = NULL;
+       char *condition = NULL;
+       char *error_message = NULL;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char where[MAX_QUERY_LEN] = {'\0'};
+       GSList *list;
+       int ret = 0;
+       pkgmgr_pkginfo_x *info = NULL;
+       pkgmgr_pkginfo_x *filtinfo = NULL;
+       pkgmgr_appinfo_x *appinfo = NULL;
+       uiapplication_x *ptr1 = NULL;
+       serviceapplication_x *ptr2 = NULL;
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+
+       /*Get current locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
+
+       ret = __open_manifest_db();
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
+
+       /*Start constructing query*/
+       memset(where, '\0', MAX_QUERY_LEN);
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
+       /*Get where clause*/
+       for (list = filter->list; list; list = g_slist_next(list)) {
+               __get_metadata_filter_condition(list->data, &condition);
+               if (condition) {
+                       strncat(where, condition, sizeof(where) - strlen(where) -1);
+                       free(condition);
+                       condition = NULL;
+               }
+               if (g_slist_next(list)) {
+                       strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
+               }
        }
-       if (handle == NULL) {
-               _LOGE("Certinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
+       _LOGE("where = %s (%d)\n", where, strlen(where));
+       if (strlen(where) > 0) {
+               strncat(query, where, sizeof(query) - strlen(query) - 1);
+       }
+       _LOGE("query = %s (%d)\n", query, strlen(query));
+       /*To get filtered list*/
+       info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       /*To get detail app info for each member of filtered list*/
+       filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
+       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
+       memset(query, '\0', MAX_QUERY_LEN);
+
+       if (info->manifest_info->uiapplication) {
+               LISTHEAD(info->manifest_info->uiapplication, ptr1);
+               info->manifest_info->uiapplication = ptr1;
+       }
+       if (info->manifest_info->serviceapplication) {
+               LISTHEAD(info->manifest_info->serviceapplication, ptr2);
+               info->manifest_info->serviceapplication = ptr2;
+       }
+
+       /*UI Apps*/
+       for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
+       {
+               snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
+                                                       ptr1->appid, "uiapp");
+               ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
+               tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
+               memset(query, '\0', MAX_QUERY_LEN);
+       }
+       /*Service Apps*/
+       for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
+       {
+               snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
+                                                       ptr2->appid, "svcapp");
+               ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
+               tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
+               memset(query, '\0', MAX_QUERY_LEN);
+       }
+       /*Filtered UI Apps*/
+       if (filtinfo->manifest_info->uiapplication) {
+               LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
+               filtinfo->manifest_info->uiapplication = ptr1;
+       }
+       /*If the callback func return < 0 we break and no more call back is called*/
+       while(ptr1 != NULL)
+       {
+               appinfo->locale = strdup(locale);
+               appinfo->uiapp_info = ptr1;
+               appinfo->app_component = PMINFO_UI_APP;
+               ret = app_cb((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               ptr1 = ptr1->next;
+       }
+       /*Filtered Service Apps*/
+       if (filtinfo->manifest_info->serviceapplication) {
+               LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
+               filtinfo->manifest_info->serviceapplication = ptr2;
+       }
+       /*If the callback func return < 0 we break and no more call back is called*/
+       while(ptr2 != NULL)
+       {
+               appinfo->locale = strdup(locale);
+               appinfo->svcapp_info = ptr2;
+               appinfo->app_component = PMINFO_SVC_APP;
+               ret = app_cb((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               ptr2 = ptr2->next;
+       }
+       ret = PMINFO_R_OK;
+catch:
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       sqlite3_free(error_message);
+       sqlite3_close(manifest_db);
+       if (appinfo) {
+               free(appinfo);
+               appinfo = NULL;
        }
+       __cleanup_pkginfo(info);
+       __cleanup_pkginfo(filtinfo);
+       return ret;
+}
+
+API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       pkgmgr_certinfo_x *certinfo = NULL;
+       certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
+       retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
+       *handle = (void *)certinfo;
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
+{
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
        pkgmgr_certinfo_x *certinfo = NULL;
        char *error_message = NULL;
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        int exist = 0;
+       int i = 0;
 
+       /*Open db.*/
+       ret = db_util_open_with_options(CERT_DB, &cert_db,
+                                       SQLITE_OPEN_READONLY, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("connect db [%s] failed!\n", CERT_DB);
+               return PMINFO_R_ERROR;
+       }
        /*validate pkgid*/
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
        if (SQLITE_OK !=
@@ -6042,7 +6091,8 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
        if (exist == 0) {
                _LOGE("Package not found in DB\n");
@@ -6058,783 +6108,433 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_
                ret = PMINFO_R_ERROR;
                goto err;
        }
-       return PMINFO_R_OK;
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               memset(query, '\0', MAX_QUERY_LEN);
+               snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
+               ret = __exec_certinfo_query(query, (void *)certinfo);
+               if (ret == -1) {
+                       _LOGE("Cert Info DB Information retrieval failed\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               if (certinfo->cert_value) {
+                       (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
+                       free(certinfo->cert_value);
+                       certinfo->cert_value = NULL;
+               }
+       }
 err:
+       sqlite3_close(cert_db);
        return ret;
 }
 
 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
 {
-       if (!handle || !cert_value) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if ((cert_type < PMINFO_AUTHOR_ROOT_CERT) || (cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT)) {
-               _LOGE("Invalid certificate type\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
+       retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
        pkgmgr_certinfo_x *certinfo = NULL;
-       char *error_message = NULL;
-       int ret = PMINFO_R_OK;
-       char query[MAX_QUERY_LEN] = {'\0'};
-       int exist = 0;
        certinfo = (pkgmgr_certinfo_x *)handle;
-       *cert_value = NULL;
-       switch(cert_type) {
-       case PMINFO_AUTHOR_SIGNER_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->auth_signer_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->auth_signer_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info " \
-                               "where package='%s'", certinfo->auth_signer_cert);
-                       free(certinfo->auth_signer_cert);
-                       certinfo->auth_signer_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->auth_signer_cert;
-               }
-               break;
-       case PMINFO_AUTHOR_INTERMEDIATE_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->auth_im_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->auth_im_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_im_cert from package_cert_info " \
-                               "where package='%s'", certinfo->auth_im_cert);
-                       free(certinfo->auth_im_cert);
-                       certinfo->auth_im_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->auth_im_cert;
-               }
-               break;
-       case PMINFO_AUTHOR_ROOT_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->auth_root_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->auth_root_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select author_root_cert from package_cert_info " \
-                               "where package='%s'", certinfo->auth_root_cert);
-                       free(certinfo->auth_root_cert);
-                       certinfo->auth_root_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->auth_root_cert;
-               }
-               break;
-       case PMINFO_DISTRIBUTOR_SIGNER_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist_signer_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->dist_signer_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select dist_signer_cert from package_cert_info " \
-                               "where package='%s'", certinfo->dist_signer_cert);
-                       free(certinfo->dist_signer_cert);
-                       certinfo->dist_signer_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->dist_signer_cert;
-               }
-               break;
-       case PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist_im_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->dist_im_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select dist_im_cert from package_cert_info " \
-                               "where package='%s'", certinfo->dist_im_cert);
-                       free(certinfo->dist_im_cert);
-                       certinfo->dist_im_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->dist_im_cert;
-               }
-               break;
-       case PMINFO_DISTRIBUTOR_ROOT_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist_root_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->dist_root_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select dist_root_cert from package_cert_info " \
-                               "where package='%s'", certinfo->dist_root_cert);
-                       free(certinfo->dist_root_cert);
-                       certinfo->dist_root_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->dist_root_cert;
-               }
-               break;
-       case PMINFO_DISTRIBUTOR2_SIGNER_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist2_signer_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->dist2_signer_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select dist2_signer_cert from package_cert_info " \
-                               "where package='%s'", certinfo->dist2_signer_cert);
-                       free(certinfo->dist2_signer_cert);
-                       certinfo->dist2_signer_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->dist2_signer_cert;
-               }
-               break;
-       case PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist2_im_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->dist2_im_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select dist2_im_cert from package_cert_info " \
-                               "where package='%s'", certinfo->dist2_im_cert);
-                       free(certinfo->dist2_im_cert);
-                       certinfo->dist2_im_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->dist2_im_cert;
-               }
-               break;
-       case PMINFO_DISTRIBUTOR2_ROOT_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist2_root_cert);
-               if (SQLITE_OK !=
-                   sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                              error_message);
-                       sqlite3_free(error_message);
-                       return PMINFO_R_ERROR;
-               }
-               if (exist == 0)
-                       *cert_value = certinfo->dist2_root_cert;
-               else {
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select dist2_root_cert from package_cert_info " \
-                               "where package='%s'", certinfo->dist2_root_cert);
-                       free(certinfo->dist2_root_cert);
-                       certinfo->dist2_root_cert = NULL;
-                       ret = __exec_certinfo_query(query, (void *)certinfo);
-                       if (ret == -1) {
-                               _LOGE("Cert Info DB Information retrieval failed\n");
-                               return PMINFO_R_ERROR;
-                       }
-                       *cert_value = certinfo->dist2_root_cert;
-               }
-               break;
-       }
+       if ((certinfo->cert_info)[cert_type])
+               *cert_value = (certinfo->cert_info)[cert_type];
+       else
+               *cert_value = NULL;
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       int i = 0;
        pkgmgr_certinfo_x *certinfo = NULL;
        certinfo = (pkgmgr_certinfo_x *)handle;
        if (certinfo->pkgid) {
                free(certinfo->pkgid);
                certinfo->pkgid = NULL;
        }
-       if (certinfo->auth_signer_cert) {
-               free(certinfo->auth_signer_cert);
-               certinfo->auth_signer_cert = NULL;
-       }
-       if (certinfo->auth_im_cert) {
-               free(certinfo->auth_im_cert);
-               certinfo->auth_im_cert = NULL;
-       }
-       if (certinfo->auth_root_cert) {
-               free(certinfo->auth_root_cert);
-               certinfo->auth_root_cert = NULL;
-       }
-       if (certinfo->dist_signer_cert) {
-               free(certinfo->dist_signer_cert);
-               certinfo->dist_signer_cert = NULL;
-       }
-       if (certinfo->dist_im_cert) {
-               free(certinfo->dist_im_cert);
-               certinfo->dist_im_cert = NULL;
-       }
-       if (certinfo->dist_root_cert) {
-               free(certinfo->dist_root_cert);
-               certinfo->dist_root_cert = NULL;
-       }
-       if (certinfo->dist2_signer_cert) {
-               free(certinfo->dist2_signer_cert);
-               certinfo->dist2_signer_cert = NULL;
-       }
-       if (certinfo->dist2_im_cert) {
-               free(certinfo->dist2_im_cert);
-               certinfo->dist2_im_cert = NULL;
-       }
-       if (certinfo->dist2_root_cert) {
-               free(certinfo->dist2_root_cert);
-               certinfo->dist2_root_cert = NULL;
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((certinfo->cert_info)[i]) {
+                       free((certinfo->cert_info)[i]);
+                       (certinfo->cert_info)[i] = NULL;
+               }
        }
        free(certinfo);
        certinfo = NULL;
-       sqlite3_close(cert_db);
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_instcertinfo_x *certinfo = NULL;
-       int ret = 0;
        certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
-       if (!certinfo) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
        *handle = (void *)certinfo;
-       /*Open db. It will be closed in destroy handle API*/
-       ret = db_util_open(CERT_DB, &cert_db,
-               DB_UTIL_REGISTER_HOOK_METHOD);
-       if (ret != SQLITE_OK) {
-               _LOGE("connect db [%s] failed!\n", CERT_DB);
-               free(certinfo);
-               return PMINFO_R_ERROR;
-       }
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
 {
-       if (!handle || !cert_value) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if ((cert_type < PMINFO_SET_AUTHOR_ROOT_CERT) || (cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT)) {
-               _LOGE("Invalid certificate type\n");
-               return PMINFO_R_EINVAL;
-       }
-       char query[MAX_QUERY_LEN] = {'\0'};
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
+       retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
        pkgmgr_instcertinfo_x *certinfo = NULL;
-       int ret = 0;
        certinfo = (pkgmgr_instcertinfo_x *)handle;
-       switch(cert_type) {
-       case PMINFO_SET_AUTHOR_SIGNER_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where author_signer_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->auth_signer_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->auth_signer_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_AUTHOR_INTERMEDIATE_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where author_im_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->auth_im_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->auth_im_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_AUTHOR_ROOT_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where author_root_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->auth_root_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->auth_root_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_DISTRIBUTOR_SIGNER_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where dist_signer_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->dist_signer_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->dist_signer_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where dist_im_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->dist_im_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->dist_im_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_DISTRIBUTOR_ROOT_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where dist_root_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->dist_root_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->dist_root_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where dist2_signer_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->dist2_signer_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->dist2_signer_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where dist2_im_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->dist2_im_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->dist2_im_cert = strdup(cert_value);
-               break;
-       case PMINFO_SET_DISTRIBUTOR2_ROOT_CERT:
-               snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
-                       "where dist2_root_cert='%s'", cert_value);
-               ret = __exec_certinfo_query(query, (void *)certinfo);
-               if (ret == -1) {
-                       _LOGE("Cert Info DB Information retrieval failed\n");
-                       return PMINFO_R_ERROR;
-               }
-               if (certinfo->pkgid)
-                       certinfo->dist2_root_cert = strdup(certinfo->pkgid);
-               else
-                       certinfo->dist2_root_cert = strdup(cert_value);
-               break;
-       }
-       if (certinfo->pkgid) {
-               free(certinfo->pkgid);
-               certinfo->pkgid = NULL;
-       }
+       (certinfo->cert_info)[cert_type] = strdup(cert_value);
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
 {
-       if (!handle || !pkgid) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
+       char *error_message = NULL;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char *vquery = NULL;
+       int len = 0;
+       int i = 0;
+       int j = 0;
+       int c = 0;
+       int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+       int newid = 0;
+       int is_new = 0;
+       int exist = -1;
+       int ret = -1;
+       int maxid = 0;
+       int flag = 0;
+       pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
+       pkgmgr_certindexinfo_x *indexinfo = NULL;
+       indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
+       if (indexinfo == NULL) {
+               _LOGE("Out of Memory!!!");
+               return PMINFO_R_ERROR;
+       }
+       info->pkgid = strdup(pkgid);
+
+       /*Open db.*/
+       ret = db_util_open_with_options(CERT_DB, &cert_db,
+                                       SQLITE_OPEN_READWRITE, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("connect db [%s] failed!\n", CERT_DB);
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       /*Begin Transaction*/
+       ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to begin transaction\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       _LOGE("Transaction Begin\n");
+       /*Check if request is to insert/update*/
+       snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
+       if (SQLITE_OK !=
+           sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+               sqlite3_free(error_message);
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       if (exist) {
+               /*Update request.
+               We cant just issue update query directly. We need to manage index table also.
+               Hence it is better to delete and insert again in case of update*/
+               ret = __delete_certinfo(pkgid);
+               if (ret < 0)
+                       _LOGE("Certificate Deletion Failed\n");
+       }
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((info->cert_info)[i]) {
+                       for (j = 0; j < i; j++) {
+                               if ( (info->cert_info)[j]) {
+                                       if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
+                                               (info->cert_id)[i] = (info->cert_id)[j];
+                                               (info->is_new)[i] = 0;
+                                               (info->ref_count)[i] = (info->ref_count)[j];
+                                               break;
+                                       }
+                               }
+                       }
+                       if (j < i)
+                               continue;
+                       memset(query, '\0', MAX_QUERY_LEN);
+                       snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
+                               "where cert_info='%s'",(info->cert_info)[i]);
+                       ret = __exec_certindexinfo_query(query, (void *)indexinfo);
+                       if (ret == -1) {
+                               _LOGE("Cert Info DB Information retrieval failed\n");
+                               ret = PMINFO_R_ERROR;
+                               goto err;
+                       }
+                       if (indexinfo->cert_id == 0) {
+                               /*New certificate. Get newid*/
+                               memset(query, '\0', MAX_QUERY_LEN);
+                               snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
+                               if (SQLITE_OK !=
+                                   sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
+                                       _LOGE("Don't execute query = %s error message = %s\n", query,
+                                              error_message);
+                                       sqlite3_free(error_message);
+                                       ret = PMINFO_R_ERROR;
+                                       goto err;
+                               }
+                               newid = newid + 1;
+                               if (flag == 0) {
+                                       maxid = newid;
+                                       flag = 1;
+                               }
+                               indexinfo->cert_id = maxid;
+                               indexinfo->cert_ref_count = 1;
+                               is_new = 1;
+                               maxid = maxid + 1;
+                       }
+                       (info->cert_id)[i] = indexinfo->cert_id;
+                       (info->is_new)[i] = is_new;
+                       (info->ref_count)[i] = indexinfo->cert_ref_count;
+                       _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
+                       indexinfo->cert_id = 0;
+                       indexinfo->cert_ref_count = 0;
+                       is_new = 0;
+               }
        }
-       char *error_message = NULL;
-       int exist = -1;
-       char query[MAX_QUERY_LEN] = {'\0'};
-       char *vquery = NULL;
-       int len = 0;
-       pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
-       info->pkgid = strdup(pkgid);
-       snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
-       if (SQLITE_OK !=
-           sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
-               _LOGE("Don't execute query = %s error message = %s\n", query,
-                      error_message);
-               sqlite3_free(error_message);
-               return PMINFO_R_ERROR;
+       len = MAX_QUERY_LEN;
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((info->cert_info)[i])
+                       len+= strlen((info->cert_info)[i]);
        }
-
-       len = 4096;
-       if (info->auth_root_cert)
-               len += strlen(info->auth_root_cert);
-       if (info->auth_im_cert)
-               len += strlen(info->auth_im_cert);
-       if (info->auth_signer_cert)
-               len += strlen(info->auth_signer_cert);
-       if (info->dist_root_cert)
-               len += strlen(info->dist_root_cert);
-       if (info->dist_im_cert)
-               len += strlen(info->dist_im_cert);
-       if (info->dist_signer_cert)
-               len += strlen(info->dist_signer_cert);
-       if (info->dist2_root_cert)
-               len += strlen(info->dist2_root_cert);
-       if (info->dist2_im_cert)
-               len += strlen(info->dist2_im_cert);
-       if (info->dist2_signer_cert)
-               len += strlen(info->dist2_signer_cert);
        vquery = (char *)calloc(1, len);
-
-       if (exist == 0) {
-               _LOGE("pkgid not found in DB\n");
-               /*insert*/
-               snprintf(vquery, len,
-                        "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
-                       "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
-                       "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
-                        info->pkgid, info->auth_root_cert, info->auth_im_cert, info->auth_signer_cert, info->dist_root_cert, info->dist_im_cert,
-                        info->dist_signer_cert, info->dist2_root_cert, info->dist2_im_cert, info->dist2_signer_cert);
-       } else {
-               _LOGE("pkgid exists in DB..Update it\n");
-               /*Update*/
-               snprintf(vquery, len,
-                        "update package_cert_info set author_root_cert='%s', author_im_cert='%s', author_signer_cert='%s', dist_root_cert='%s', " \
-                       "dist_im_cert='%s', dist_signer_cert='%s', dist2_root_cert='%s', dist2_im_cert='%s', dist2_signer_cert='%s' " \
-                       "where package='%s'",\
-                        info->auth_root_cert, info->auth_im_cert, info->auth_signer_cert, info->dist_root_cert, info->dist_im_cert,
-                        info->dist_signer_cert, info->dist2_root_cert, info->dist2_im_cert, info->dist2_signer_cert, info->pkgid);
-       }
+       /*insert*/
+       snprintf(vquery, len,
+                 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
+                "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
+                "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
+                 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
+               (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
+               (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
+               (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
+               (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
         if (SQLITE_OK !=
             sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", vquery,
                       error_message);
                sqlite3_free(error_message);
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
+               goto err;
         }
-       return PMINFO_R_OK;
+       /*Update index table info*/
+       /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((info->cert_info)[i]) {
+                       memset(vquery, '\0', len);
+                       if ((info->is_new)[i]) {
+                               snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
+                               "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
+                               unique_id[c++] = (info->cert_id)[i];
+                       } else {
+                               /*Update*/
+                               for (j = 0; j < MAX_CERT_TYPE; j++) {
+                                       if ((info->cert_id)[i] == unique_id[j]) {
+                                               /*Ref count has already been increased. Just continue*/
+                                               break;
+                                       }
+                               }
+                               if (j == MAX_CERT_TYPE)
+                                       unique_id[c++] = (info->cert_id)[i];
+                               else
+                                       continue;
+                               snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
+                               "where cert_id=%d",  (info->ref_count)[i] + 1, (info->cert_id)[i]);
+                       }
+                       if (SQLITE_OK !=
+                           sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
+                               _LOGE("Don't execute query = %s error message = %s\n", vquery,
+                                      error_message);
+                               sqlite3_free(error_message);
+                               ret = PMINFO_R_ERROR;
+                               goto err;
+                       }
+               }
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to commit transaction, Rollback now\n");
+               sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       _LOGE("Transaction Commit and End\n");
+       ret =  PMINFO_R_OK;
+err:
+       sqlite3_close(cert_db);
+       if (vquery) {
+               free(vquery);
+               vquery = NULL;
+       }
+       if (indexinfo) {
+               free(indexinfo);
+               indexinfo = NULL;
+       }
+       return ret;
 }
 
 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       int i = 0;
        pkgmgr_instcertinfo_x *certinfo = NULL;
        certinfo = (pkgmgr_instcertinfo_x *)handle;
        if (certinfo->pkgid) {
                free(certinfo->pkgid);
                certinfo->pkgid = NULL;
        }
-       if (certinfo->auth_signer_cert) {
-               free(certinfo->auth_signer_cert);
-               certinfo->auth_signer_cert = NULL;
-       }
-       if (certinfo->auth_im_cert) {
-               free(certinfo->auth_im_cert);
-               certinfo->auth_im_cert = NULL;
-       }
-       if (certinfo->auth_root_cert) {
-               free(certinfo->auth_root_cert);
-               certinfo->auth_root_cert = NULL;
-       }
-       if (certinfo->dist_signer_cert) {
-               free(certinfo->dist_signer_cert);
-               certinfo->dist_signer_cert = NULL;
-       }
-       if (certinfo->dist_im_cert) {
-               free(certinfo->dist_im_cert);
-               certinfo->dist_im_cert = NULL;
-       }
-       if (certinfo->dist_root_cert) {
-               free(certinfo->dist_root_cert);
-               certinfo->dist_root_cert = NULL;
-       }
-       if (certinfo->dist2_signer_cert) {
-               free(certinfo->dist2_signer_cert);
-               certinfo->dist2_signer_cert = NULL;
-       }
-       if (certinfo->dist2_im_cert) {
-               free(certinfo->dist2_im_cert);
-               certinfo->dist2_im_cert = NULL;
-       }
-       if (certinfo->dist2_root_cert) {
-               free(certinfo->dist2_root_cert);
-               certinfo->dist2_root_cert = NULL;
+       for (i = 0; i < MAX_CERT_TYPE; i++) {
+               if ((certinfo->cert_info)[i]) {
+                       free((certinfo->cert_info)[i]);
+                       (certinfo->cert_info)[i] = NULL;
+               }
        }
        free(certinfo);
        certinfo = NULL;
-       sqlite3_close(cert_db);
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
 {
-       if (!pkgid) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
        int ret = -1;
-       int i = 0;
-       char *error_message = NULL;
-       char query[MAX_QUERY_LEN] = {'\0'};
-       ret = db_util_open(CERT_DB, &cert_db,
-               DB_UTIL_REGISTER_HOOK_METHOD);
+       /*Open db.*/
+       ret = db_util_open_with_options(CERT_DB, &cert_db,
+                                       SQLITE_OPEN_READWRITE, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("connect db [%s] failed!\n", CERT_DB);
-               return PMINFO_R_ERROR;
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
-       /*First make copy of all entries for which other packages have an index here*/
-       snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package!='%s'", pkgid);
-        if (SQLITE_OK !=
-            sqlite3_exec(cert_db, query, __delete_certinfo_cb, (void *)pkgid, &error_message)) {
-                _LOGE("Don't execute query = %s error message = %s\n", query,
-                       error_message);
-               sqlite3_free(error_message);
-               sqlite3_close(cert_db);
+       /*Begin Transaction*/
+       ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to begin transaction\n");
                ret = PMINFO_R_ERROR;
                goto err;
-        }
-       /*Now delete the entry from db*/
-       snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
-        if (SQLITE_OK !=
-            sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
-                _LOGE("Don't execute query = %s error message = %s\n", query,
-                       error_message);
-               sqlite3_free(error_message);
-               sqlite3_close(cert_db);
+       }
+       _LOGE("Transaction Begin\n");
+       ret = __delete_certinfo(pkgid);
+       if (ret < 0) {
+               _LOGE("Certificate Deletion Failed\n");
+       } else {
+               _LOGE("Certificate Deletion Success\n");
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to commit transaction, Rollback now\n");
+               sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
                ret = PMINFO_R_ERROR;
                goto err;
-        }
+       }
+       _LOGE("Transaction Commit and End\n");
        ret = PMINFO_R_OK;
 err:
        sqlite3_close(cert_db);
-       for (i = 0; i < 9; i++) {
-               gflag[i] = 0;
-               if (gpkgcert[i]) {
-                       free(gpkgcert[i]);
-                       gpkgcert[i] = NULL;
-               }
-       }
        return ret;
 }
 
 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
 {
-       if (!pkgid || !handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
+       char *manifest = NULL;
        manifest_x *mfx = NULL;
-       mfx = calloc(1, sizeof(manifest_x));
-       if (!mfx) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
+
+       manifest = pkgmgr_parser_get_manifest_file(pkgid);
+       retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
+
+       mfx = pkgmgr_parser_process_manifest_xml(manifest);
+       if (manifest) {
+               free(manifest);
+               manifest = NULL;
        }
-       mfx->package = strdup(pkgid);
+       retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
+
        *handle = (void *)mfx;
+
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
 {
-       if (!type || !handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        int len = strlen(type);
+       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (len > PKG_TYPE_STRING_LEN_MAX) {
-               _LOGE("pkg type length exceeds the max limit\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (mfx->type == NULL)
-               mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
-       else
-               mfx->type = type;
 
+       mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
 {
-       if (!version || !handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        int len = strlen(version);
+       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (len > PKG_VERSION_STRING_LEN_MAX) {
-               _LOGE("pkg version length exceeds the max limit\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (mfx->version == NULL)
-               mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
-       else
-               mfx->version = version;
 
+       mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (location < 0 || location > 1) {
-               _LOGE("Argument supplied is invalid\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (mfx->installlocation == NULL) {
-               mfx->installlocation = (char *)calloc(1, strlen("prefer-external") + 1);
-               if (mfx->installlocation == NULL) {
-                       _LOGE("Malloc Failed\n");
-                       return PMINFO_R_ERROR;
-               }
-       }
-       if (location == INSTALL_INTERNAL) {
+
+       if (location == INSTALL_INTERNAL)
                strcpy(mfx->installlocation, "internal-only");
-       } else if (location == INSTALL_EXTERNAL) {
+       else if (location == INSTALL_EXTERNAL)
                strcpy(mfx->installlocation, "prefer-external");
-       } else {
-               _LOGE("Invalid location type\n");
-               return PMINFO_R_ERROR;
-       }
+
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (size == NULL) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (mfx->installlocation == NULL) {
-               _LOGE("cant set size without specifying install location\n");
-               return PMINFO_R_ERROR;
-       }
-       if (strcmp(mfx->installlocation, "prefer-external") == 0) {
-               if (mfx->package_size == NULL)
-                       mfx->package_size = strdup(size);
-               else
-                       mfx->package_size = size;
-       } else {
-               _LOGE("cant set size for internal location\n");
-               return PMINFO_R_ERROR;
-       }
+
+       mfx->package_size = strdup(size);
+
        return PMINFO_R_OK;
 }
+
 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
 {
-       if (!handle || !label_txt) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        int len = strlen(label_txt);
+       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (len > PKG_VALUE_STRING_LEN_MAX) {
-               _LOGE("label length exceeds the max limit\n");
-               return PMINFO_R_EINVAL;
-       }
+
        label_x *label = calloc(1, sizeof(label_x));
-       if (label == NULL) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
+
        LISTADD(mfx->label, label);
        if (locale)
                mfx->label->lang = strdup(locale);
@@ -6847,21 +6547,17 @@ API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const c
 
 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
 {
-       if (!handle || !icon_txt) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        int len = strlen(icon_txt);
+       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (len > PKG_VALUE_STRING_LEN_MAX) {
-               _LOGE("icon length exceeds the max limit\n");
-               return PMINFO_R_EINVAL;
-       }
+
        icon_x *icon = calloc(1, sizeof(icon_x));
-       if (icon == NULL) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
+
        LISTADD(mfx->icon, icon);
        if (locale)
                mfx->icon->lang = strdup(locale);
@@ -6874,21 +6570,17 @@ API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const ch
 
 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
 {
-       if (!handle || !desc_txt) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        int len = strlen(desc_txt);
+       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (len > PKG_VALUE_STRING_LEN_MAX) {
-               _LOGE("description length exceeds the max limit\n");
-               return PMINFO_R_EINVAL;
-       }
+
        description_x *description = calloc(1, sizeof(description_x));
-       if (description == NULL) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
+
        LISTADD(mfx->description, description);
        if (locale)
                mfx->description->lang = strdup(locale);
@@ -6902,16 +6594,11 @@ API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, c
 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
                const char *author_email, const char *author_href, const char *locale)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
        manifest_x *mfx = (manifest_x *)handle;
        author_x *author = calloc(1, sizeof(author_x));
-       if (author == NULL) {
-               _LOGE("Malloc Failed\n");
-               return PMINFO_R_ERROR;
-       }
+       retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        LISTADD(mfx->author, author);
        if (author_name)
                mfx->author->text = strdup(author_name);
@@ -6928,93 +6615,58 @@ API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const
 
 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (removable < 0 || removable > 1) {
-               _LOGE("Argument supplied is invalid\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (mfx->removable == NULL) {
-               mfx->removable = (char *)calloc(1, strlen("false") + 1);
-               if (mfx->removable == NULL) {
-                       _LOGE("Malloc Failed\n");
-                       return PMINFO_R_ERROR;
-               }
-       }
-       if (removable == 0) {
+
+       if (removable == 0)
                strcpy(mfx->removable, "false");
-       } else if (removable == 1) {
+       else if (removable == 1)
                strcpy(mfx->removable, "true");
-       } else {
-               _LOGE("Invalid removable type\n");
-               return PMINFO_R_ERROR;
-       }
+
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (preload < 0 || preload > 1) {
-               _LOGE("Argument supplied is invalid\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        manifest_x *mfx = (manifest_x *)handle;
-       if (mfx->preload == NULL) {
-               mfx->preload = (char *)calloc(1, strlen("false") + 1);
-               if (mfx->preload == NULL) {
-                       _LOGE("Malloc Failed\n");
-                       return PMINFO_R_ERROR;
-               }
-       }
-       if (preload == 0) {
+
+       if (preload == 0)
                strcpy(mfx->preload, "false");
-       } else if (preload == 1) {
+       else if (preload == 1)
                strcpy(mfx->preload, "true");
-       } else {
-               _LOGE("Invalid preload type\n");
-               return PMINFO_R_ERROR;
-       }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
+{
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
+
+       manifest_x *mfx = (manifest_x *)handle;
+
+       if (location == INSTALL_INTERNAL)
+               strcpy(mfx->installed_storage, "installed_internal");
+       else if (location == INSTALL_EXTERNAL)
+               strcpy(mfx->installed_storage, "installed_external");
+
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        int ret = 0;
        manifest_x *mfx = NULL;
-       label_x *tmp1 = NULL;
-       icon_x *tmp2 = NULL;
-       description_x *tmp3 = NULL;
-       author_x *tmp4 = NULL;
        mfx = (manifest_x *)handle;
-       /*First move to head of all list pointers*/
-       if (mfx->label) {
-               LISTHEAD(mfx->label, tmp1);
-               mfx->label = tmp1;
-       }
-       if (mfx->icon) {
-               LISTHEAD(mfx->icon, tmp2);
-               mfx->icon = tmp2;
-       }
-       if (mfx->description) {
-               LISTHEAD(mfx->description, tmp3);
-               mfx->description= tmp3;
-       }
-       if (mfx->author) {
-               LISTHEAD(mfx->author, tmp4);
-               mfx->author = tmp4;
-       }
-       ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
+
+       ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
        if (ret == 0) {
                _LOGE("Successfully stored info in DB\n");
                return PMINFO_R_OK;
@@ -7026,10 +6678,8 @@ API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
 
 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
 {
-       if (!handle) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
        manifest_x *mfx = NULL;
        mfx = (manifest_x *)handle;
        pkgmgr_parser_free_manifest_xml(mfx);
@@ -7044,10 +6694,7 @@ API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
 
 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
 {
-       if (appid == NULL) {
-               _LOGE("appid is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
        int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
        ret = __open_manifest_db();
@@ -7101,23 +6748,10 @@ API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
 
 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
 {
-       if (providerid == NULL) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (type == NULL) {
-               _LOGE("Argument supplied is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (appid == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (access == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-
+       retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *error_message = NULL;
@@ -7159,10 +6793,7 @@ API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * typ
 
 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
 {
-       if (appid == NULL) {
-               _LOGE("appid is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
        int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *error_message = NULL;
@@ -7214,14 +6845,8 @@ API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *labe
 
 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
-       if (status == NULL) {
-               _LOGE("Argument supplied to hold return value is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
+       retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->guestmode_visibility;
@@ -7239,10 +6864,7 @@ API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
 
 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
 {
-       if (handle == NULL) {
-               _LOGE("appinfo handle is NULL\n");
-               return PMINFO_R_EINVAL;
-       }
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        char *val = NULL;
        int ret = 0;
        char *noti_string = NULL;