Fix compare and load certinfo by GLOBAL USER.
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgr-info.c
old mode 100755 (executable)
new mode 100644 (file)
index 4e03576..3a7c264
@@ -19,7 +19,8 @@
  * limitations under the License.
  *
  */
-
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <assert.h>
 #include <dlfcn.h>
+#include <sys/smack.h>
+#include <linux/limits.h>
+#include <libgen.h>
+#include <grp.h>
 
 #include <libxml/parser.h>
 #include <libxml/xmlreader.h>
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
+/* For multi-user support */
+#include <tzplatform_config.h>
+
 #include "pkgmgr_parser.h"
 #include "pkgmgr-info-internal.h"
 #include "pkgmgr-info-debug.h"
 #include "pkgmgr-info.h"
 #include "pkgmgr_parser_db.h"
+#include "pkgmgr_parser_internal.h"
 #include <dirent.h>
 #include <sys/stat.h>
 
 #define ASC_CHAR(s) (const char *)s
 #define XML_CHAR(s) (const xmlChar *)s
 
-#define MANIFEST_DB    "/opt/dbspace/.pkgmgr_parser.db"
+#define MANIFEST_DB    tzplatform_mkpath(TZ_SYS_DB, ".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 CERT_DB                tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
+#define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
 #define PKG_TYPE_STRING_LEN_MAX                128
 #define PKG_VERSION_STRING_LEN_MAX     128
 #define PKG_VALUE_STRING_LEN_MAX               512
 #define PKG_LOCALE_STRING_LEN_MAX              8
-#define PKG_RW_PATH "/opt/usr/apps/"
-#define PKG_RO_PATH "/usr/apps/"
+#define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
+#define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
 #define BLOCK_SIZE      4096 /*in bytes*/
+#define BUFSIZE 4096
+#define ROOT_UID 0
 
-#define MMC_PATH "/opt/storage/sdcard"
-#define PKG_SD_PATH MMC_PATH"/app2sd/"
-#define PKG_INSTALLATION_PATH "/opt/usr/apps/"
+#define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
+#define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
+#define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
 
 #define FILTER_QUERY_COUNT_PACKAGE     "select count(DISTINCT package_info.package) " \
                                "from package_info LEFT OUTER JOIN package_localized_info " \
 #define METADATA_FILTER_QUERY_UNION_CLAUSE     " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
 
 #define LANGUAGE_LENGTH 2
-#define LIBAIL_PATH "/usr/lib/libail.so.0"
 
 #define SERVICE_NAME "org.tizen.system.deviced"
 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
 #define METHOD_NAME "RequestMountApp2ext"
 
+
+
 typedef struct _pkgmgr_instcertinfo_x {
        char *pkgid;
        char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
@@ -128,6 +140,7 @@ typedef struct _pkgmgr_certindexinfo_x {
 } pkgmgr_certindexinfo_x;
 
 typedef struct _pkgmgr_pkginfo_x {
+       uid_t uid;
        manifest_x *manifest_info;
        char *locale;
 
@@ -169,6 +182,7 @@ typedef struct _pkgmgr_appinfo_x {
 } pkgmgr_appinfo_x;
 
 typedef struct _pkgmgr_certinfo_x {
+       int for_all_users;
        char *pkgid;
        char *cert_value;
        char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
@@ -177,6 +191,7 @@ typedef struct _pkgmgr_certinfo_x {
 
 /*For filter APIs*/
 typedef struct _pkgmgrinfo_filter_x {
+       uid_t uid;
        GSList *list;
 } pkgmgrinfo_filter_x;
 
@@ -197,6 +212,13 @@ typedef struct _pkgmgrinfo_appcontrol_x {
        char **subapp;
 } pkgmgrinfo_appcontrol_x;
 
+
+typedef struct _db_handle {
+       sqlite3 *dbHandle;
+       int ref;
+} db_handle;
+
+
 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
 
 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
@@ -235,12 +257,35 @@ typedef enum {
 #define MAX_PKG_BUF_LEN                1024
 #define MAX_PKG_INFO_LEN       10
 
+#define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
+                                               "(cert_info text not null, " \
+                                               "cert_id integer, " \
+                                               "cert_ref_count integer, " \
+                                               "PRIMARY KEY(cert_id)) "
+
+#define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
+                                               "(package text not null, " \
+                                               "author_root_cert integer, " \
+                                               "author_im_cert integer, " \
+                                               "author_signer_cert integer, " \
+                                               "dist_root_cert integer, " \
+                                               "dist_im_cert integer, " \
+                                               "dist_signer_cert integer, " \
+                                               "dist2_root_cert integer, " \
+                                               "dist2_im_cert integer, " \
+                                               "dist2_signer_cert integer, " \
+                                               "PRIMARY KEY(package)) "
+
+#define GET_DB(X)  (X).dbHandle
 char *pkgtype = "rpm";
-__thread sqlite3 *manifest_db = NULL;
-__thread sqlite3 *datacontrol_db = NULL;
-__thread sqlite3 *cert_db = NULL;
-
-static int __open_manifest_db();
+__thread db_handle manifest_db;
+__thread db_handle datacontrol_db;
+__thread db_handle cert_db;
+
+static int __open_manifest_db(uid_t uid);
+static int __close_manifest_db(void);
+static int __open_cert_db(uid_t uid, char* mode);
+static int __close_cert_db(void);
 static int __exec_pkginfo_query(char *query, void *data);
 static int __exec_certinfo_query(char *query, void *data);
 static int __exec_certindexinfo_query(char *query, void *data);
@@ -262,7 +307,238 @@ 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 int __delete_certinfo(const char *pkgid, uid_t uid);
+static int _check_create_Cert_db( sqlite3 *certdb);
+static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
+
+static int _mkdir_for_user(const char* dir, uid_t uid, gid_t gid)
+{
+       int ret;
+       char *fullpath;
+       char *subpath;
+
+       fullpath = strdup(dir);
+       subpath = dirname(fullpath);
+       if (strlen(subpath) > 1 && strcmp(subpath, fullpath) != 0) {
+               ret = _mkdir_for_user(fullpath, uid, gid);
+               if (ret == -1) {
+                       free(fullpath);
+                       return ret;
+               }
+       }
+
+       ret = mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+       if (ret && errno != EEXIST) {
+               free(fullpath);
+               return ret;
+       } else if (ret && errno == EEXIST) {
+               free(fullpath);
+               return 0;
+       }
+
+       if (getuid() == ROOT_UID) {
+               ret = chown(dir, uid, gid);
+               if (ret == -1)
+                       _LOGE("FAIL : chown %s %d.%d, because %s", dir, uid,
+                                       gid, strerror(errno));
+       }
+
+       free(fullpath);
+
+       return 0;
+}
+
+static const char *_get_db_path(uid_t uid) {
+       const char *db_path = NULL;
+       if (uid != GLOBAL_USER && uid != ROOT_UID) {
+               tzplatform_set_user(uid);
+               db_path = tzplatform_getenv(TZ_USER_DB);
+               tzplatform_reset_user();
+       } else {
+               db_path = tzplatform_getenv(TZ_SYS_DB);
+       }
+       return db_path;
+}
+
+static int __attach_and_create_view(sqlite3 *handle, const char *db, const char *tables[], uid_t uid)
+{
+       int i;
+       char *err;
+       char query[MAX_QUERY_LEN];
+
+       if (uid == GLOBAL_USER || uid == ROOT_UID)
+               return SQLITE_OK;
+
+       snprintf(query, sizeof(query), "ATTACH DATABASE '%s' AS Global", db);
+       if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
+               _LOGD("Don't execute query = %s error message = %s\n", query, err);
+               sqlite3_free(err);
+               return SQLITE_ERROR;
+       }
+
+       for (i = 0; tables[i]; i++) {
+               snprintf(query, sizeof(query), "CREATE TEMP VIEW '%s' AS SELECT * \
+                               FROM (SELECT *,0 AS for_all_users FROM  main.'%s' UNION \
+                               SELECT *,1 AS for_all_users FROM Global.'%s')",
+                               tables[i], tables[i], tables[i]);
+               if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
+                       _LOGD("Don't execute query = %s error message = %s\n", query, err);
+                       sqlite3_free(err);
+               }
+       }
+
+       return SQLITE_OK;
+}
+
+static int _check_create_Cert_db( sqlite3 *certdb)
+{
+       int ret = 0;
+       ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
+       if(ret < 0)
+               return ret;
+       ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
+       return ret;
+}
+
+static gid_t _get_gid(const char *name)
+{
+       char buf[BUFSIZE];
+       struct group entry;
+       struct group *ge;
+       int ret;
+
+       ret = getgrnam_r(name, &entry, buf, sizeof(buf), &ge);
+       if (ret || ge == NULL) {
+               _LOGE("fail to get gid of %s", name);
+               return -1;
+       }
+
+       return entry.gr_gid;
+}
+
+API char *getIconPath(uid_t uid)
+{
+       const char *path = NULL;
+       uid_t uid_caller = getuid();
+       gid_t gid = ROOT_UID;
+
+       if (uid != GLOBAL_USER && uid != ROOT_UID) {
+               tzplatform_set_user(uid);
+               path = tzplatform_mkpath(TZ_USER_ICONS, "/");
+               gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
+               tzplatform_reset_user();
+       } else {
+               path = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
+       }
+
+       // just allow certain users to create the icon directory if needed.
+       if (uid_caller == ROOT_UID || uid_caller == uid)
+               _mkdir_for_user(path, uid, gid);
+
+       return path;
+}
+
+API char *getUserPkgParserDBPath(void)
+{
+       return getUserPkgParserDBPathUID(GLOBAL_USER);
+}
+
+API char *getUserPkgParserDBPathUID(uid_t uid)
+{
+       const char *pkgmgr_parser_db = NULL;
+       uid_t uid_caller = getuid();
+       gid_t gid = ROOT_UID;
+
+       if (uid != GLOBAL_USER && uid != ROOT_UID) {
+               tzplatform_set_user(uid);
+               pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
+               gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
+               tzplatform_reset_user();
+       } else {
+               pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
+       }
+
+       // just allow certain users to create the dbspace directory if needed.
+       if (uid_caller == ROOT_UID || uid_caller == uid) {
+               const char *db_path = _get_db_path(uid);
+               _mkdir_for_user(db_path, uid, gid);
+       }
+
+       return pkgmgr_parser_db;
+}
+
+API char *getUserPkgCertDBPath(void)
+{
+        return getUserPkgCertDBPathUID(GLOBAL_USER);
+}
+
+API char *getUserPkgCertDBPathUID(uid_t uid)
+{
+       const char *pkgmgr_cert_db = NULL;
+       uid_t uid_caller = getuid();
+       gid_t gid = ROOT_UID;
+
+       if (uid != GLOBAL_USER && uid != ROOT_UID) {
+               tzplatform_set_user(uid);
+               pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db");
+               gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
+               tzplatform_reset_user();
+       } else {
+               pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
+       }
+
+       // just allow certain users to create the dbspace directory if needed.
+       if (uid_caller == ROOT_UID || uid_caller == uid) {
+               const char *db_path = _get_db_path(uid);
+               _mkdir_for_user(db_path, uid, gid);
+       }
+
+       return pkgmgr_cert_db;
+}
+
+API const char* getUserDesktopPath(uid_t uid)
+{
+       const char *path = NULL;
+       uid_t uid_caller = getuid();
+       gid_t gid = ROOT_UID;
+
+       if (uid != GLOBAL_USER && uid != ROOT_UID) {
+               tzplatform_set_user(uid);
+               path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
+               gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
+               tzplatform_reset_user();
+       } else {
+               path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
+       }
+
+       // just allow certain users to create the icon directory if needed.
+       if (uid_caller == ROOT_UID || uid_caller == uid)
+               _mkdir_for_user(path, uid, gid);
+
+       return path;
+}
+
+API const char* getUserManifestPath(uid_t uid)
+{
+       const char *path = NULL;
+       uid_t uid_caller = getuid();
+       gid_t gid = ROOT_UID;
+
+       if (uid != GLOBAL_USER && uid != ROOT_UID) {
+               tzplatform_set_user(uid);
+               path = tzplatform_mkpath(TZ_USER_PACKAGES, "/");
+               gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
+               tzplatform_reset_user();
+       } else {
+               path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
+       }
+
+       // just allow certain users to create the icon directory if needed.
+       if (uid_caller == ROOT_UID || uid_caller == uid)
+               _mkdir_for_user(path, uid, gid);
+
+       return path;
+}
 
 static gint __compare_func(gconstpointer data1, gconstpointer data2)
 {
@@ -486,28 +762,131 @@ static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
        return;
 }
 
-static int __open_manifest_db()
+static int __close_manifest_db(void)
+{
+       if(manifest_db.ref) {
+               if(--manifest_db.ref == 0)
+                       sqlite3_close(GET_DB(manifest_db));
+               return 0;
+       }
+       return -1;
+}
+
+static const char *parserdb_tables[] = {
+       "package_app_app_category",
+       "package_app_info",
+       "package_app_app_control",
+       "package_app_localized_info",
+       "package_app_app_metadata",
+       "package_app_share_allowed",
+       "package_app_app_permission",
+       "package_app_share_request",
+       "package_app_app_svc",
+       "package_info",
+       "package_app_data_control",
+       "package_localized_info",
+       "package_app_icon_section_info",
+       "package_privilege_info",
+       "package_app_image_info",
+       NULL
+};
+
+static int __open_manifest_db(uid_t uid)
 {
        int ret = -1;
-       if (access(MANIFEST_DB, F_OK) == 0) {
-               ret =
-                   db_util_open_with_options(MANIFEST_DB, &manifest_db,
-                                SQLITE_OPEN_READONLY, NULL);
-               retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
+       if(manifest_db.ref) {
+               manifest_db.ref ++;
+               return 0;
+       }
+       const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
+       if (access(user_pkg_parser, F_OK) != 0) {
+               _LOGE("Manifest DB does not exists !! try to create\n");
+
+               if (pkgmgr_parser_check_and_create_db(uid)) {
+                       _LOGE("create db failed");
+                       return -1;
+               }
+
+               if (pkgmgr_parser_initialize_db()) {
+                       _LOGE("initialize db failed");
+                       return -1;
+               }
+       }
+
+       ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
+                       SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
+       manifest_db.ref ++;
+       ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB, parserdb_tables, uid);
+       retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
+
+       return 0;
+}
+
+static int __close_cert_db(void)
+{
+       if(cert_db.ref) {
+               if(--cert_db.ref == 0)
+                       sqlite3_close(GET_DB(cert_db));
+                       return 0;
+       }
+       _LOGE("Certificate DB is already closed !!\n");
+       return -1;
+}
+
+static const char *certdb_tables[] = {
+       "package_cert_index_info",
+       "package_cert_info",
+       NULL
+};
+
+static int __open_cert_db(uid_t uid, char* mode)
+{
+       int ret = -1;
+       if(cert_db.ref) {
+               cert_db.ref ++;
+               return 0;
+       }
+
+       const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
+       if (access(user_cert_parser, F_OK) == 0) {
+               ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
+                                SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+               retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
+               cert_db.ref ++;
+               if ((strcmp(mode, "w") != 0)) {
+                       ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB, certdb_tables, uid);
+                       retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
+               }
                return 0;
        }
-       _LOGE("Manifest DB does not exists !!\n");
+       _LOGE("Cert DB does not exists !!\n");
+       return -1;
+}
+
+static int __close_datacontrol_db(void)
+{
+       if(datacontrol_db.ref) {
+               if(--datacontrol_db.ref == 0)
+                       sqlite3_close(GET_DB(datacontrol_db));
+                       return 0;
+       }
+       _LOGE("Certificate DB is already closed !!\n");
        return -1;
 }
 
 static int __open_datacontrol_db()
 {
        int ret = -1;
+       if(datacontrol_db.ref) {
+               datacontrol_db.ref ++;
+               return 0;
+       }
        if (access(DATACONTROL_DB, F_OK) == 0) {
-               ret =
-                   db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
+               ret = db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
                                 SQLITE_OPEN_READONLY, NULL);
                retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
+               datacontrol_db.ref ++;
                return 0;
        }
        _LOGE("Datacontrol DB does not exists !!\n");
@@ -523,6 +902,7 @@ static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
        info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
 
        LISTADD(udata, info);
+
        for(i = 0; i < ncols; i++)
        {
                if (strcmp(colname[i], "package") == 0) {
@@ -530,9 +910,19 @@ static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->package = strdup(coltxt[i]);
                        else
                                info->manifest_info->package = NULL;
+               } else if (strcmp(colname[i], "for_all_users") == 0) {
+                       if (coltxt[i])
+                               info->manifest_info->for_all_users = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->for_all_users = NULL;      
                } else
                        continue;
        }
+       
+       //by default if views are not set , the column for_all_users doesn't exist,
+       // in this case we assume we retreive information about app avaible for all users
+       if (!info->manifest_info->for_all_users)
+               info->manifest_info->for_all_users = strdup("1");
 
        return 0;
 }
@@ -738,6 +1128,11 @@ static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
                        else
                                info->manifest_info->uiapplication->submode_mainid = NULL;
+               } else if (strcmp(colname, "app_launch_mode") == 0 ) {
+                       if (coltxt[i])
+                               info->manifest_info->uiapplication->launch_mode = strdup(coltxt[i]);
+                       else
+                               info->manifest_info->uiapplication->launch_mode = NULL;
                } else
                        continue;
        }
@@ -1287,6 +1682,11 @@ static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                info->cert_value = strdup(coltxt[i]);
                        else
                                info->cert_value = NULL;
+               } else if (strcmp(colname[i], "for_all_users") == 0 ){
+                       if (coltxt[i])
+                               info->for_all_users = atoi(coltxt[i]);
+                       else
+                               info->for_all_users = 0;
                } else
                        continue;
        }
@@ -1421,6 +1821,11 @@ static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colnam
                                                                info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
                                                        else
                                                                info->manifest_info->uiapplication->submode_mainid = NULL;
+                                               } else if (strcmp(colname[j], "app_launch_mode") == 0 ) {
+                                                       if (coltxt[j])
+                                                               info->manifest_info->uiapplication->launch_mode = strdup(coltxt[j]);
+                                                       else
+                                                               info->manifest_info->uiapplication->launch_mode = NULL;
                                                } else
                                                        continue;
                                        }
@@ -1478,6 +1883,34 @@ static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colnam
        return 0;
 }
 
+static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
+{
+       char *dup;
+       char *token;
+       char *ptr;
+       appcontrol_x *ac;
+
+       if (appcontrol_str == NULL)
+               return;
+
+       dup = strdup(appcontrol_str);
+       do {
+               ac = calloc(1, sizeof(appcontrol_x));
+               token = strtok_r(dup, "|", &ptr);
+               if (strcmp(token, "NULL"))
+                       ac->operation = strdup(token);
+               token = strtok_r(NULL, "|", &ptr);
+               if (strcmp(token, "NULL"))
+                       ac->uri = strdup(token);
+               token = strtok_r(NULL, "|", &ptr);
+               if (strcmp(token, "NULL"))
+                       ac->mime = strdup(token);
+               LISTADD(*appcontrol, ac);
+       } while (token = strtok_r(NULL, ";", &ptr));
+
+       free(dup);
+}
+
 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
 {
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
@@ -1488,6 +1921,7 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
        metadata_x *metadata = NULL;
        permission_x *permission = NULL;
        image_x *image = NULL;
+       appcontrol_x *appcontrol = NULL;
 
        switch (info->app_component) {
        case PMINFO_UI_APP:
@@ -1670,6 +2104,13 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                        info->uiapp_info->submode_mainid = strdup(coltxt[i]);
                                else
                                        info->uiapp_info->submode_mainid = NULL;
+                       } else if (strcmp(colname[i], "app_launch_mode") == 0 ) {
+                               if (coltxt[i])
+                                       info->uiapp_info->launch_mode = strdup(coltxt[i]);
+                               else
+                                       info->uiapp_info->launch_mode = NULL;
+                       } else if (strcmp(colname[i], "app_control") == 0 ) {
+                               __parse_appcontrol(&info->uiapp_info->appcontrol, coltxt[i]);
                        } else
                                continue;
                }
@@ -1771,6 +2212,8 @@ static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
                                        info->svcapp_info->permission_type = strdup(coltxt[i]);
                                else
                                        info->svcapp_info->permission_type = NULL;
+                       } else if (strcmp(colname[i], "app_control") == 0 ) {
+                               __parse_appcontrol(&info->svcapp_info->appcontrol, coltxt[i]);
                        } else
                                continue;
                }
@@ -1861,7 +2304,7 @@ static int __exec_pkginfo_query(char *query, void *data)
 {
        char *error_message = NULL;
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
@@ -1875,7 +2318,7 @@ static int __exec_certinfo_query(char *query, void *data)
 {
        char *error_message = NULL;
        if (SQLITE_OK !=
-           sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
+           sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
@@ -1889,7 +2332,7 @@ static int __exec_certindexinfo_query(char *query, void *data)
 {
        char *error_message = NULL;
        if (SQLITE_OK !=
-           sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
+           sqlite3_exec(GET_DB(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);
@@ -1902,10 +2345,10 @@ static int __exec_certindexinfo_query(char *query, void *data)
 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
 {
        char *error_message = NULL;
-       if (SQLITE_OK !=
-           sqlite3_exec(db, query, callback, data, &error_message)) {
-               _LOGE("Don't execute query = %s error message = %s\n", query,
-                      error_message);
+       int ret = sqlite3_exec(db, query, callback, data, &error_message);
+       if (SQLITE_OK != ret) {
+               _LOGE("Don't execute query = %s error message = %s   ret = %d\n", query,
+                      error_message, ret);
                sqlite3_free(error_message);
                return -1;
        }
@@ -2112,7 +2555,7 @@ long long _pkgmgr_calculate_dir_size(char *dirname)
 
 }
 
-static int __delete_certinfo(const char *pkgid)
+static int __delete_certinfo(const char *pkgid, uid_t uid)
 {
        int ret = -1;
        int i = 0;
@@ -2131,6 +2574,8 @@ static int __delete_certinfo(const char *pkgid)
                ret = PMINFO_R_ERROR;
                goto err;
        }
+
+       __open_cert_db(uid, "w");
        /*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);
@@ -2170,7 +2615,7 @@ static int __delete_certinfo(const char *pkgid)
                                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)) {
+                           sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
                                _LOGE("Don't execute query = %s error message = %s\n", query,
                                       error_message);
                                sqlite3_free(error_message);
@@ -2182,7 +2627,7 @@ static int __delete_certinfo(const char *pkgid)
        /*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)) {
+            sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
                 _LOGE("Don't execute query = %s error message = %s\n", query,
                        error_message);
                sqlite3_free(error_message);
@@ -2205,6 +2650,7 @@ err:
                        (certinfo->cert_info)[i] = NULL;
                }
        }
+       __close_cert_db();
        free(certinfo);
        certinfo = NULL;
        return ret;
@@ -2229,11 +2675,13 @@ static int __get_pkg_location(const char *pkgid)
        return PMINFO_INTERNAL_STORAGE;
 }
 
-API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
+API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
 {
        retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
        char *error_message = NULL;
        int ret = PMINFO_R_OK;
+       int ret_db = 0;
+
        char query[MAX_QUERY_LEN] = {'\0'};
        char *syslocale = NULL;
        char *locale = NULL;
@@ -2247,21 +2695,21 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
        if (syslocale == NULL) {
                _LOGE("current locale is NULL\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
+               return PMINFO_R_ERROR;
        }
        locale = __convert_system_locale_to_manifest_locale(syslocale);
        if (locale == NULL) {
                _LOGE("manifest locale is NULL\n");
-               ret = PMINFO_R_EINVAL;
-               goto err;
+               free(syslocale);
+               return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
-       if (ret == -1) {
+       ret_db = __open_manifest_db(uid);
+       if (ret_db == -1) {
                _LOGE("Fail to open manifest DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
+               free(syslocale);
+               free(locale);
+               return PMINFO_R_ERROR;
        }
        pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
        pkgmgr_pkginfo_x *node = NULL;
@@ -2269,11 +2717,10 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
 
        snprintf(query, MAX_QUERY_LEN, "select * from package_info");
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
-               sqlite3_close(manifest_db);
                ret = PMINFO_R_ERROR;
                goto err;
        }
@@ -2351,6 +2798,7 @@ 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->uid = uid;
                ret = pkg_list_cb( (void *)pkginfo, user_data);
                if(ret < 0)
                        break;
@@ -2359,7 +2807,7 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
        ret = PMINFO_R_OK;
 
 err:
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        if (syslocale) {
                free(syslocale);
                syslocale = NULL;
@@ -2380,8 +2828,12 @@ err:
        return ret;
 }
 
+API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
+{
+       return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
+}
 
-API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
+API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
 {
        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");
@@ -2396,15 +2848,18 @@ API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *
        description_x *tmp3 = NULL;
        author_x *tmp4 = NULL;
        privilege_x *tmp5 = NULL;
-       sqlite3 *pkginfo_db = NULL;
+       const char* user_pkg_parser = NULL;
+
+       *handle = NULL;
 
        /*validate pkgid*/
-       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);
+       user_pkg_parser = getUserPkgParserDBPathUID(uid);
+       ret = __open_manifest_db(uid);
+         retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
 
        /*check pkgid exist on db*/
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
-       ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
+       ret = __exec_db_query(GET_DB(manifest_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);
 
@@ -2430,26 +2885,26 @@ API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *
 
        /*populate manifest_info from DB*/
        snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
-       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       ret = __exec_db_query(GET_DB(manifest_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);
+       ret = __exec_db_query(GET_DB(manifest_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_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       ret = __exec_db_query(GET_DB(manifest_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_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       ret = __exec_db_query(GET_DB(manifest_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) {
@@ -2480,8 +2935,7 @@ catch:
                *handle = NULL;
                __cleanup_pkginfo(pkginfo);
        }
-       sqlite3_close(pkginfo_db);
-
+       __close_manifest_db();
        if (syslocale) {
                free(syslocale);
                syslocale = NULL;
@@ -2493,6 +2947,10 @@ catch:
        return ret;
 }
 
+API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
+{
+       return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
+}
 
 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
 {
@@ -2564,9 +3022,7 @@ API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *si
        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;
        val = (char *)info->manifest_info->package_size;
        if (val) {
                *size = atoi(val);
@@ -3076,7 +3532,7 @@ API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **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)
+API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, uid_t uid, pkgmgrinfo_cert_compare_result_type_e *compare_result)
 {
        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");
@@ -3085,68 +3541,85 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *error_message = NULL;
-       pkgmgr_cert_x *info= NULL;
+       sqlite3_stmt *stmt = NULL;
+       char *lhs_certinfo = NULL;
+       char *rhs_certinfo = NULL;
        int lcert = 0;
        int rcert = 0;
        int exist = -1;
+       int i;
+       int is_global = 0;
        *compare_result = PMINFO_CERT_COMPARE_ERROR;
-       info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
-       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);
+       ret = __open_cert_db(uid, "r");
+       if (ret != 0) {
                ret = PMINFO_R_ERROR;
                goto err;
        }
-
+       _check_create_Cert_db(GET_DB(cert_db));
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
        if (SQLITE_OK !=
-           sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
+           sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                ret = PMINFO_R_ERROR;
                goto err;
        }
-
-       if (exist == 0) {
-               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 !=
-                       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->cert_id;
-       }
+       lcert = exist;
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
        if (SQLITE_OK !=
-               sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
+               sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                           error_message);
                ret = PMINFO_R_ERROR;
                goto err;
        }
+       rcert = exist;
 
-       if (exist == 0) {
-               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 !=
-                       sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
-                       _LOGE("Don't execute query = %s error message = %s\n", query,
-                                  error_message);
+       if (uid == GLOBAL_USER || uid == ROOT_UID) {
+               snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=(select author_signer_cert from package_cert_info where package=?)");
+               is_global = 1;
+       } else
+               snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=(select author_signer_cert from package_cert_info where package=?) and for_all_users=(select for_all_users from package_cert_info where package=?)");
+       if (SQLITE_OK != sqlite3_prepare_v2(GET_DB(cert_db), query, strlen(query), &stmt, NULL)) {
+               _LOGE("sqlite3_prepare_v2 error: %s", sqlite3_errmsg(GET_DB(cert_db)));
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+
+       for (i = 1; i <= 2 - is_global; i++) {
+               if (SQLITE_OK != sqlite3_bind_text(stmt, i, lhs_package_id, -1, SQLITE_STATIC)) {
+                       _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+       }
+       if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
+               _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+
+       lhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
+       sqlite3_reset(stmt);
+       sqlite3_clear_bindings(stmt);
+
+       for (i = 1; i <= 2 - is_global; i++) {
+               if (SQLITE_OK != sqlite3_bind_text(stmt, i, rhs_package_id, -1, SQLITE_STATIC)) {
+                       _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
-               rcert = info->cert_id;
+       }
+       if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
+               _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
 
+       rhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
+
        if ((lcert == 0) || (rcert == 0))
        {
                if ((lcert == 0) && (rcert == 0))
@@ -3156,26 +3629,29 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
                else if (rcert == 0)
                        *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
        } else {
-               if (lcert == rcert)
+               if (!strcmp(lhs_certinfo, rhs_certinfo))
                        *compare_result = PMINFO_CERT_COMPARE_MATCH;
                else
                        *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
        }
 
 err:
+       if (stmt)
+               sqlite3_finalize(stmt);
+       if (lhs_certinfo)
+               free(lhs_certinfo);
+       if (rhs_certinfo)
+               free(rhs_certinfo);
        sqlite3_free(error_message);
-       sqlite3_close(cert_db);
-       if (info) {
-               if (info->pkgid) {
-                       free(info->pkgid);
-                       info->pkgid = NULL;
-               }
-               free(info);
-               info = NULL;
-       }
+       __close_cert_db();
+
        return ret;
 }
 
+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)
+{
+       return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
+}
 
 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)
 {
@@ -3190,21 +3666,22 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        int exist = -1;
        char *lpkgid = NULL;
        char *rpkgid = NULL;
+       const char* user_pkg_parser = getUserPkgParserDBPath();
 
        info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
        retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
 
-       ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
+       ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
                                        SQLITE_OPEN_READONLY, NULL);
        if (ret != SQLITE_OK) {
-               _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
+               _LOGE("connect db [%s] failed!\n", user_pkg_parser);
                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);
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                ret = PMINFO_R_ERROR;
@@ -3216,7 +3693,7 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        } else {
                snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
                if (SQLITE_OK !=
-                       sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
+                       sqlite3_exec(GET_DB(manifest_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;
@@ -3234,7 +3711,7 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
 
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                ret = PMINFO_R_ERROR;
@@ -3246,7 +3723,7 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        } else {
                snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
                if (SQLITE_OK !=
-                       sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
+                       sqlite3_exec(GET_DB(manifest_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;
@@ -3264,7 +3741,7 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
  err:
        sqlite3_free(error_message);
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        if (info) {
                if (info->pkgid) {
                        free(info->pkgid);
@@ -3284,24 +3761,130 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        return ret;
 }
 
-API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
+API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, uid_t uid, pkgmgrinfo_cert_compare_result_type_e *compare_result)
 {
-       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");
-                return PMINFO_R_ERROR;
-       }
-        _LOGD("pkgmgr_get_pkg_external_validation() called\n");
+       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");
 
-       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, };
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char *error_message = NULL;
+       pkgmgr_cert_x *info= NULL;
+       int exist = -1;
+       char *lpkgid = NULL;
+       char *rpkgid = NULL;
+
+       info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
+       retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
+
+       ret = __open_manifest_db(uid);
+       if (ret != SQLITE_OK) {
+               _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
+               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);
+       if (SQLITE_OK !=
+           sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+
+       if (exist == 0) {
+               lpkgid = NULL;
+       } else {
+               snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
+               if (SQLITE_OK !=
+                       sqlite3_exec(GET_DB(manifest_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;
+               }
+               lpkgid = strdup(info->pkgid);
+               if (lpkgid == NULL) {
+                       _LOGE("Out of Memory\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               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);
+       if (SQLITE_OK !=
+           sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+
+       if (exist == 0) {
+               rpkgid = NULL;
+       } else {
+               snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
+               if (SQLITE_OK !=
+                       sqlite3_exec(GET_DB(manifest_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;
+               }
+               rpkgid = strdup(info->pkgid);
+               if (rpkgid == NULL) {
+                       _LOGE("Out of Memory\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               free(info->pkgid);
+               info->pkgid = NULL;
+       }
+       ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
+ err:
+       sqlite3_free(error_message);
+       __close_manifest_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)
+{
+       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");
+                return PMINFO_R_ERROR;
+       }
+        _LOGD("pkgmgr_get_pkg_external_validation() called\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);
@@ -3462,6 +4045,26 @@ API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(for_all_users == 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->for_all_users;
+       if (val) {
+               if (strcasecmp(val, "1") == 0)
+                       *for_all_users = 1;
+               else if (strcasecmp(val, "0") == 0)
+                       *for_all_users = 0;
+               else
+                       *for_all_users = 1;
+       }
+       return PMINFO_R_OK;
+}
+
+
 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -3630,7 +4233,7 @@ 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)
+API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
 {
        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");
@@ -3644,6 +4247,7 @@ API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int
        int ret = 0;
 
        pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+       filter->uid = uid;
        /*Get current locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
        if (syslocale == NULL) {
@@ -3657,11 +4261,12 @@ API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(uid);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
+               free(syslocale);
+               free(locale);
+               return PMINFO_R_ERROR;
        }
 
        /*Start constructing query*/
@@ -3681,20 +4286,17 @@ API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int
                        where[sizeof(where) - 1] = '\0';
                }
        }
-       _LOGE("where = %s\n", where);
        if (strlen(where) > 0) {
                strncat(query, where, sizeof(query) - strlen(query) - 1);
                query[sizeof(query) - 1] = '\0';
        }
-       _LOGE("query = %s\n", query);
 
        /*Execute Query*/
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
-               sqlite3_close(manifest_db);
                ret = PMINFO_R_ERROR;
                *count = 0;
                goto err;
@@ -3709,12 +4311,17 @@ err:
                free(syslocale);
                syslocale = NULL;
        }
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        return ret;
 }
 
-API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
-                               pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
+API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
+{
+       return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
+}
+
+API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
+                               pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
 {
        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");
@@ -3749,11 +4356,12 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(uid);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
+               free(syslocale);
+               free(locale);
+               return PMINFO_R_ERROR;
        }
        /*Start constructing query*/
        snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
@@ -3772,12 +4380,10 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
                        where[sizeof(where) - 1] = '\0';
                }
        }
-       _LOGE("where = %s\n", where);
        if (strlen(where) > 0) {
                strncat(query, where, sizeof(query) - strlen(query) - 1);
                query[sizeof(query) - 1] = '\0';
        }
-       _LOGE("query = %s\n", query);
        tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
        if (tmphead == NULL) {
                _LOGE("Out of Memory!!!\n");
@@ -3785,12 +4391,12 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
                goto err;
        }
 
+       tmphead->uid = uid;
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
-               sqlite3_close(manifest_db);
                ret = PMINFO_R_ERROR;
                goto err;
        }
@@ -3859,6 +4465,7 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
 
        for(node = node->next ; node ; node = node->next) {
                pkginfo = node;
+               pkginfo->uid = uid;
                ret = pkg_cb( (void *)pkginfo, user_data);
                if(ret < 0)
                        break;
@@ -3874,11 +4481,17 @@ err:
                free(syslocale);
                syslocale = NULL;
        }
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        __cleanup_pkginfo(tmphead);
        return ret;
 }
 
+API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
+                               pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
+{
+       return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
+}
+
 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
                        pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
 {
@@ -3898,8 +4511,8 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
        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)
+API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
+                                               pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
        retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
@@ -3918,7 +4531,8 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
        metadata_x *ptr4 = NULL;
        permission_x *ptr5 = NULL;
        image_x *ptr6 = NULL;
-       sqlite3 *appinfo_db = NULL;
+       appcontrol_x *ptr7 = NULL;
+       const char* user_pkg_parser = NULL;
 
        /*get system locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
@@ -3949,8 +4563,9 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                appinfo->app_component = PMINFO_ALL_APP;
 
        /*open db */
-       ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
-       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+       user_pkg_parser = getUserPkgParserDBPathUID(uid);
+       ret = __open_manifest_db(uid);
+       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
 
        appinfo->package = strdup(info->manifest_info->package);
        snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
@@ -3962,7 +4577,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
        switch(component) {
        case PMINFO_UI_APP:
                /*Populate ui app info */
-               ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
 
                uiapplication_x *tmp = NULL;
@@ -3980,31 +4595,37 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                if (locale) {
                                        free(locale);
                                }
-                               locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
+                               locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
                        }
 
                        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);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                        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, DEFAULT_LOCALE);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                        /*store setting notification icon section*/
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
                        
                        /*store app preview image info*/
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
 
+                       /*store app control info*/
+                       snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
+                       memset(query, '\0', MAX_QUERY_LEN);
                        if (appinfo->uiapp_info->label) {
                                LISTHEAD(appinfo->uiapp_info->label, ptr2);
                                appinfo->uiapp_info->label = ptr2;
@@ -4029,6 +4650,10 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->uiapp_info->image, ptr6);
                                appinfo->uiapp_info->image = ptr6;
                        }
+                       if (appinfo->uiapp_info->appcontrol) {
+                               LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
+                               appinfo->uiapp_info->appcontrol = ptr7;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4037,7 +4662,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                break;
        case PMINFO_SVC_APP:
                /*Populate svc app info */
-               ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
 
                serviceapplication_x *tmp1 = NULL;
@@ -4053,14 +4678,18 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                        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);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                        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, DEFAULT_LOCALE);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
+                       snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
                        if (appinfo->svcapp_info->label) {
                                LISTHEAD(appinfo->svcapp_info->label, ptr2);
                                appinfo->svcapp_info->label = ptr2;
@@ -4081,6 +4710,10 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->svcapp_info->permission, ptr5);
                                appinfo->svcapp_info->permission = ptr5;
                        }
+                       if (appinfo->svcapp_info->appcontrol) {
+                               LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
+                               appinfo->svcapp_info->appcontrol = ptr7;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4092,7 +4725,7 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
 
                /*Populate all app info */
-               ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
 
                /*UI Apps*/
@@ -4110,26 +4743,31 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                        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);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                        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, DEFAULT_LOCALE);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                        /*store setting notification icon section*/
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
                        
                        /*store app preview image info*/
                        memset(query, '\0', MAX_QUERY_LEN);
                        snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
 
+                       /*store app control info*/
+                       snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
                        if (appinfo->uiapp_info->label) {
                                LISTHEAD(appinfo->uiapp_info->label, ptr2);
                                appinfo->uiapp_info->label = ptr2;
@@ -4154,6 +4792,10 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->uiapp_info->image, ptr6);
                                appinfo->uiapp_info->image = ptr6;
                        }
+                       if (appinfo->uiapp_info->appcontrol) {
+                               LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
+                               appinfo->uiapp_info->appcontrol = ptr7;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4175,14 +4817,18 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                        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);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                        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, DEFAULT_LOCALE);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
+                       snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
+                       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
                        if (appinfo->svcapp_info->label) {
                                LISTHEAD(appinfo->svcapp_info->label, ptr2);
                                appinfo->svcapp_info->label = ptr2;
@@ -4203,6 +4849,10 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                                LISTHEAD(appinfo->svcapp_info->permission, ptr5);
                                appinfo->svcapp_info->permission = ptr5;
                        }
+                       if (appinfo->svcapp_info->appcontrol) {
+                               LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
+                               appinfo->svcapp_info->appcontrol = ptr7;
+                       }
                        ret = app_func((void *)appinfo, user_data);
                        if (ret < 0)
                                break;
@@ -4233,11 +4883,17 @@ catch:
        }
        __cleanup_pkginfo(allinfo);
 
-       sqlite3_close(appinfo_db);
+       __close_manifest_db();
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
+                                               pkgmgrinfo_app_list_cb app_func, void *user_data)
+{
+       return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
+}
+
+API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
 {
        retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
 
@@ -4246,11 +4902,12 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, voi
        pkgmgr_appinfo_x *appinfo = NULL;
        uiapplication_x *ptr1 = NULL;
        serviceapplication_x *ptr2 = NULL;
-       sqlite3 *appinfo_db = NULL;
+       const char* user_pkg_parser = 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);
+       user_pkg_parser = getUserPkgParserDBPathUID(uid);
+       ret = __open_manifest_db(uid);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
 
        /*calloc pkginfo*/
        pkgmgr_pkginfo_x *info = NULL;
@@ -4266,7 +4923,7 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, voi
        tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
 
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
-       ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
        if (info->manifest_info->uiapplication) {
@@ -4307,8 +4964,7 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, voi
        ret = PMINFO_R_OK;
 
 catch:
-       sqlite3_close(appinfo_db);
-
+       __close_manifest_db();
        if (appinfo) {
                free(appinfo);
                appinfo = NULL;
@@ -4317,7 +4973,12 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+{
+       return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
+}
+
+API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
 {
        retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
 
@@ -4334,7 +4995,8 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
        metadata_x *tmp4 = NULL;
        permission_x *tmp5 = NULL;
        image_x *tmp6 = NULL;
-       sqlite3 *appinfo_db = NULL;
+       appcontrol_x *tmp7 = NULL;
+       const char *user_pkg_parser = NULL;
 
        /*get system locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
@@ -4345,8 +5007,9 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
        tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is 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);
+       user_pkg_parser = getUserPkgParserDBPathUID(uid);
+       ret = __open_manifest_db(uid);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
 
        /*calloc pkginfo*/
        pkgmgr_pkginfo_x *info = NULL;
@@ -4362,7 +5025,7 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
        tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
 
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
-       ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
        if (info->manifest_info->uiapplication) {
@@ -4384,14 +5047,14 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
                                "from package_app_info where " \
                                "app_id='%s'", ptr1->appid);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
                if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
                        if (locale) {
                                free(locale);
                        }
-                       locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
+                       locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
                }
 
                memset(query, '\0', MAX_QUERY_LEN);
@@ -4399,7 +5062,7 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                                "from package_app_localized_info where " \
                                "app_id='%s' and app_locale='%s'",
                                ptr1->appid, locale);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                memset(query, '\0', MAX_QUERY_LEN);
@@ -4408,21 +5071,26 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                                "app_id='%s' and app_locale='%s'",
                                ptr1->appid, DEFAULT_LOCALE);
 
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
                /*store setting notification icon section*/
                memset(query, '\0', MAX_QUERY_LEN);
                snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
-               
+
                /*store app preview image info*/
                memset(query, '\0', MAX_QUERY_LEN);
                snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
 
+               /*store app control info*/
+               snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr1->appid);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+               tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
                if (appinfo->uiapp_info->label) {
                        LISTHEAD(appinfo->uiapp_info->label, tmp1);
                        appinfo->uiapp_info->label = tmp1;
@@ -4447,6 +5115,10 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                        LISTHEAD(appinfo->uiapp_info->image, tmp6);
                        appinfo->uiapp_info->image = tmp6;
                }
+               if (appinfo->uiapp_info->appcontrol) {
+                       LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
+                       appinfo->uiapp_info->appcontrol = tmp7;
+               }
                ret = app_func((void *)appinfo, user_data);
                if (ret < 0)
                        break;
@@ -4464,7 +5136,7 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
                                "from package_app_info where " \
                                "app_id='%s'", ptr2->appid);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
                memset(query, '\0', MAX_QUERY_LEN);
@@ -4472,7 +5144,7 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                                "from package_app_localized_info where " \
                                "app_id='%s' and app_locale='%s'",
                                ptr2->appid, locale);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
                memset(query, '\0', MAX_QUERY_LEN);
@@ -4480,9 +5152,13 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                                "from package_app_localized_info where " \
                                "app_id='%s' and app_locale='%s'",
                                ptr2->appid, DEFAULT_LOCALE);
-               ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
                tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
+               snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr2->appid);
+               ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+               tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
                if (appinfo->svcapp_info->label) {
                        LISTHEAD(appinfo->svcapp_info->label, tmp1);
                        appinfo->svcapp_info->label = tmp1;
@@ -4503,6 +5179,10 @@ API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, v
                        LISTHEAD(appinfo->svcapp_info->permission, tmp5);
                        appinfo->svcapp_info->permission = tmp5;
                }
+               if (appinfo->svcapp_info->appcontrol) {
+                       LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
+                       appinfo->svcapp_info->appcontrol = tmp7;
+               }
                ret = app_func((void *)appinfo, user_data);
                if (ret < 0)
                        break;
@@ -4520,7 +5200,7 @@ catch:
                free(syslocale);
                syslocale = NULL;
        }
-       sqlite3_close(appinfo_db);
+       __close_manifest_db();
        if (appinfo) {
                free(appinfo);
                appinfo = NULL;
@@ -4529,7 +5209,12 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
+API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+{
+       return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
+}
+
+API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
 {
        retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
@@ -4545,16 +5230,20 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        metadata_x *tmp4 = NULL;
        permission_x *tmp5 = NULL;
        image_x *tmp6 = NULL;
+       appcontrol_x *tmp7 = NULL;
        char query[MAX_QUERY_LEN] = {'\0'};
-       sqlite3 *appinfo_db = NULL;
+       const char* user_pkg_parser = 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);
+       *handle = NULL;
 
+       /*open db*/
+       user_pkg_parser = getUserPkgParserDBPathUID(uid);
+       ret = __open_manifest_db(uid);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
+  
        /*check appid exist on db*/
        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);
+       ret = __exec_db_query(GET_DB(manifest_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[%s] not found in DB", appid);
 
@@ -4573,7 +5262,7 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        /*check app_component from DB*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
-       ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
        /*calloc app_component*/
@@ -4589,50 +5278,55 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        /*populate app_info from DB*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
        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'", appid, locale);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App 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_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
 
        /*Populate app category*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
 
        /*Populate app metadata*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
 
        /*Populate app permission*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
 
        /*store setting notification icon section*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
 
        /*store app preview image info*/
        memset(query, '\0', MAX_QUERY_LEN);
        snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
-       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
 
+       /*store app control info*/
+       snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
+       ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
+
        switch (appinfo->app_component) {
        case PMINFO_UI_APP:
                if (appinfo->uiapp_info->label) {
@@ -4659,6 +5353,10 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
                        LISTHEAD(appinfo->uiapp_info->image, tmp6);
                        appinfo->uiapp_info->image = tmp6;
                }
+               if (appinfo->uiapp_info->appcontrol) {
+                       LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
+                       appinfo->uiapp_info->appcontrol = tmp7;
+               }
                break;
        case PMINFO_SVC_APP:
                if (appinfo->svcapp_info->label) {
@@ -4681,6 +5379,10 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
                        LISTHEAD(appinfo->svcapp_info->permission, tmp5);
                        appinfo->svcapp_info->permission = tmp5;
                }
+               if (appinfo->svcapp_info->appcontrol) {
+                       LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
+                       appinfo->svcapp_info->appcontrol = tmp7;
+               }
                break;
        default:
                break;
@@ -4696,7 +5398,7 @@ catch:
                __cleanup_appinfo(appinfo);
        }
 
-       sqlite3_close(appinfo_db);
+       __close_manifest_db();
        if (syslocale) {
                free(syslocale);
                syslocale = NULL;
@@ -4708,6 +5410,10 @@ catch:
        return ret;
 }
 
+API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
+{
+       return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
+}
 
 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h  handle, char **appid)
 {
@@ -4840,6 +5546,76 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h  handle, char **label)
        return PMINFO_R_OK;
 }
 
+static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
+{
+       char *result = NULL;
+       char *query = NULL;
+       sqlite3_stmt *stmt = NULL;
+       sqlite3 *db = NULL;
+       char *val;
+       char *manifest_db;
+
+       manifest_db = getUserPkgParserDBPathUID(uid);
+       if (manifest_db == NULL) {
+               _LOGE("Failed to get manifest db path");
+               goto err;
+       }
+
+       if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
+               _LOGE("DB open fail\n");
+               goto err;
+       }
+
+       query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
+       if (query == NULL) {
+               _LOGE("Out of memory");
+               goto err;
+       }
+
+       if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
+               _LOGE("prepare_v2 fail\n");
+               goto err;
+       }
+
+       if (sqlite3_step(stmt) == SQLITE_ROW) {
+               val = (char *)sqlite3_column_text(stmt, 0);
+               if (val != NULL)
+                       result = strdup(val);
+       }
+
+err:
+       sqlite3_finalize(stmt);
+       sqlite3_free(query);
+       sqlite3_close(db);
+
+       return result;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
+{
+       char *val;
+       int ret;
+
+       retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
+
+       val = _get_localed_label(appid, locale, uid);
+       if (val == NULL)
+               val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
+
+       if (val == NULL) {
+               ret = PMINFO_R_ERROR;
+       } else {
+               *label = val;
+               ret = PMINFO_R_OK;
+       }
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
+{
+       return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
+}
 
 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h  handle, pkgmgrinfo_app_component *component)
 {
@@ -5115,6 +5891,106 @@ API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
+       retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info->app_component != PMINFO_UI_APP)
+               return PMINFO_R_EINVAL;
+
+       if (info->uiapp_info->launch_mode == NULL)
+               return PMINFO_R_ERROR;
+
+       *mode = (char *)(info->uiapp_info->launch_mode);
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
+{
+       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 = NULL;
+       sqlite3_stmt *stmt = NULL;
+
+       /*open db*/
+       ret = __open_manifest_db(uid);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+
+       /*Start constructing query*/
+       query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
+
+       /*prepare query*/
+       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
+       tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
+
+       /*step query*/
+       ret = sqlite3_step(stmt);
+       tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
+
+       *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+       *access = strdup((char *)sqlite3_column_text(stmt, 2));
+
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_free(query);
+       sqlite3_finalize(stmt);
+       __close_manifest_db();
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
+{
+       return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
+{
+       retvm_if(providerid == 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");
+
+       int ret = PMINFO_R_OK;
+       char *query = NULL;
+       sqlite3_stmt *stmt = NULL;
+
+       /*open db*/
+       ret = __open_manifest_db(uid);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+
+       /*Start constructing query*/
+       query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
+
+       /*prepare query*/
+       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
+       tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
+
+       /*step query*/
+       ret = sqlite3_step(stmt);
+       tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
+
+       *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_free(query);
+       sqlite3_finalize(stmt);
+       __close_manifest_db();
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
+{
+       return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
+}
+
 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
 {
@@ -5192,182 +6068,35 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
 {
        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;
+       int ret;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       appcontrol_x *appcontrol;
        pkgmgrinfo_app_component component;
-       pkgmgrinfo_appcontrol_x *ptr = NULL;
-       ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
-       if (ret < 0) {
-               _LOGE("Failed to get package name\n");
-               return PMINFO_R_ERROR;
-       }
        ret = pkgmgrinfo_appinfo_get_component(handle, &component);
        if (ret < 0) {
                _LOGE("Failed to get app component name\n");
                return PMINFO_R_ERROR;
        }
-       manifest = pkgmgr_parser_get_manifest_file(pkgid);
-       if (manifest == NULL) {
-               _LOGE("Failed to fetch package manifest file\n");
-               return PMINFO_R_ERROR;
-       }
-       mfx = pkgmgr_parser_process_manifest_xml(manifest);
-       if (mfx == NULL) {
-               _LOGE("Failed to parse package manifest file\n");
-               free(manifest);
-               manifest = NULL;
-               return PMINFO_R_ERROR;
-       }
-       free(manifest);
-       ptr  = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
-       if (ptr == NULL) {
-               _LOGE("Out of Memory!!!\n");
-               pkgmgr_parser_free_manifest_xml(mfx);
-               return PMINFO_R_ERROR;
-       }
-       /*Get Operation, Uri, Mime*/
        switch (component) {
        case PMINFO_UI_APP:
-               if (mfx->uiapplication) {
-                       if (mfx->uiapplication->appsvc) {
-                               appcontrol = mfx->uiapplication->appsvc;
-                       }
-               }
+               if (info->uiapp_info == NULL)
+                       return PMINFO_R_EINVAL;
+               appcontrol = info->uiapp_info->appcontrol;
                break;
        case PMINFO_SVC_APP:
-               if (mfx->serviceapplication) {
-                       if (mfx->serviceapplication->appsvc) {
-                               appcontrol = mfx->serviceapplication->appsvc;
-                       }
-               }
+               if (info->svcapp_info == NULL)
+                       return PMINFO_R_EINVAL;
+               appcontrol = info->svcapp_info->appcontrol;
                break;
        default:
                break;
        }
        for (; appcontrol; appcontrol = appcontrol->next) {
-               op = appcontrol->operation;
-               for (; op; op = op->next)
-                       oc = oc + 1;
-               op = appcontrol->operation;
-
-               ui = appcontrol->uri;
-               for (; ui; ui = ui->next)
-                       uc = uc + 1;
-               ui = appcontrol->uri;
-
-               mi = appcontrol->mime;
-               for (; mi; mi = mi->next)
-                       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);
-                       op = op->next;
-               }
-
-               uri = (char **)calloc(uc, sizeof(char *));
-               for (i = 0; i < uc; i++) {
-                       uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
-                       ui = ui->next;
-               }
-
-               mime = (char **)calloc(mc, sizeof(char *));
-               for (i = 0; i < mc; i++) {
-                       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]) {
-                               free(operation[i]);
-                               operation[i] = NULL;
-                       }
-               }
-               if (operation) {
-                       free(operation);
-                       operation = NULL;
-               }
-               for (i = 0; i < uc; i++) {
-                       if (uri[i]) {
-                               free(uri[i]);
-                               uri[i] = NULL;
-                       }
-               }
-               if (uri) {
-                       free(uri);
-                       uri = NULL;
-               }
-               for (i = 0; i < mc; i++) {
-                       if (mime[i]) {
-                               free(mime[i]);
-                               mime[i] = NULL;
-                       }
-               }
-               if (mime) {
-                       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;
-               }
+               ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
                if (ret < 0)
                        break;
-               uc = 0;
-               mc = 0;
-               oc = 0;
-               sc = 0;
-       }
-       pkgmgr_parser_free_manifest_xml(mfx);
-       if (ptr) {
-               free(ptr);
-               ptr = NULL;
        }
+
        return PMINFO_R_OK;
 }
 
@@ -5561,6 +6290,32 @@ API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
+       retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
+
+       category_x *ptr = NULL;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       *exist = 0;
+
+       ptr = info->uiapp_info->category;
+
+       for (; ptr; ptr = ptr->next) {
+               if (ptr->name) {
+                       if (strcasecmp(ptr->name, category) == 0)
+                       {
+                               *exist = 1;
+                               break;
+                       }
+               }
+       }
+
+       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");
@@ -5742,7 +6497,7 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
+API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
 {
        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");
@@ -5769,11 +6524,12 @@ API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(uid);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
+               free(syslocale);
+               free(locale);
+               return PMINFO_R_ERROR;
        }
 
        /*Start constructing query*/
@@ -5793,20 +6549,17 @@ API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int
                        where[sizeof(where) - 1] = '\0';
                }
        }
-       _LOGE("where = %s\n", where);
        if (strlen(where) > 0) {
                strncat(query, where, sizeof(query) - strlen(query) - 1);
                query[sizeof(query) - 1] = '\0';
        }
-       _LOGE("query = %s\n", query);
 
        /*Execute Query*/
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
-               sqlite3_close(manifest_db);
                ret = PMINFO_R_ERROR;
                *count = 0;
                goto err;
@@ -5821,12 +6574,17 @@ err:
                free(syslocale);
                syslocale = NULL;
        }
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
-                               pkgmgrinfo_app_list_cb app_cb, void * user_data)
+API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
+{
+       return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
+}
+
+API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
+                               pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
 {
        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");
@@ -5854,11 +6612,12 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(uid);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
-               ret = PMINFO_R_ERROR;
-               goto err;
+               free(syslocale);
+               free(locale);
+               return PMINFO_R_ERROR;
        }
        /*Start constructing query*/
        snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
@@ -5876,14 +6635,13 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                        where[sizeof(where) - 1] = '\0';
                }
        }
-       _LOGE("where = %s\n", where);
        if (strlen(where) > 0) {
                strncat(query, where, sizeof(query) - strlen(query) - 1);
                query[sizeof(query) - 1] = '\0';
        }
-       _LOGE("query = %s\n", query);
        /*To get filtered list*/
        pkgmgr_pkginfo_x *info = NULL;
+       pkgmgr_pkginfo_x *filtinfo = NULL;
        info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
        if (info == NULL) {
                _LOGE("Out of Memory!!!\n");
@@ -5897,7 +6655,6 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                goto err;
        }
        /*To get detail app info for each member of filtered list*/
-       pkgmgr_pkginfo_x *filtinfo = NULL;
        filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
        if (filtinfo == NULL) {
                _LOGE("Out of Memory!!!\n");
@@ -5917,11 +6674,10 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                goto err;
        }
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
-               sqlite3_close(manifest_db);
                ret = PMINFO_R_ERROR;
                goto err;
        }
@@ -5940,11 +6696,10 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
                                                        ptr1->appid, "uiapp");
                if (SQLITE_OK !=
-               sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
+               sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
                        _LOGE("Don't execute query = %s error message = %s\n", query,
                               error_message);
                        sqlite3_free(error_message);
-                       sqlite3_close(manifest_db);
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
@@ -5954,11 +6709,10 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
                                                        ptr2->appid, "svcapp");
                if (SQLITE_OK !=
-               sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
+               sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
                        _LOGE("Don't execute query = %s error message = %s\n", query,
                               error_message);
                        sqlite3_free(error_message);
-                       sqlite3_close(manifest_db);
                        ret = PMINFO_R_ERROR;
                        goto err;
                }
@@ -5970,6 +6724,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->package = strdup(ptr1->package);
                appinfo->locale = strdup(locale);
                appinfo->uiapp_info = ptr1;
                appinfo->app_component = PMINFO_UI_APP;
@@ -5986,6 +6741,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->package = strdup(ptr2->package);
                appinfo->locale = strdup(locale);
                appinfo->svcapp_info = ptr2;
                appinfo->app_component = PMINFO_SVC_APP;
@@ -6004,7 +6760,7 @@ err:
                free(syslocale);
                syslocale = NULL;
        }
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        if (appinfo) {
                free(appinfo);
                appinfo = NULL;
@@ -6014,6 +6770,12 @@ err:
        return ret;
 }
 
+API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
+                               pkgmgrinfo_app_list_cb app_cb, void * user_data)
+{
+       return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
+}
+
 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
 {
        return (pkgmgrinfo_pkginfo_filter_create(handle));
@@ -6064,8 +6826,8 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
-               pkgmgrinfo_app_list_cb app_cb, void *user_data)
+API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
+               pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
 {
        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");
@@ -6090,9 +6852,13 @@ API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_f
        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");
-
+       ret = __open_manifest_db(uid);
+       if (ret == -1) {
+               _LOGE("Fail to open manifest DB\n");
+               free(syslocale);
+               free(locale);
+               return PMINFO_R_ERROR;
+       }
        /*Start constructing query*/
        memset(where, '\0', MAX_QUERY_LEN);
        memset(query, '\0', MAX_QUERY_LEN);
@@ -6109,11 +6875,9 @@ API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_f
                        strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
                }
        }
-       _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");
@@ -6131,7 +6895,7 @@ API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_f
        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);
+       ret = sqlite3_exec(GET_DB(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);
 
@@ -6149,7 +6913,7 @@ API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_f
        {
                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);
+               ret = sqlite3_exec(GET_DB(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);
        }
@@ -6158,7 +6922,7 @@ API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_f
        {
                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);
+               ret = sqlite3_exec(GET_DB(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);
        }
@@ -6205,7 +6969,7 @@ catch:
                syslocale = NULL;
        }
        sqlite3_free(error_message);
-       sqlite3_close(manifest_db);
+       __close_manifest_db();
        if (appinfo) {
                free(appinfo);
                appinfo = NULL;
@@ -6215,17 +6979,24 @@ catch:
        return ret;
 }
 
+API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
+               pkgmgrinfo_app_list_cb app_cb, void *user_data)
+{
+       return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
+}
+
 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));
+       *handle = NULL;
        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)
+API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
 {
        retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
@@ -6237,16 +7008,17 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_
        int i = 0;
 
        /*Open db.*/
-       ret = db_util_open_with_options(CERT_DB, &cert_db,
-                                       SQLITE_OPEN_READONLY, NULL);
+       ret = __open_cert_db(uid,"r");
        if (ret != SQLITE_OK) {
-               _LOGE("connect db [%s] failed!\n", CERT_DB);
-               return PMINFO_R_ERROR;
+               _LOGE("connect db [%s] failed!\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
+       _check_create_Cert_db(GET_DB(cert_db));
        /*validate 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)) {
+           sqlite3_exec(GET_DB(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);
@@ -6269,7 +7041,10 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_
        }
        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]);
+               if (uid == GLOBAL_USER || uid == ROOT_UID)
+                       snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d", (certinfo->cert_id)[i]);
+               else
+                       snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d and for_all_users=%d", (certinfo->cert_id)[i], certinfo->for_all_users);
                ret = __exec_certinfo_query(query, (void *)certinfo);
                if (ret == -1) {
                        _LOGE("Cert Info DB Information retrieval failed\n");
@@ -6283,7 +7058,7 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_
                }
        }
 err:
-       sqlite3_close(cert_db);
+       __close_cert_db();
        return ret;
 }
 
@@ -6327,6 +7102,7 @@ API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
        pkgmgr_instcertinfo_x *certinfo = NULL;
+       *handle = NULL;
        certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
        retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
        *handle = (void *)certinfo;
@@ -6345,7 +7121,7 @@ API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_i
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
+API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
 {
        retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
@@ -6373,25 +7149,25 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
        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 =__open_cert_db(uid, "w");
+       if (ret != 0) {
                ret = PMINFO_R_ERROR;
+               _LOGE("Failed to open cert db \n");
                goto err;
        }
+       _check_create_Cert_db(GET_DB(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 = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret == -1) {
+               _LOGE("Failed to begin transaction %s\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)) {
+           sqlite3_exec(GET_DB(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);
@@ -6402,7 +7178,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                /*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);
+               ret = __delete_certinfo(pkgid, uid);
                if (ret < 0)
                        _LOGE("Certificate Deletion Failed\n");
        }
@@ -6434,7 +7210,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                                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)) {
+                                   sqlite3_exec(GET_DB(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);
@@ -6454,7 +7230,6 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                        (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;
@@ -6477,7 +7252,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                (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)) {
+            sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", vquery,
                       error_message);
                sqlite3_free(error_message);
@@ -6509,7 +7284,7 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                                "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)) {
+                           sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
                                _LOGE("Don't execute query = %s error message = %s\n", vquery,
                                       error_message);
                                sqlite3_free(error_message);
@@ -6519,17 +7294,17 @@ API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h ha
                }
        }
        /*Commit transaction*/
-       ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
+       ret = sqlite3_exec(GET_DB(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);
+               sqlite3_exec(GET_DB(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);
+       __close_cert_db();
        if (vquery) {
                free(vquery);
                vquery = NULL;
@@ -6562,55 +7337,84 @@ API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_delete_certinfo(const char *pkgid)
+API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
 {
        retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
        int ret = -1;
        /*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 = __open_cert_db(uid, "w");
+       if (ret != 0) {
+               _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
                ret = PMINFO_R_ERROR;
                goto err;
        }
+       _check_create_Cert_db(GET_DB(cert_db));
        /*Begin Transaction*/
-       ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       ret = sqlite3_exec(GET_DB(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");
-       ret = __delete_certinfo(pkgid);
+       ret = __delete_certinfo(pkgid, uid);
        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);
+       ret = sqlite3_exec(GET_DB(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);
+               sqlite3_exec(GET_DB(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);
+       __close_cert_db();
        return ret;
 }
 
-API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
+
+API int pkgmgrinfo_delete_certinfo(const char *pkgid)
+{
+       return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
+}
+
+API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
 {
        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;
+       *handle = NULL;
+       manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
+       retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
 
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       if (manifest) {
+               free(manifest);
+               manifest = NULL;
+       }
+       retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
+
+       *handle = (void *)mfx;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
+{
+       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;
+       *handle = NULL;
        manifest = pkgmgr_parser_get_manifest_file(pkgid);
        retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
 
@@ -6835,6 +7639,24 @@ API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
        }
 }
 
+API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
+{
+       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+
+       int ret = 0;
+       manifest_x *mfx = NULL;
+       mfx = (manifest_x *)handle;
+
+       ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
+       if (ret == 0) {
+               _LOGE("Successfully stored info in DB\n");
+               return PMINFO_R_OK;
+       } else {
+               _LOGE("Failed to store info in DB\n");
+               return PMINFO_R_ERROR;
+       }
+}
+
 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
 {
        retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
@@ -6851,27 +7673,24 @@ API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
        return 0;
 }
 
-API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
+API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
 {
        retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
        int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
-       ret = __open_manifest_db();
 
-       if (access(MANIFEST_DB, F_OK) == 0) {
-               ret = db_util_open(MANIFEST_DB, &manifest_db,
-                        DB_UTIL_REGISTER_HOOK_METHOD);
-               if (ret != SQLITE_OK) {
-                       _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
-                       return PMINFO_R_ERROR;
-               }
+       /* Open db.*/
+       ret = __open_manifest_db(uid);
+       if (ret != SQLITE_OK) {
+               _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
+               return PMINFO_R_ERROR;
        }
 
        /*Begin transaction*/
-       ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("Failed to begin transaction\n");
-               sqlite3_close(manifest_db);
+               __close_manifest_db();
                return PMINFO_R_ERROR;
        }
        _LOGD("Transaction Begin\n");
@@ -6882,7 +7701,7 @@ API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
 
        char *error_message = NULL;
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
@@ -6891,19 +7710,22 @@ API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
        sqlite3_free(error_message);
 
        /*Commit transaction*/
-       ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
+       ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("Failed to commit transaction. Rollback now\n");
-               sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
-               sqlite3_close(manifest_db);
+               sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
+               __close_manifest_db();
                return PMINFO_R_ERROR;
        }
        _LOGD("Transaction Commit and End\n");
-       sqlite3_close(manifest_db);
-
+       __close_manifest_db();
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
+{
+       return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
+}
 
 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
 {
@@ -6925,53 +7747,45 @@ API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * typ
        data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
        if (data == NULL) {
                _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
-               sqlite3_close(datacontrol_db);
+               __close_datacontrol_db();
                return PMINFO_R_ERROR;
        }
 
        snprintf(query, MAX_QUERY_LEN, 
-               "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.provider_id = '%s' and datacontrol.type='%s' COLLATE NOCASE",
+               "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.providerid = '%s' and datacontrol.type='%s' COLLATE NOCASE",
                providerid, type);
 
        if (SQLITE_OK !=
-               sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
+               sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                           error_message);
                sqlite3_free(error_message);
-               sqlite3_close(datacontrol_db);
+               __close_datacontrol_db();
                return PMINFO_R_ERROR;
        }
 
        *appid = (char *)data->appid;
        *access = (char *)data->access;
        free(data);
-       sqlite3_close(datacontrol_db);
+    __close_datacontrol_db();
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
+API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
 {
        retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
        int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *error_message = NULL;
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(uid);
 
-       if (access(MANIFEST_DB, F_OK) == 0) {
-               ret = db_util_open(MANIFEST_DB, &manifest_db,
-                        DB_UTIL_REGISTER_HOOK_METHOD);
-               if (ret != SQLITE_OK) {
-                       _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
-                       return PMINFO_R_ERROR;
-               }
-       }
 
        /*Begin transaction*/
-       ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("Failed to begin transaction\n");
-               sqlite3_close(manifest_db);
+               __close_manifest_db();
                return PMINFO_R_ERROR;
        }
        _LOGD("Transaction Begin\n");
@@ -6981,7 +7795,7 @@ API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *labe
                "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
 
        if (SQLITE_OK !=
-           sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
+           sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
                _LOGE("Don't execute query = %s error message = %s\n", query,
                       error_message);
                sqlite3_free(error_message);
@@ -6989,19 +7803,23 @@ API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *labe
        }
 
        /*Commit transaction*/
-       ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
+       ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("Failed to commit transaction. Rollback now\n");
-               sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
-               sqlite3_close(manifest_db);
+               sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
+               __close_manifest_db();
                return PMINFO_R_ERROR;
        }
        _LOGD("Transaction Commit and End\n");
-       sqlite3_close(manifest_db);
-
+       __close_manifest_db();
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
+{
+       return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
+}
+
 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
@@ -7021,12 +7839,11 @@ API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
+API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        char *val = NULL;
        int ret = 0;
-       char *noti_string = NULL;
        int len = 0;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *errmsg = NULL;
@@ -7035,14 +7852,14 @@ API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        val = (char *)info->uiapp_info->guestmode_visibility;
        if (val ) {
-                ret =
-                   db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
-                                SQLITE_OPEN_READWRITE, NULL);
+               ret =
+                 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
+                               SQLITE_OPEN_READWRITE, NULL);
 
-                if (ret != SQLITE_OK) {
+               if (ret != SQLITE_OK) {
                        _LOGE("DB Open Failed\n");
                        return PMINFO_R_ERROR;
-                }
+               }
 
                /*TODO: Write to DB here*/
                if (status == true)
@@ -7050,27 +7867,22 @@ API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
                else
                        snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
 
-               if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
+               ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg);
+               sqlite3_close(pkgmgr_parser_db);
+               if (ret != SQLITE_OK) {
                        _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
                        free(errmsg);
-                       sqlite3_close(pkgmgr_parser_db);
-                       return PMINFO_R_ERROR;
-               }else{
-                       sqlite3_close(pkgmgr_parser_db);
-                       len = strlen((char *)info->uiapp_info->appid) + 8;
-                       noti_string = calloc(1, len);
-                       if (noti_string == NULL){
-                               return PMINFO_R_ERROR;
-                       }
-                       snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
-               vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
-                       vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
-                       free(noti_string);
+                       return PMINFO_R_ERROR;
                }
        }
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
+{
+       return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
+}
+
 /* pkgmgrinfo client start*/
 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
 {
@@ -7113,7 +7925,28 @@ API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type
        tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
 
 catch:
+        /*
+         * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
+         *
+         * The lib dependency chain like below
+         * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
+         *
+         * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
+         * which will registered to dbus callback in amd though in fact amd doesn't direct depends
+         * on libpkgmgr-installer-client.
+         *
+         * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
+         * link to it then.
+         *
+         * However, when the libdbus call into the callback function, it suddenly fond that the
+         * function address is gone (unmapped), then we receive a SIGSEGV.
+         *
+         * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
+         * robust if we just link to the well-known lib.
+         *
+         * See https://bugs.tizen.org/jira/browse/PTREL-591
        dlclose(handle);
+         */
        return ret;
 }
 
@@ -7135,7 +7968,7 @@ API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handle
        tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
 
 catch:
-       dlclose(handle);
+        /* same as pkgmgrinfo_client_new */
        return ret;
 }
 
@@ -7157,7 +7990,7 @@ API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
        tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
 
 catch:
-       dlclose(handle);
+        /* same as pkgmgrinfo_client_new */
        return ret;
 }