Multi user features 20/25720/2 submit/tizen_common/20140811.160835 submit/tizen_common/20140811.161134 submit/tizen_common/20140811.192137 submit/tizen_ivi/20140813.000000
authorSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Tue, 17 Jun 2014 14:27:52 +0000 (16:27 +0200)
committerSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Mon, 11 Aug 2014 15:58:50 +0000 (17:58 +0200)
    ->Add / Use Usr App related fonctions instead of Global App related Functions

Change-Id: Iebd5b7b66f9446a61c608b32669cec94a269063d
Signed-off-by: Sabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
include/pkgmgr-info.h
parser/pkgmgr_parser.c
parser/pkgmgr_parser.h
parser/pkgmgr_parser_db.c
parser/pkgmgr_parser_db.h
src/pkgmgr-info.c

index 9683079..7e9c4a7 100755 (executable)
@@ -435,14 +435,27 @@ typedef enum {
  /** string property for filtering based on pkg info*/
 #define        PMINFO_PKGINFO_PROP_RANGE_BASIC "PMINFO_PKGINFO_PROP_RANGE_BASIC"
 
+/* For multiuser support */
+char *getUserDBLabel(void);
+char *getUserPkgParserDBPath(void);
+char *getUserPkgParserDBPathUID(uid_t uid);
+char *getUserPkgParserJournalDBPath(uid_t uid);
+char *getUserPkgCertDBPath(void);
+char *getUserPkgCertDBPathUID(uid_t uid);
+char *getUserPkgCertJournalDBPath(uid_t uid);
+const char* getUserDesktopPath(uid_t uid);
+const char* getUserManifestPath(uid_t uid);
+
 /**
  * @fn int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
+ * @fn int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
  * @brief      This API gets list of installed packages
  *
  * @par                This API is for package-manager client application
  * @par Sync (or) Async : Synchronous API
  * @param[in]  pkg_list_cb     iteration function for list
  * @param[in]  user_data       user data to be passed to callback function
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -476,7 +489,7 @@ static int list_pkgs()
  * @endcode
  */
 int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data);
-
+int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid);
 /**
  * @fn int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
  * @brief      This API creates the package information handle from db
@@ -485,6 +498,7 @@ int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_d
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  pkgid   pointer to package ID
+ * @param[in]  uid     the addressee user id of the instruction
  * @param[out] handle          pointer to the package info handle.
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
@@ -515,6 +529,7 @@ static int get_pkg_type(const char *pkgid)
  * @endcode
  */
 int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle);
+int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle);
 
 /**
  * @fn int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
@@ -1359,7 +1374,7 @@ static int compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_pac
  * @endcode
  */
 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);
-
+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);
 /**
  * @fn 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)
  * @brief      This API compare the cert information from given app id
@@ -1394,7 +1409,7 @@ static int compare_app_cert_info(const char *lhs_app_id, const char *rhs_app_id,
  * @endcode
  */
 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);
-
+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);
 /**
  * @fn int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
  * @brief      This API gets the package 'removable' value from the package ID
@@ -1983,6 +1998,7 @@ int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle
 
 /**
  * @fn int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
+ * @fn int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
  * @brief      This API counts the package that satisfy the filter conditions
  *
  * @par                This API is for package-manager client application
@@ -1990,6 +2006,7 @@ int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle
  *
  * @param[in] handle           pointer to the package info filter handle.
  * @param[in] count            pointer to store the count value.
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -2023,7 +2040,7 @@ static int get_rpm_pkg_count()
  * @endcode
  */
 int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count);
-
+int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid);
 /**
  * @fn int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
                        pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data);
@@ -2155,7 +2172,7 @@ static int list_apps()
  * @endcode
  */
 int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data);
-
+int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data);
 /**
  * @fn int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data);
  * @brief      This API gets list of installed applications from all packages.
@@ -2197,6 +2214,7 @@ static int list_apps()
  * @endcode
  */
 int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data);
+int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data);
 
 /**
  * @fn int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
@@ -2236,7 +2254,7 @@ static int get_app_type(const char *appid)
  * @endcode
  */
 int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle);
-int pkgmgrinfo_appinfo_get_appinfo_user(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle);
+int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle);
 /**
  * @fn int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
  * @brief      This API gets the application ID
@@ -3298,6 +3316,8 @@ int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
 /**
  * @fn int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data);
+ * @fn int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid);
  * @brief      This API gets the list of app-control for a particular application
  *
  * @par                This API is for package-manager client application
@@ -3305,6 +3325,7 @@ int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
  * @param[in]  handle          pointer to the application info handle.
  * @param[in]  appcontrol_func         callback function for list
  * @param[in] user_data        user data to be passed to callback function
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -3345,6 +3366,8 @@ static int check_operation(const char *appid, char *operation)
  */
 int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data);
+int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid);
 
 /**
  * @fn int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
@@ -4054,6 +4077,7 @@ int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle
 
 /**
  * @fn int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
+ * @fn int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
  * @brief      This API counts the application that satisfy the filter conditions
  *
  * @par                This API is for package-manager client application
@@ -4061,6 +4085,7 @@ int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle
  *
  * @param[in] handle           pointer to the application info filter handle.
  * @param[in] count            pointer to store count value
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -4094,7 +4119,7 @@ static int get_capp_count()
  * @endcode
  */
 int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count);
-
+int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid);
 /**
  * @fn int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
  * @brief      This API creates the application's metadata  information filter handle from db.
@@ -4245,6 +4270,7 @@ int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h
 
 /**
  * @fn int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle, pkgmgrinfo_app_list_cb app_cb, void *user_data)
+ * @fn 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)
  * @brief      This API executes the filter query. The query will search the entire application metadata  information collected from
  * the manifest file of all the installed packages. For each application returned by the query, the callback will be called. If callback returns
  * negative value, no more callbacks will be called and API will return.
@@ -4255,6 +4281,7 @@ int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h
  * @param[in] handle           pointer to the application metadata info filter handle.
  * @param[in] app_cb           function pointer to callback
  * @param[in] user_data                pointer to user data
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -4294,7 +4321,8 @@ static int get_app_list(const char *mkey, const char *mvalue)
  */
 int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
                pkgmgrinfo_app_list_cb app_cb, void *user_data);
-
+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);
 /**
  * @fn int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
  * @brief      This API creates the package cert information handle to get data from db.
@@ -4496,12 +4524,14 @@ static int delete_cert_info(const char *pkgid)
 
 /**
  * @fn int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
+ * @fn int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
  * @brief      This API creates the package db information handle to set data in db.
  *
  * @par                This API is for package-manager client application
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in] pkgid    pointer to the package ID.
+ * @param[in]  uid     the addressee user id of the instruction
  * @param[out] handle          pointer to the package db info handle.
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
@@ -4535,6 +4565,7 @@ static int set_pkg_in_db(const char *pkgid)
  * @endcode
  */
 int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle);
+int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle);
 
 /**
  * @fn int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
@@ -5007,12 +5038,14 @@ int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle,
 
 /**
  * @fn int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
+ * @fn int pkgmgrinfo_save_pkgdbusrinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
  * @brief      This API saves all the information from the handle to the DB.
  *
  * @par                This API is for package-manager client application
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in] handle           pointer to the package db info handle.
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -5044,7 +5077,7 @@ static int set_pkg_in_db(const char *pkgid)
  * @endcode
  */
 int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle);
-
+int pkgmgrinfo_save_pkgdbusrinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid);
 /**
  * @fn int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
  * @brief      This API destroys the package db information handle freeing up all the resources
@@ -5345,7 +5378,7 @@ static int set_app_guestmode_visibility(const char *appid, bool value)
  * @endcode
  */
  int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status);
-
+ int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status);
 /**
  * @pkgmgrinfo client API
 **/
index 0936e71..eff5c64 100755 (executable)
@@ -33,7 +33,6 @@
 #include <libxml/xmlschemas.h>
 #include <vconf.h>
 #include <glib.h>
-#include <pwd.h>
 #include <grp.h>
 
 #include "pkgmgr_parser.h"
 #endif
 #define LOG_TAG "PKGMGR_PARSER"
 
-#define MANIFEST_RW_DIRECTORY tzplatform_getenv(TZ_SYS_RW_PACKAGES)
-#define MANIFEST_RO_DIRECTORY tzplatform_getenv(TZ_SYS_RO_PACKAGES)
 #define ASCII(s) (const char *)s
 #define XMLCHAR(s) (const xmlChar *)s
 
-#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
+//#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/metadata_parser_list.txt"
+#define METADATA_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/metadata/mdparser_list.txt"
 #define METADATA_PARSER_NAME   "metadataparser:"
 
 #define CATEGORY_PARSER_LIST SYSCONFDIR "/package-manager/parserlib/category/category_parser_list.txt"
@@ -63,8 +61,8 @@
 #define TAG_PARSER_NAME        "parserlib:"
 
 #define PKG_TAG_LEN_MAX 128
-
-
+#define OWNER_ROOT 0
+#define BUFSIZE 4096
 
 /* operation_type */
 typedef enum {
@@ -113,15 +111,15 @@ static int __ps_process_define(xmlTextReaderPtr reader, define_x *define);
 static int __ps_process_appsvc(xmlTextReaderPtr reader, appsvc_x *appsvc);
 static int __ps_process_launchconditions(xmlTextReaderPtr reader, launchconditions_x *launchconditions);
 static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashare);
-static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon);
+static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid);
 static int __ps_process_author(xmlTextReaderPtr reader, author_x *author);
 static int __ps_process_description(xmlTextReaderPtr reader, description_x *description);
 static int __ps_process_capability(xmlTextReaderPtr reader, capability_x *capability);
 static int __ps_process_license(xmlTextReaderPtr reader, license_x *license);
 static int __ps_process_appcontrol(xmlTextReaderPtr reader, appcontrol_x *appcontrol);
 static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *datacontrol);
-static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication);
-static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication);
+static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid);
+static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid);
 static int __ps_process_font(xmlTextReaderPtr reader, font_x *font);
 static int __ps_process_theme(xmlTextReaderPtr reader, theme_x *theme);
 static int __ps_process_daemon(xmlTextReaderPtr reader, daemon_x *daemon);
@@ -160,10 +158,10 @@ static void __ps_free_font(font_x *font);
 static void __ps_free_theme(theme_x *theme);
 static void __ps_free_daemon(daemon_x *daemon);
 static void __ps_free_ime(ime_x *ime);
-static char *__pkgid_to_manifest(const char *pkgid);
+static char *__pkgid_to_manifest(const char *pkgid, uid_t uid);
 static int __next_child_element(xmlTextReaderPtr reader, int depth);
-static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx);
-static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx);
+static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
+static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid);
 static void __str_trim(char *input);
 static char *__get_parser_plugin(const char *type);
 static int __ps_run_parser(xmlDocPtr docPtr, const char *tag, ACTION_TYPE action, const char *pkgid);
@@ -171,83 +169,7 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
 static void __processNode(xmlTextReaderPtr reader, ACTION_TYPE action, char *const tagv[], const char *pkgid);
 static void __streamFile(const char *filename, ACTION_TYPE action, char *const tagv[], const char *pkgid);
 static int __validate_appid(const char *pkgid, const char *appid, char **newappid);
-static int __is_admin();
-
-API char *getUserDBLabel(void)
-{
-       char *result;
-       if(__is_admin())
-               result = strdup("System");
-       else
-               result = strdup("User");
-       return result;
-}
-
-API char *getUserPkgParserDBPath(void)
-{
-   return getUserPkgParserDBPathUID(getuid());
-}
-
-API char *getUserPkgParserDBPathUID(uid_t uid)
-{
-       char  *result = NULL;
-       if(!uid)
-       {
-               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
-       }
-       else
-       {
-               static char result_psswd[4096];
-               const char *name = "users";
-               struct passwd *userinfo = NULL;
-               struct group *grpinfo = NULL;
-
-               userinfo = getpwuid(uid);
-               if(userinfo == NULL)
-                       _LOGE("getpwuid(%d) returns NULL !", uid);
-
-               grpinfo = getgrnam(name);
-               if(grpinfo == NULL)
-                       _LOGE("getgrnam(users) returns NULL !");
-
-               // Compare git_t type and not group name
-               if (grpinfo->gr_gid != userinfo->pw_gid)
-                       _LOGE("UID [%d] does not belong to 'users' group!", uid);
-               snprintf(result_psswd,sizeof(result_psswd),"%s/.applications/dbspace/.pkgmgr_parser.db",userinfo->pw_dir);
-               result = result_psswd;
-       }
-  return result;
-}
-
-API char *getUserPkgParserJournalDBPath(void)
-{
-       char *result;
-       if(getuid())
-               result = tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.pkgmgr_parser-journal.db");
-       else
-               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
-    return result;
-}
-
-API char *getUserPkgCertDBPath(void)
-{
-       char *result;
-       if(getuid())
-               result = tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.pkgmgr_cert.db");
-       else
-               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
-    return result;
-}
-
-API char *getUserPkgCertJournalDBPath(void)
-{
-       char *result;
-       if(getuid())
-               result = tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.pkgmgr_cert-journal.db");
-       else
-               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert-journal.db");
-    return result;
-}
+API int __is_admin();
 
 void *__open_lib_handle(char *tag)
 {
@@ -287,7 +209,7 @@ static void __str_trim(char *input)
        return;
 }
 
-static int __is_admin()
+API int __is_admin()
 {
        uid_t uid = getuid();
        if ((uid_t) 0 == uid )
@@ -711,7 +633,7 @@ END:
        return ret;
 }
 
-static char *__pkgid_to_manifest(const char *pkgid)
+static char *__pkgid_to_manifest(const char *pkgid, uid_t uid)
 {
        char *manifest;
        int size;
@@ -721,17 +643,17 @@ static char *__pkgid_to_manifest(const char *pkgid)
                return NULL;
        }
 
-       size = strlen(MANIFEST_RW_DIRECTORY) + strlen(pkgid) + 10;
+       size = strlen(getUserManifestPath(uid)) + strlen(pkgid) + 10;
        manifest = malloc(size);
        if (manifest == NULL) {
                _LOGE("No memory");
                return NULL;
        }
        memset(manifest, '\0', size);
-       snprintf(manifest, size, "%s/%s.xml", MANIFEST_RW_DIRECTORY, pkgid);
+       snprintf(manifest, size, "%s/%s.xml", getUserManifestPath(uid), pkgid);
 
        if (access(manifest, F_OK)) {
-               snprintf(manifest, size, "%s/%s.xml", MANIFEST_RO_DIRECTORY, pkgid);
+               snprintf(manifest, size, "%s/%s.xml", getUserManifestPath(uid), pkgid);
        }
 
        return manifest;
@@ -920,10 +842,12 @@ static int __run_metadata_parser_prestep (manifest_x *mfx, char *md_key, ACTION_
                //send glist to parser when tags for metadata plugin parser exist.
                if (tag_exist) {
                        ret = __ps_run_metadata_parser(md_list, md_tag, action, mfx->package, up->appid);
-                       if (ret < 0)
+                       if (ret < 0){
                                _LOGD("metadata_parser failed[%d] for tag[%s]\n", ret, md_tag);
-                       else
+                       }
+                       else{
                                _LOGD("metadata_parser success for tag[%s]\n", md_tag);
+                       }
                }
                __metadata_parser_clear_dir_list(md_list);
                md_list = NULL;
@@ -1108,9 +1032,8 @@ static int __run_parser_prestep(xmlTextReaderPtr reader, ACTION_TYPE action, con
            cur_node->next ? cur_node->next->name : "NULL",
            cur_node->prev ? cur_node->prev->name : "NULL");
 
-       FILE *fp = fopen("/opt/share/test.xml", "a");
+       FILE *fp = fopen(tzplatform_mkpath(TZ_SYS_SHARE, "test.xml"), "a");
        xmlDocDump(fp, copyDocPtr);
-       fprintf(fp, "\n");
        fclose(fp);
 #endif
 
@@ -2554,6 +2477,7 @@ int __ps_process_tag_parser(manifest_x *mfx, const char *filename, ACTION_TYPE a
 
 int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
 {
+       fprintf(stdout,"__ps_process_metadata_parser\n");
        int ret = -1;
        FILE *fp = NULL;
        char md_key[PKG_STRING_LEN_MAX] = { 0 };
@@ -2563,7 +2487,7 @@ int __ps_process_metadata_parser(manifest_x *mfx, ACTION_TYPE action)
                _LOGD("no preload list\n");
                return -1;
        }
-
+       
        while (fgets(md_key, sizeof(md_key), fp) != NULL) {
                __str_trim(md_key);
                ret = __run_metadata_parser_prestep(mfx, md_key, action);
@@ -3108,13 +3032,14 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
 }
 
 static char*
-__get_icon_with_path(const char* icon)
+__get_icon_with_path(const char* icon, uid_t uid)
 {
        if (!icon)
                return NULL;
 
        if (index(icon, '/') == NULL) {
                char* theme = NULL;
+               char* iconPath = NULL;
                char* icon_with_path = NULL;
                int len;
 
@@ -3143,30 +3068,57 @@ __get_icon_with_path(const char* icon)
                }
 
                memset(icon_with_path, 0, len);
+               //--------------------------------------------------------------
+               //workaround to bypass segfault when we use geticon function
+               
+               if(uid != GLOBAL_USER)
+                       iconPath = tzplatform_getenv(TZ_USER_ICONS);
+               else
+                       iconPath = tzplatform_getenv(TZ_SYS_RW_ICONS);
+               if(access(iconPath, F_OK)) {
+                       struct group *grpinfo = NULL;
+                       const char *name = "users";
+                       int ret;
+                       char buf[BUFSIZE];
+                       mkdir(iconPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+                       grpinfo = getgrnam(name);
+                       if(grpinfo == NULL)
+                               _LOGD("getgrnam(users) returns NULL !");
+
+                       ret = chown(iconPath, uid, grpinfo->gr_gid);
+                       if (ret == -1) {
+                               strerror_r(errno, buf, sizeof(buf));
+                               _LOGD("FAIL : chown %s %d.%d, because %s", iconPath, uid, grpinfo->gr_gid, buf);
+                       }
+                       
+               }
+               if(iconPath == NULL)
+                       _LOGD("Icon path error: %s ",iconPath );
+               else
+                       snprintf(icon_with_path, len, "%s/%s/small/%s", iconPath, theme, icon);
 
-               snprintf(icon_with_path, len, "/opt/share/icons/%s/small/%s", theme, icon);
                do {
                        if (access(icon_with_path, R_OK) == 0) break;
-                       snprintf(icon_with_path, len, "/usr/share/icons/%s/small/%s", theme, icon);
+                       snprintf(icon_with_path, len, "%s/%s/small/%s", tzplatform_getenv(TZ_SYS_RO_ICONS), theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        _LOGD("cannot find icon %s", icon_with_path);
-                       snprintf(icon_with_path, len,"/opt/share/icons/default/small/%s", icon);
+                       snprintf(icon_with_path, len,"%s/default/small/%s", iconPath, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       snprintf(icon_with_path, len, "/usr/share/icons/default/small/%s", icon);
+                       snprintf(icon_with_path, len, "%s/icons/default/small/%s", tzplatform_getenv(TZ_SYS_RO_ICONS), icon);
                        if (access(icon_with_path, R_OK) == 0) break;
 
                        /* icon path is going to be moved intto the app directory */
                        _LOGE("icon file must be moved to %s", icon_with_path);
-                       snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/%s/small/%s", package, theme, icon);
+                       snprintf(icon_with_path, len, "%s/%s/res/icons/%s/small/%s", tzplatform_getenv(TZ_SYS_RW_APP), package, theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/%s/small/%s", package, theme, icon);
+                       snprintf(icon_with_path, len, "%s/%s/res/icons/%s/small/%s", tzplatform_getenv(TZ_SYS_RO_APP), package, theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        _LOGD("cannot find icon %s", icon_with_path);
-                       snprintf(icon_with_path, len, "/opt/apps/%s/res/icons/default/small/%s", package, icon);
+                       snprintf(icon_with_path, len, "%s/%s/res/icons/default/small/%s", tzplatform_getenv(TZ_SYS_RW_APP), package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       snprintf(icon_with_path, len, "/usr/apps/%s/res/icons/default/small/%s", package, icon);
+                       snprintf(icon_with_path, len, "%s/res/icons/default/small/%s", tzplatform_getenv(TZ_SYS_RO_APP), package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       snprintf(icon_with_path, len, "/usr/ug/res/images/%s/%s", package, icon);
+                       snprintf(icon_with_path, len, "%s/res/images/%s/%s", tzplatform_getenv(TZ_SYS_RO_UG), package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                } while (0);
 
@@ -3234,7 +3186,7 @@ static void __ps_process_tag(manifest_x * mfx, char *const tagv[])
        }
 }
 
-static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
+static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon, uid_t uid)
 {
        if (xmlTextReaderGetAttribute(reader, XMLCHAR("name")))
                icon->name = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("name")));
@@ -3255,7 +3207,7 @@ static int __ps_process_icon(xmlTextReaderPtr reader, icon_x *icon)
        if (xmlTextReaderValue(reader)) {
                const char *text  = ASCII(xmlTextReaderValue(reader));
                if(text) {
-                       icon->text = (const char *)__get_icon_with_path(text);
+                       icon->text = (const char *)__get_icon_with_path(text, uid);
                        free((void *)text);
                }
        }
@@ -3291,13 +3243,13 @@ static int __ps_process_label(xmlTextReaderPtr reader, label_x *label)
                label->lang = strdup(ASCII(xmlTextReaderConstXmlLang(reader)));
                if (label->lang == NULL)
                        label->lang = strdup(DEFAULT_LOCALE);
-       } else {
+       } else 
                label->lang = strdup(DEFAULT_LOCALE);
-       }
        xmlTextReaderRead(reader);
        if (xmlTextReaderValue(reader))
                label->text = ASCII(xmlTextReaderValue(reader));
 
+
 /*     _LOGD("lable name %s\n", label->name);
        _LOGD("lable lang %s\n", label->lang);
        _LOGD("lable text %s\n", label->text);
@@ -3455,8 +3407,9 @@ static int __ps_process_datacontrol(xmlTextReaderPtr reader, datacontrol_x *data
        return ret;
 }
 
-static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication)
+static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *uiapplication, uid_t uid)
 {
+       fprintf(stdout, "__ps_process_uiapplication\n");
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
@@ -3633,7 +3586,7 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
                        }
                        memset(icon, '\0', sizeof(icon_x));
                        LISTADD(uiapplication->icon, icon);
-                       ret = __ps_process_icon(reader, icon);
+                       ret = __ps_process_icon(reader, icon, uid);
                } else if (!strcmp(ASCII(node), "image")) {
                        image_x *image = malloc(sizeof(image_x));
                        if (image == NULL) {
@@ -3771,8 +3724,9 @@ static int __ps_process_uiapplication(xmlTextReaderPtr reader, uiapplication_x *
        return ret;
 }
 
-static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication)
+static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceapplication_x *serviceapplication, uid_t uid)
 {
+       fprintf(stdout, "__ps_process_serviceapplication\n");
        const xmlChar *node;
        int ret = -1;
        int depth = -1;
@@ -3862,7 +3816,7 @@ static int __ps_process_serviceapplication(xmlTextReaderPtr reader, serviceappli
                        }
                        memset(icon, '\0', sizeof(icon_x));
                        LISTADD(serviceapplication->icon, icon);
-                       ret = __ps_process_icon(reader, icon);
+                       ret = __ps_process_icon(reader, icon, uid);
                } else if (!strcmp(ASCII(node), "category")) {
                        category_x *category = malloc(sizeof(category_x));
                        if (category == NULL) {
@@ -4030,7 +3984,7 @@ static int __ps_process_ime(xmlTextReaderPtr reader, ime_x *ime)
        return 0;
 }
 
-static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
+static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
 {
        _LOGD("__start_process\n");
        const xmlChar *node;
@@ -4052,6 +4006,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
        privileges_x *tmp14 = NULL;
 
        depth = xmlTextReaderDepth(reader);
+       int  i =0;
        while ((ret = __next_child_element(reader, depth))) {
                node = xmlTextReaderConstName(reader);
                if (!node) {
@@ -4112,7 +4067,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        }
                        memset(uiapplication, '\0', sizeof(uiapplication_x));
                        LISTADD(mfx->uiapplication, uiapplication);
-                       ret = __ps_process_uiapplication(reader, uiapplication);
+                       ret = __ps_process_uiapplication(reader, uiapplication, uid);
                } else if (!strcmp(ASCII(node), "service-application")) {
                        serviceapplication_x *serviceapplication = malloc(sizeof(serviceapplication_x));
                        if (serviceapplication == NULL) {
@@ -4121,7 +4076,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        }
                        memset(serviceapplication, '\0', sizeof(serviceapplication_x));
                        LISTADD(mfx->serviceapplication, serviceapplication);
-                       ret = __ps_process_serviceapplication(reader, serviceapplication);
+                       ret = __ps_process_serviceapplication(reader, serviceapplication, uid);
                } else if (!strcmp(ASCII(node), "daemon")) {
                        daemon_x *daemon = malloc(sizeof(daemon_x));
                        if (daemon == NULL) {
@@ -4166,7 +4121,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
                        }
                        memset(icon, '\0', sizeof(icon_x));
                        LISTADD(mfx->icon, icon);
-                       ret = __ps_process_icon(reader, icon);
+                       ret = __ps_process_icon(reader, icon, uid);
                } else if (!strcmp(ASCII(node), "device-profile")) {
                        deviceprofile_x *deviceprofile = malloc(sizeof(deviceprofile_x));
                        if (deviceprofile == NULL) {
@@ -4262,7 +4217,7 @@ static int __start_process(xmlTextReaderPtr reader, manifest_x * mfx)
        return ret;
 }
 
-static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
+static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx, uid_t uid)
 {
        const xmlChar *node;
        int ret = -1;
@@ -4275,8 +4230,9 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                }
 
                if (!strcmp(ASCII(node), "manifest")) {
-                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")))
+                       if (xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns"))){
                                mfx->ns = ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("xmlns")));
+                       }
                        if (xmlTextReaderGetAttribute(reader, XMLCHAR("package"))) {
                                mfx->package= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("package")));
                                if (mfx->package == NULL) {
@@ -4321,7 +4277,6 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                        }
                        if (xmlTextReaderGetAttribute(reader, XMLCHAR("url")))
                                mfx->package_url= ASCII(xmlTextReaderGetAttribute(reader, XMLCHAR("url")));
-
                        /*Assign default values. If required it will be overwritten in __add_preload_info()*/
                        mfx->preload = strdup("False");
                        mfx->removable = strdup("True");
@@ -4335,10 +4290,9 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
                        snprintf(buf, PKG_STRING_LEN_MAX - 1, "%d", current_time);
                        val = strndup(buf, PKG_STRING_LEN_MAX - 1);
                        mfx->installed_time = val;
-
                        mfx->installed_storage= strdup("installed_internal");
 
-                       ret = __start_process(reader, mfx);
+                       ret = __start_process(reader, mfx, uid);
                } else {
                        _LOGD("No Manifest element found\n");
                        return -1;
@@ -4347,38 +4301,6 @@ static int __process_manifest(xmlTextReaderPtr reader, manifest_x * mfx)
        return ret;
 }
 
-static const char* getUserDesktopPath(void)
-{
-       const char* desktop_path;
-       if(getuid() > 0)
-  {
-    desktop_path = tzplatform_mkpath(TZ_USER_HOME, ".applications/desktop/");
-  }
-  else
-  {
-    desktop_path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
-  }
-
-  _LOGD("uid: [%d] / desktop_path: [%s]\n", getuid(), desktop_path);
-  return desktop_path;
-}
-
-static const char* getUserManifestPath(void)
-{
-       const char* manifest_path;
-       if(getuid() > 0)
-  {
-    manifest_path = tzplatform_mkpath(TZ_USER_HOME, ".config/xwalk-service/applications/");
-  }
-  else
-  {
-    manifest_path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
-  }
-
-  _LOGD("uid: [%d] / manifest_path: [%s]\n", getuid(), manifest_path);
-  return manifest_path;
-}
-
 static char* __convert_to_system_locale(const char *mlocale)
 {
        if (mlocale == NULL)
@@ -4409,10 +4331,9 @@ typedef enum {
        AIL_MAX
 } AIL_TYPE;
 
-static int __ail_change_info(int op, const char *appid)
+static int __ail_change_info(int op, const char *appid, uid_t uid)
 {
        void *lib_handle = NULL;
-       int (*ail_desktop_operation) (const char *);
        char *aop = NULL;
        int ret = 0;
 
@@ -4420,37 +4341,70 @@ static int __ail_change_info(int op, const char *appid)
                _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
                goto END;
        }
+//is_admin
+       if(uid != GLOBAL_USER)
+       {
+               int (*ail_desktop_operation) (const char *, uid_t uid);
+               switch (op) {
+                       case 0:
+                               aop  = "ail_usr_desktop_add";
+                               break;
+                       case 1:
+                               aop  = "ail_usr_desktop_update";
+                               break;
+                       case 2:
+                               aop  = "ail_usr_desktop_remove";
+                               break;
+                       case 3:
+                               aop  = "ail_usr_desktop_clean";
+                               break;
+                       case 4:
+                               aop  = "ail_usr_desktop_fota";
+                               break;
+                       default:
+                               goto END;
+                               break;
+               }
 
-
-       switch (op) {
-               case 0:
-                       aop  = "ail_desktop_add";
-                       break;
-               case 1:
-                       aop  = "ail_desktop_update";
-                       break;
-               case 2:
-                       aop  = "ail_desktop_remove";
-                       break;
-               case 3:
-                       aop  = "ail_desktop_clean";
-                       break;
-               case 4:
-                       aop  = "ail_desktop_fota";
-                       break;
-               default:
+               if ((ail_desktop_operation =
+                       dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
+                       _LOGE("can not find symbol \n");
                        goto END;
-                       break;
-       }
+               }
 
-       if ((ail_desktop_operation =
-            dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
-               _LOGE("can not find symbol \n");
-               goto END;
-       }
+               ret = ail_desktop_operation(appid, uid);
+       }else{
+               int (*ail_desktop_operation) (const char *);
+               switch (op) {
+                       case 0:
+                               aop  = "ail_desktop_add";
+                               break;
+                       case 1:
+                               aop  = "ail_desktop_update";
+                               break;
+                       case 2:
+                               aop  = "ail_desktop_remove";
+                               break;
+                       case 3:
+                               aop  = "ail_desktop_clean";
+                               break;
+                       case 4:
+                               aop  = "ail_desktop_fota";
+                               break;
+                       default:
+                               goto END;
+                               break;
+               }
 
-       ret = ail_desktop_operation(appid);
+               if ((ail_desktop_operation =
+                       dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
+                       _LOGE("can not find symbol \n");
+                       goto END;
+               }
+
+               ret = ail_desktop_operation(appid);
 
+       }
 END:
        if (lib_handle)
                dlclose(lib_handle);
@@ -4458,11 +4412,10 @@ END:
        return ret;
 }
 
-
 /* desktop shoud be generated automatically based on manifest */
 /* Currently removable, taskmanage, etc fields are not considerd. it will be decided soon.*/
 #define BUFMAX 1024*128
-static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, ACTION_TYPE action)
+static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, ACTION_TYPE action, uid_t uid)
 {
         FILE* file = NULL;
         int fd = 0;
@@ -4485,20 +4438,20 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, A
        }
 
        if (action == ACTION_UPGRADE)
-               __ail_change_info(AIL_CLEAN, mfx->package);
+               __ail_change_info(AIL_CLEAN, mfx->package, uid);
 
        for(; mfx->uiapplication; mfx->uiapplication=mfx->uiapplication->next) {
 
                if (manifest != NULL) {
                        /* skip making a deskfile and update ail, if preload app is updated */
-                       if(strstr(manifest, getUserManifestPath())) {
-                               __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
+                       if(strstr(manifest, getUserManifestPath(uid))) {
+                               __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid, uid);
                    _LOGE("preload app is update : skip and update ail : %s", manifest);
                                continue;
                        }
                }
 
-               snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(), mfx->uiapplication->appid);
+               snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(uid), mfx->uiapplication->appid);
 
                /* skip if desktop exists
                if (access(filepath, R_OK) == 0)
@@ -4814,9 +4767,9 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, A
                fsync(fd);
                fclose(file);
                if (action == ACTION_FOTA)
-                       __ail_change_info(AIL_FOTA, mfx->uiapplication->appid);
+                       __ail_change_info(AIL_FOTA, mfx->uiapplication->appid, uid);
                else
-                       __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid);
+                       __ail_change_info(AIL_INSTALL, mfx->uiapplication->appid, uid);
        }
 
        free(buf);
@@ -4825,16 +4778,16 @@ static int __ps_make_nativeapp_desktop(manifest_x * mfx, const char *manifest, A
         return 0;
 }
 
-static int __ps_remove_nativeapp_desktop(manifest_x *mfx)
+static int __ps_remove_nativeapp_desktop(manifest_x *mfx, uid_t uid)
 {
        char filepath[PKG_STRING_LEN_MAX] = "";
        int ret = 0;
        uiapplication_x *uiapplication = mfx->uiapplication;
 
        for(; uiapplication; uiapplication=uiapplication->next) {
-               snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(), uiapplication->appid);
+               snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(uid), uiapplication->appid);
 
-               __ail_change_info(AIL_REMOVE, uiapplication->appid);
+               __ail_change_info(AIL_REMOVE, uiapplication->appid, uid);
 
                ret = remove(filepath);
                if (ret <0)
@@ -4878,13 +4831,13 @@ END:
 }
 
 #define PRELOAD_PACKAGE_LIST SYSCONFDIR "/package-manager/preload/preload_list.txt"
-static int __add_preload_info(manifest_x * mfx, const char *manifest)
+static int __add_preload_info(manifest_x * mfx, const char *manifest, uid_t uid)
 {
        FILE *fp = NULL;
        char buffer[1024] = { 0 };
        int state = 0;
 
-       if(strstr(manifest, getUserManifestPath())) {
+       if(strstr(manifest, getUserManifestPath(uid))) {
                free((void *)mfx->readonly);
                mfx->readonly = strdup("True");
 
@@ -4943,16 +4896,16 @@ static int __add_preload_info(manifest_x * mfx, const char *manifest)
        return 0;
 }
 
-static int __check_preload_updated(manifest_x * mfx, const char *manifest)
+static int __check_preload_updated(manifest_x * mfx, const char *manifest, uid_t uid)
 {
        char filepath[PKG_STRING_LEN_MAX] = "";
        int ret = 0;
        uiapplication_x *uiapplication = mfx->uiapplication;
 
-       if(strstr(manifest, getUserManifestPath())) {
+       if(strstr(manifest, getUserManifestPath(uid))) {
                /* if preload app is updated, then remove previous desktop file on RW*/
                for(; uiapplication; uiapplication=uiapplication->next) {
-                               snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(), uiapplication->appid);
+                               snprintf(filepath, sizeof(filepath),"%s%s.desktop", getUserDesktopPath(uid), uiapplication->appid);
                        ret = remove(filepath);
                        if (ret <0)
                                return -1;
@@ -4974,7 +4927,7 @@ API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
                _LOGD("Manifest pointer is NULL\n");
                return -1;
        }
-        ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL);
+        ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL, GLOBAL_USER);
         if (ret == -1)
                 _LOGD("Creating desktop file failed\n");
         else
@@ -4982,6 +4935,22 @@ API int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
         return ret;
 }
 
+API int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
+{
+        int ret = 0;
+       if (mfx == NULL) {
+               _LOGD("Manifest pointer is NULL\n");
+               return -1;
+       }
+        ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL, uid);
+        if (ret == -1)
+                _LOGD("Creating desktop file failed\n");
+        else
+                _LOGD("Creating desktop file Success\n");
+        return ret;
+}
+
+
 API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
 {
        if (mfx == NULL)
@@ -5218,7 +5187,35 @@ API void pkgmgr_parser_free_manifest_xml(manifest_x *mfx)
 
 API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
 {
-       _LOGD("parsing start\n");
+       _LOGD("parsing start pkgmgr_parser_process_manifest_xml\n");
+       xmlTextReaderPtr reader;
+       manifest_x *mfx = NULL;
+
+       reader = xmlReaderForFile(manifest, NULL, 0);
+       if (reader) {
+               mfx = malloc(sizeof(manifest_x));
+               if (mfx) {
+                       memset(mfx, '\0', sizeof(manifest_x));
+                       if (__process_manifest(reader, mfx, GLOBAL_USER) < 0) {
+                               _LOGD("Parsing Failed\n");
+                               pkgmgr_parser_free_manifest_xml(mfx);
+                               mfx = NULL;
+                       } else
+                               _LOGD("Parsing Success\n");
+               } else {
+                       _LOGD("Memory allocation error\n");
+               }
+               xmlFreeTextReader(reader);
+       } else {
+               _LOGD("Unable to create xml reader\n");
+       }
+       return mfx;
+}
+
+
+API manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
+{
+       _LOGD("parsing start pkgmgr_parser_usr_process_manifest_xml\n");
        xmlTextReaderPtr reader;
        manifest_x *mfx = NULL;
 
@@ -5227,7 +5224,7 @@ API manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
                mfx = malloc(sizeof(manifest_x));
                if (mfx) {
                        memset(mfx, '\0', sizeof(manifest_x));
-                       if (__process_manifest(reader, mfx) < 0) {
+                       if (__process_manifest(reader, mfx, uid) < 0) {
                                _LOGD("Parsing Failed\n");
                                pkgmgr_parser_free_manifest_xml(mfx);
                                mfx = NULL;
@@ -5262,7 +5259,7 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
 
 //     __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
        __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
-       __add_preload_info(mfx, manifest);
+       __add_preload_info(mfx, manifest, GLOBAL_USER);
 
        _LOGD("Added preload infomation\n");
 
@@ -5282,9 +5279,9 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
                _LOGD("Creating category parser failed\n");
 
        if (__check_action_fota(tagv))
-               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_FOTA);
+               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_FOTA, GLOBAL_USER);
        else
-               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL);
+               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL, GLOBAL_USER);
 
        if (ret == -1)
                _LOGD("Creating desktop file failed\n");
@@ -5297,13 +5294,58 @@ API int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char
 
        return PMINFO_R_OK;
 }
+API int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
+{
+//     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("parsing manifest for installation: %s\n", manifest);
+       manifest_x *mfx = NULL;
+       int ret = -1;
+
+       xmlInitParser();
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+
+       _LOGD("Parsing Finished\n");
+//     __streamFile(manifest, ACTION_INSTALL, temp, mfx->package);
+       __ps_process_tag_parser(mfx, manifest, ACTION_INSTALL);
+       __add_preload_info(mfx, manifest, uid);
+
+       _LOGD("Added preload infomation\n");
+       __ps_process_tag(mfx, tagv);
+
+       ret = pkgmgr_parser_insert_manifest_info_in_usr_db(mfx, uid);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+
+       _LOGD("DB Insert Success\n");
+       ret = __ps_process_metadata_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating metadata parser failed\n");
+       ret = __ps_process_category_parser(mfx, ACTION_INSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+
+       if (__check_action_fota(tagv))
+               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_FOTA, uid);
+       else
+               ret = __ps_make_nativeapp_desktop(mfx, NULL, ACTION_INSTALL, uid);
+
+       if (ret == -1)
+               _LOGD("Creating desktop file failed\n");
+       else
+               _LOGD("Creating desktop file Success\n");
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
+}
 
 API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
 {
 //     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
        retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
-       _LOGD("parsing manifest for upgradation: %s\n", manifest);
-
+       _LOGD("pkgmgr_parser_parse_manifest_for_upgrade  parsing manifest for upgradation: %s\n", manifest);
        manifest_x *mfx = NULL;
        int ret = -1;
        bool preload = false;
@@ -5316,17 +5358,15 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
 
        _LOGD("Parsing Finished\n");
-
 //     __streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
        __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
-       __add_preload_info(mfx, manifest);
+       __add_preload_info(mfx, manifest, GLOBAL_USER);
        _LOGD("Added preload infomation\n");
-       __check_preload_updated(mfx, manifest);
+       __check_preload_updated(mfx, manifest, GLOBAL_USER);
 
        ret = pkgmgrinfo_pkginfo_get_pkginfo(mfx->package, &handle);
        if (ret != PMINFO_R_OK)
                _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
-
        ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
        if (ret != PMINFO_R_OK)
                _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
@@ -5339,7 +5379,6 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
        if (ret != PMINFO_R_OK)
                _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
-
        if (system) {
                free((void *)mfx->system);
                mfx->system = strdup("true");
@@ -5348,7 +5387,7 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
        if (ret != PMINFO_R_OK)
                _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
-
+       
        if (csc_path != NULL) {
                if (mfx->csc_path)
                        free((void *)mfx->csc_path);
@@ -5358,21 +5397,95 @@ API int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *con
        ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
        retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
        _LOGD("DB Update Success\n");
+       ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1){
+               _LOGD("Upgrade metadata parser failed\n");
+       }
+       ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+       ret = __ps_make_nativeapp_desktop(mfx, manifest, ACTION_UPGRADE, GLOBAL_USER);
+       if (ret == -1)
+               _LOGD("Creating desktop file failed\n");
+       else
+               _LOGD("Creating desktop file Success\n");
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[])
+{
+//     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD(" pkgmgr_parser_parse_usr_manifest_for_upgrade parsing manifest for upgradation: %s\n", manifest);
+       manifest_x *mfx = NULL;
+       int ret = -1;
+       bool preload = false;
+       bool system = false;
+       char *csc_path = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       xmlInitParser();
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+
+       _LOGD("Parsing Finished\n");
+       //__streamFile(manifest, ACTION_UPGRADE, temp, mfx->package);
+       __ps_process_tag_parser(mfx, manifest, ACTION_UPGRADE);
+       __add_preload_info(mfx, manifest, uid);
+       _LOGD("Added preload infomation\n");
+       _LOGE("Added preload infomation\n");
+       __check_preload_updated(mfx, manifest, uid);
+
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(mfx->package, uid, &handle);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_pkginfo failed\n");
+       ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_preload failed\n");
+
+       if (preload) {
+               free((void *)mfx->preload);
+               mfx->preload = strdup("true");
+       }
+
+       ret = pkgmgrinfo_pkginfo_is_system(handle, &system);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_is_system failed\n");
+
+       if (system) {
+               free((void *)mfx->system);
+               mfx->system = strdup("true");
+       }
 
+       ret = pkgmgrinfo_pkginfo_get_csc_path(handle, &csc_path);
+       if (ret != PMINFO_R_OK)
+               _LOGD("pkgmgrinfo_pkginfo_get_csc_path failed\n");
+       if (csc_path != NULL) {
+               if (mfx->csc_path)
+                       free((void *)mfx->csc_path);
+               mfx->csc_path = strdup(csc_path);
+       }
+
+       ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
+       retvm_if(ret == PMINFO_R_ERROR, PMINFO_R_ERROR, "DB Insert failed");
+       _LOGD("DB Update Success\n");
+       _LOGE("DB Update Success\n" );
        ret = __ps_process_metadata_parser(mfx, ACTION_UPGRADE);
        if (ret == -1)
                _LOGD("Upgrade metadata parser failed\n");
-
        ret = __ps_process_category_parser(mfx, ACTION_UPGRADE);
        if (ret == -1)
                _LOGD("Creating category parser failed\n");
-
-       ret = __ps_make_nativeapp_desktop(mfx, manifest, ACTION_UPGRADE);
+       ret = __ps_make_nativeapp_desktop(mfx, manifest, ACTION_UPGRADE, GLOBAL_USER);
        if (ret == -1)
                _LOGD("Creating desktop file failed\n");
        else
                _LOGD("Creating desktop file Success\n");
-
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
        pkgmgr_parser_free_manifest_xml(mfx);
        _LOGD("Free Done\n");
@@ -5398,7 +5511,7 @@ API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, ch
 //     __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
        __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
 
-       __add_preload_info(mfx, manifest);
+       __add_preload_info(mfx, manifest, GLOBAL_USER);
        _LOGD("Added preload infomation\n");
 
        ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
@@ -5415,7 +5528,61 @@ API int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, ch
        else
                _LOGD("DB Delete Success\n");
 
-       ret = __ps_remove_nativeapp_desktop(mfx);
+       ret = __ps_remove_nativeapp_desktop(mfx, GLOBAL_USER);
+       if (ret == -1)
+               _LOGD("Removing desktop file failed\n");
+       else
+               _LOGD("Removing desktop file Success\n");
+
+       ret = __ps_remove_appsvc_db(mfx);
+       if (ret == -1)
+               _LOGD("Removing appsvc_db failed\n");
+       else
+               _LOGD("Removing appsvc_db Success\n");
+
+       pkgmgr_parser_free_manifest_xml(mfx);
+       _LOGD("Free Done\n");
+       xmlCleanupParser();
+
+       return PMINFO_R_OK;
+}
+
+
+API int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
+{
+//     char *temp[] = {"shortcut-list", "livebox", "account", "notifications", "privileges", "ime", "font", NULL};
+       retvm_if(manifest == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+       _LOGD("parsing manifest for uninstallation: %s\n", manifest);
+
+       manifest_x *mfx = NULL;
+       int ret = -1;
+       xmlInitParser();
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       retvm_if(mfx == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
+
+       _LOGD("Parsing Finished\n");
+
+//     __streamFile(manifest, ACTION_UNINSTALL, temp, mfx->package);
+       __ps_process_tag_parser(mfx, manifest, ACTION_UNINSTALL);
+
+       __add_preload_info(mfx, manifest, GLOBAL_USER);
+       _LOGD("Added preload infomation\n");
+
+       ret = __ps_process_metadata_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _LOGD("Removing metadata parser failed\n");
+
+       ret = __ps_process_category_parser(mfx, ACTION_UNINSTALL);
+       if (ret == -1)
+               _LOGD("Creating category parser failed\n");
+
+       ret = pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, uid);
+       if (ret == -1)
+               _LOGD("DB Delete failed\n");
+       else
+               _LOGD("DB Delete Success\n");
+
+       ret = __ps_remove_nativeapp_desktop(mfx, uid);
        if (ret == -1)
                _LOGD("Removing desktop file failed\n");
        else
@@ -5439,9 +5606,20 @@ API int pkgmgr_parser_parse_manifest_for_preload()
        return pkgmgr_parser_update_preload_info_in_db();
 }
 
+API int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
+{
+       return pkgmgr_parser_update_preload_info_in_usr_db(uid);
+}
+
+
+API char *pkgmgr_parser_get_usr_manifest_file(const char *pkgid, uid_t uid)
+{
+       return __pkgid_to_manifest(pkgid, uid);
+}
+
 API char *pkgmgr_parser_get_manifest_file(const char *pkgid)
 {
-       return __pkgid_to_manifest(pkgid);
+       return __pkgid_to_manifest(pkgid, GLOBAL_USER);
 }
 
 API int pkgmgr_parser_run_parser_for_installation(xmlDocPtr docPtr, const char *tag, const char *pkgid)
index 03a1fe2..789e574 100755 (executable)
@@ -57,6 +57,8 @@ extern "C" {
 #define PKG_STRING_LEN_MAX 1024
 
 #define PKGMGR_PARSER_EMPTY_STR                ""
+#define GLOBAL_USER    0 //#define     tzplatform_getenv(TZ_GLOBAL) //TODO
+
 
 /**
  * @brief List definitions.
@@ -489,13 +491,27 @@ typedef struct manifest_x {
        struct deviceprofile_x *deviceprofile;          /**< package device profile*/
 } manifest_x;
 
-/* For multiuser support */
-char *getUserDBLabel(void);
-char *getUserPkgParserDBPath(void);
-char *getUserPkgParserDBPathUID(uid_t uid);
-char *getUserPkgParserJournalDBPath(void);
-char *getUserPkgCertDBPath(void);
-char *getUserPkgCertJournalDBPath(void);
+/*enum uid_value {
+       ROOT,
+       GLOBAL,
+       USER
+};*/
+
+/**uid check
+ * 
+ */
+/* int check_uid(uid_t uid)
+ {
+        switch(uid)
+        {
+               case GLOBAL_USER: return GLOBAL;
+               case 0: return ROOT;
+               default: goto user; break;
+       }
+user:
+cf getdbpath
+*/
 
 /**
  * @fn char *pkgmgr_parser_get_manifest_file(const char *pkgid)
@@ -525,12 +541,14 @@ char *pkgmgr_parser_get_manifest_file(const char *pkgid);
 
 /**
  * @fn int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[])
+ * @fn int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[])
  * @brief      This API parses the manifest file of the package after installation and stores the data in DB.
  *
  * @par                This API is for package-manager installer backends.
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  manifest        pointer to package manifest file
+ * @param[in]  uid     the addressee user id of the instruction
  * @param[in]  tagv            array of xml tags or NULL
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
@@ -550,8 +568,10 @@ static int parse_manifest_file_for_installation(const char *manifest)
  * @endcode
  */
 int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *const tagv[]);
+int pkgmgr_parser_parse_usr_manifest_for_installation(const char *manifest, uid_t uid, char *const tagv[]);
 
 /**
+ * @fn int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest,  uid_t uid, char *const tagv[])
  * @fn int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[])
  * @brief      This API parses the manifest file of the package after upgrade and stores the data in DB.
  *
@@ -559,6 +579,7 @@ int pkgmgr_parser_parse_manifest_for_installation(const char *manifest, char *co
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  manifest        pointer to package manifest file
+ * @param[in]  uid     the addressee user id of the instruction
  * @param[in]  tagv            array of xml tags or NULL
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
@@ -578,15 +599,17 @@ static int parse_manifest_file_for_upgrade(const char *manifest)
  * @endcode
  */
 int pkgmgr_parser_parse_manifest_for_upgrade(const char *manifest, char *const tagv[]);
-
+int pkgmgr_parser_parse_usr_manifest_for_upgrade(const char *manifest, uid_t uid, char *const tagv[]);
 /**
  * @fn int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[])
+ * @fn int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[])
  * @brief      This API parses the manifest file of the package after uninstallation and deletes the data from DB.
  *
  * @par                This API is for package-manager installer backends.
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  manifest        pointer to package manifest file
+ * @param[in]  uid     the addressee user id of the instruction
  * @param[in]  tagv            array of xml tags or NULL
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
@@ -606,9 +629,10 @@ static int parse_manifest_file_for_uninstallation(const char *manifest)
  * @endcode
  */
 int pkgmgr_parser_parse_manifest_for_uninstallation(const char *manifest, char *const tagv[]);
-
+int pkgmgr_parser_parse_usr_manifest_for_uninstallation(const char *manifest, uid_t uid, char *const tagv[]);
 /**
  * @fn int pkgmgr_parser_parse_manifest_for_preload()
+ * @fn int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid)
  * @brief      This API update  preload information to DB.
  *
  * @par                This API is for package-manager installer backends.
@@ -632,6 +656,7 @@ static int parser_parse_manifest_for_preload()
  * @endcode
  */
 int pkgmgr_parser_parse_manifest_for_preload();
+int pkgmgr_parser_parse_usr_manifest_for_preload(uid_t uid);
 
 /**
  * @fn int pkgmgr_parser_check_manifest_validation(const char *manifest)
@@ -687,12 +712,14 @@ void pkgmgr_parser_free_manifest_xml(manifest_x *mfx);
 
 /**
  * @fn manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest)
+ * @fn manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid)
  * @brief      This API parses the manifest file and stores all the data in the manifest structure.
  *
  * @par                This API is for package-manager installer backends.
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  manifest        pointer to package manifest file
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     manifest pointer on success, NULL on failure
  * @pre                None
  * @post               pkgmgr_parser_free_manifest_xml()
@@ -710,6 +737,7 @@ static int parse_manifest_file(const char *manifest)
  * @endcode
  */
 manifest_x *pkgmgr_parser_process_manifest_xml(const char *manifest);
+manifest_x *pkgmgr_parser_usr_process_manifest_xml(const char *manifest, uid_t uid);
 
 /**
  * @fn manifest_x *pkgmgr_parser_get_manifest_info(const char *pkigid)
@@ -834,12 +862,14 @@ int pkgmgr_parser_run_parser_for_uninstallation(xmlDocPtr docPtr, const char *ta
 
 /**
  * @fn int pkgmgr_parser_create_desktop_file(manifest_x *mfx)
+ * @fn int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid)
  * @brief      This API generates the application desktop file
  *
  * @par                This API is for package-manager installer backends.
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  mfx     manifest pointer
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @retval     PMINFO_R_OK     success
  * @retval     PMINFO_R_EINVAL invalid argument
@@ -861,6 +891,7 @@ static int create_desktop_file(char *manifest)
  * @endcode
  */
 int pkgmgr_parser_create_desktop_file(manifest_x *mfx);
+int pkgmgr_parser_create_usr_desktop_file(manifest_x *mfx, uid_t uid);
 
 /** @} */
 #ifdef __cplusplus
index 1109b5f..e02262b 100755 (executable)
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <db-util.h>
 #include <glib.h>
+#include <grp.h>
 
 /* For multi-user support */
 #include <tzplatform_config.h>
@@ -46,6 +47,8 @@
 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
 #define MAX_QUERY_LEN          4096
+#define BUFSIZE 4096
+#define OWNER_ROOT 0
 
 sqlite3 *pkgmgr_parser_db;
 sqlite3 *pkgmgr_cert_db;
@@ -73,7 +76,7 @@ sqlite3 *pkgmgr_cert_db;
                                                "mainapp_id text," \
                                                "package_url text," \
                                                "root_path text," \
-                                               "csc_path text)"
+                                               "csc_path text )"
 
 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
                                                "(package text not null, " \
@@ -240,6 +243,7 @@ sqlite3 *pkgmgr_cert_db;
                                                "dist2_signer_cert integer, " \
                                                "PRIMARY KEY(package)) "
 
+
 static int __insert_uiapplication_info(manifest_x *mfx);
 static int __insert_serviceapplication_info(manifest_x *mfx);
 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
@@ -269,7 +273,8 @@ static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
-static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
+static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
+static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
 
 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
 {
@@ -289,10 +294,12 @@ static char *__get_str(const char *str)
        return str;
 }
 
-static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
+static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
 {
        int ret = -1;
        sqlite3 *handle;
+       char *pk, key1, key2, key3, key4, key5;
+
        if (access(db_path, F_OK) == 0) {
                ret =
                    db_util_open(db_path, &handle,
@@ -303,7 +310,39 @@ static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
                        return -1;
                }
                *db_handle = handle;
-               return 0;
+
+       }
+       _LOGD("%s DB does not exists. Create one!!\n", db_path);
+
+       ret =
+           db_util_open(db_path, &handle,
+                        DB_UTIL_REGISTER_HOOK_METHOD);
+
+       if (ret != SQLITE_OK) {
+               _LOGD("connect db [%s] failed!\n", db_path);
+               return -1;
+       }
+       *db_handle = handle;
+       
+       return 0;
+}
+
+static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
+{
+       int ret = -1;
+       sqlite3 *handle;
+
+       if (access(db_path, F_OK) == 0) {
+               ret =
+                   db_util_open(db_path, &handle,
+                                DB_UTIL_REGISTER_HOOK_METHOD);
+               if (ret != SQLITE_OK) {
+                       _LOGD("connect db [%s] failed!\n",
+                              db_path);
+                       return -1;
+               }
+               *db_handle = handle;
+
        }
        _LOGD("%s DB does not exists. Create one!!\n", db_path);
 
@@ -316,6 +355,7 @@ static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
                return -1;
        }
        *db_handle = handle;
+
        return 0;
 }
 
@@ -1549,7 +1589,6 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
                if (ath->href)
                        auth_href = ath->href;
        }
-
        /*Insert in the package_info DB*/
        if (mfx->type)
                type = strdup(mfx->type);
@@ -1566,7 +1605,6 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
                        apps_path = tzplatform_getenv(TZ_USER_APP);
                        snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
                }
-
                path = strdup(root);
        }
        snprintf(query, MAX_QUERY_LEN,
@@ -1596,7 +1634,6 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
                 __get_str(mfx->package_url),
                 path,
                 __get_str(mfx->csc_path));
-
        /*If package dont have main_package tag, this package is main package.*/
        if (mfx->main_package == NULL) {
                ret = __exec_query(query);
@@ -1743,7 +1780,6 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
        g_list_free(appimage);
        appimage = NULL;
 
-
        /*Insert in the package_app_info DB*/
        ret = __insert_uiapplication_info(mfx);
        if (ret == -1)
@@ -1751,7 +1787,6 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
        ret = __insert_serviceapplication_info(mfx);
        if (ret == -1)
                return -1;
-
        /*Insert in the package_app_app_control DB*/
        ret = __insert_uiapplication_appcontrol_info(mfx);
        if (ret == -1)
@@ -1772,7 +1807,7 @@ static int __insert_manifest_info_in_db(manifest_x *mfx)
        ret = __insert_uiapplication_appmetadata_info(mfx);
        if (ret == -1)
                return -1;
-       ret = __insert_serviceapplication_appmetadata_info(mfx);
+       ret = __insert_uiapplication_appmetadata_info(mfx);
        if (ret == -1)
                return -1;
 
@@ -2110,22 +2145,74 @@ int pkgmgr_parser_initialize_db()
        return 0;
 }
 
-int pkgmgr_parser_check_and_create_db()
+static int parserdb_change_perm(const char *db_file)
+{
+       char buf[BUFSIZE];
+       char journal_file[BUFSIZE];
+       char *files[3];
+       int ret, i;
+       struct group *grpinfo = NULL;
+       files[0] = (char *)db_file;
+       files[1] = journal_file;
+       files[2] = NULL;
+
+       const char *name = "users";
+
+       if(db_file == NULL)
+               return -1;
+       if(db_file == NULL)
+               return -1;
+
+       snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
+       grpinfo = getgrnam(name);
+       if(grpinfo == NULL){
+               _LOGD("getgrnam(users) returns NULL !");
+       }
+       for (i = 0; files[i]; i++) {
+               ret = chown(files[i], OWNER_ROOT, (gid_t)grpinfo->gr_gid);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _LOGD("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, grpinfo->gr_gid, buf);
+                       return -1;
+               }
+
+               ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+int pkgmgr_parser_check_and_create_db(uid_t uid)
 {
        int ret = -1;
        /*Manifest DB*/
-       ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPath());
-       _LOGD("create db  %s", getUserPkgParserDBPath());
+       ret = __pkgmgr_parser_create_parser_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid), uid);
+       _LOGD("create db  %s", getUserPkgParserDBPathUID(uid));
        if (ret) {
                _LOGD("Manifest DB creation Failed\n");
                return -1;
        }
+       if(uid != GLOBAL_USER) {
+         if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid))) {
+               _LOGD("Failed to change permission\n");
+         }
+    }
        /*Cert DB*/
-       ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPath());
+       ret = __pkgmgr_parser_create_cert_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid), uid);
        if (ret) {
                _LOGD("Cert DB creation Failed\n");
                return -1;
        }
+       if(uid != GLOBAL_USER) {
+         if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid))) {
+               _LOGD("Failed to change permission\n");
+         }
+    }
        return 0;
 }
 
@@ -2135,6 +2222,7 @@ void pkgmgr_parser_close_db()
        sqlite3_close(pkgmgr_cert_db);
 }
 
+
 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
 {
        _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
@@ -2143,7 +2231,7 @@ API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
                return -1;
        }
        int ret = 0;
-       ret = pkgmgr_parser_check_and_create_db();
+       ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGD("Failed to open DB\n");
                return ret;
@@ -2179,6 +2267,49 @@ err:
        return ret;
 }
 
+API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
+{
+       _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
+       if (mfx == NULL) {
+               _LOGD("manifest pointer is NULL\n");
+               return -1;
+       }
+       int ret = 0;
+       ret = pkgmgr_parser_check_and_create_db(uid);
+       if (ret == -1) {
+               _LOGD("Failed to open DB\n");
+               return ret;
+       }
+       ret = pkgmgr_parser_initialize_db();
+       if (ret == -1)
+               goto err;
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction\n");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin\n");
+       ret = __insert_manifest_info_in_db(mfx);
+       if (ret == -1) {
+               _LOGD("Insert into DB failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to commit transaction. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End\n");
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+}
 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
 {
        if (mfx == NULL) {
@@ -2186,7 +2317,7 @@ API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
                return -1;
        }
        int ret = 0;
-       ret = pkgmgr_parser_check_and_create_db();
+       ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGD("Failed to open DB\n");
                return ret;
@@ -2231,6 +2362,59 @@ err:
        return ret;
 }
 
+API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
+{
+       if (mfx == NULL) {
+               _LOGD("manifest pointer is NULL\n");
+               return -1;
+       }
+       int ret = 0;
+       ret = pkgmgr_parser_check_and_create_db(uid);
+       if (ret == -1) {
+               _LOGD("Failed to open DB\n");
+               return ret;
+       }
+       ret = pkgmgr_parser_initialize_db();
+       if (ret == -1)
+               goto err;
+       /*Preserve guest mode visibility*/
+       __preserve_guestmode_visibility_value( mfx);
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction\n");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin\n");
+       ret = __delete_manifest_info_from_db(mfx);
+       if (ret == -1) {
+               _LOGD("Delete from DB failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+       ret = __insert_manifest_info_in_db(mfx);
+       if (ret == -1) {
+               _LOGD("Insert into DB failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to commit transaction. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End\n");
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+}
+
+
 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
 {
        if (mfx == NULL) {
@@ -2238,7 +2422,47 @@ API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
                return -1;
        }
        int ret = 0;
-       ret = pkgmgr_parser_check_and_create_db();
+       ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
+       if (ret == -1) {
+               _LOGD("Failed to open DB\n");
+               return ret;
+       }
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction\n");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin\n");
+       ret = __delete_manifest_info_from_db(mfx);
+       if (ret == -1) {
+               _LOGD("Delete from DB failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to commit transaction, Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End\n");
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+}
+
+API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
+{
+       if (mfx == NULL) {
+               _LOGD("manifest pointer is NULL\n");
+               return -1;
+       }
+       int ret = 0;
+       ret = pkgmgr_parser_check_and_create_db(uid);
        if (ret == -1) {
                _LOGD("Failed to open DB\n");
                return ret;
@@ -2274,7 +2498,7 @@ err:
 API int pkgmgr_parser_update_preload_info_in_db()
 {
        int ret = 0;
-       ret = pkgmgr_parser_check_and_create_db();
+       ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGD("Failed to open DB\n");
                return ret;
@@ -2307,3 +2531,38 @@ err:
        return ret;
 }
 
+API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
+{
+       int ret = 0;
+       ret = pkgmgr_parser_check_and_create_db(uid);
+       if (ret == -1) {
+               _LOGD("Failed to open DB\n");
+               return ret;
+       }
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction\n");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin\n");
+       ret = __update_preload_condition_in_db();
+       if (ret == -1) {
+               _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to commit transaction, Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End\n");
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+}
index 7dd2975..4c2e583 100755 (executable)
@@ -46,8 +46,8 @@
 extern "C" {
 #endif
 #include "pkgmgr_parser.h"
-
 /**
+ * @fn int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
  * @fn int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
  * @brief      This API inserts the parsed manifest info in db
  *
@@ -55,6 +55,7 @@ extern "C" {
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  mfx     pointer to manifest info
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @pre                None
  * @post               None
@@ -72,15 +73,18 @@ static int insert_manifest_data(manifest_x *mfx)
  * @endcode
  */
 int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx);
+int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid);
 
 /**
  * @fn int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
+ * @fn int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
  * @brief      This API updates the manifest info in db
  *
  * @par                This API is for package-manager installer backends
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  mfx     pointer to manifest info
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @pre                None
  * @post               None
@@ -98,8 +102,10 @@ static int update_manifest_data(manifest_x *mfx)
  * @endcode
  */
 int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx);
+int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid);
 
 /**
+ * @fn int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
  * @fn int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
  * @brief      This API deletes the parsed manifest info from db
  *
@@ -107,6 +113,7 @@ int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx);
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  mfx     pointer to manifest info
+ * @param[in]  uid     the addressee user id of the instruction
  * @return     0 if success, error code(<0) if fail
  * @pre                None
  * @post               None
@@ -124,10 +131,15 @@ static int delete_manifest_data(manifest_x *mfx)
  * @endcode
  */
 int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx);
+int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid);
 
 int pkgmgr_parser_update_preload_info_in_db();
-int pkgmgr_parser_check_and_create_db();
+int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid);
+int pkgmgr_parser_check_and_create_db(uid_t uid);
 int pkgmgr_parser_initialize_db();
+
+
+
 /** @} */
 #ifdef __cplusplus
 }
index 98f77a6..c05d86e 100755 (executable)
@@ -31,6 +31,8 @@
 #include <ctype.h>
 #include <assert.h>
 #include <dlfcn.h>
+#include <grp.h>
+#include <pwd.h>
 
 #include <libxml/parser.h>
 #include <libxml/xmlreader.h>
@@ -70,6 +72,7 @@
 #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 MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
@@ -258,12 +261,51 @@ typedef enum {
                                                "PRIMARY KEY(package)) "
 
 
+#define QUERY_ATTACH "attach database '%s' as Global"
+#define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select distinct * " \
+    "from (select  * from main.package_app_app_category  m union select * from  Global.package_app_app_category g WHERE m.app_id=g.app_id AND m.category=g.category)"
+#define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select distinct * "\
+    "from (select  * from main.package_app_info  m union select * from  Global.package_app_info g WHERE m.package=g.package)"
+#define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select distinct * "\
+    "from (select  * from main.package_app_app_control  m union select * from  Globalpackage_app_app_control g WHERE m.app_id=g.app_id AND m.operation=g.operation "\
+        "AND m.uri_scheme=guri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
+#define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select distinct * "\
+    "from (select  * from main.package_app_localized_info  m union select * from  Global.package_app_localized_info g WHERE m.app_id=g.app_id AND m.app_locale=g.app_locale)"
+#define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select distinct * "\
+    "from (select  * from main.package_app_app_metadata  m union select * from  Global.package_app_app_metadata g WHERE m.app_id=g.app_id AND m.md_key=g.md_key "\
+        "AND m.md_value=g.md_value)"
+#define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select distinct * "\
+    "from (select  * from main.package_app_share_allowed  m union select * from  Global.package_app_share_allowed g WHERE m.app_id=g.app_id AND m.data_share_path=g.data_share_path "\
+        "AND m.data_share_allowed=g.data_share_allowed)"
+#define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select distinct * "\
+    "from (select  * from main.package_app_app_permission  m union select * from  Global.package_app_app_permission g WHERE m.app_id=g.app_id AND m.pm_type=g.pm_type "\
+        "AND m.pm_value=g.pm_value)"
+#define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select distinct * "\
+    "from (select  * from main.package_app_share_request  m union select * from  Global.package_app_share_request g WHERE m.app_id=g.app_id AND m.data_share_request=g.data_share_request)"
+#define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select distinct * "\
+    "from (select  * from main.package_app_app_svc  m union select * from  Global.package_app_app_svc g WHERE m.app_id=g.app_id AND m.operation=g.operation "\
+        "AND m.uri_scheme=g.uri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
+#define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select distinct * "\
+    "from (select  * from main.package_info  m union select * from  Global.package_info g WHERE m.package=g.package)"
+#define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select distinct * "\
+    "from (select  * from main.package_app_icon_section_info  m union select * from  Global.package_app_icon_section_info g WHERE m.app_id=g.app_id "\
+        "AND m.app_icon_section=g.app_icon_section AND m.app_icon_resolution=g.app_icon_resolution)"
+#define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select distinct * "\
+    "from (select  * from main.package_localized_info  m union select * from  Global.package_localized_info g WHERE m.package=g.package AND m.package_locale=g.package_locale)"
+#define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select distinct * "\
+    "from (select  * from main.package_localized_info  m union select * from  Global.package_localized_info g WHERE m.app_id=g.app_id AND m.app_icon_section=g.app_icon_section "\
+        "AND m.app_icon_resolution=g.app_icon_resolution)"
+#define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select distinct * "\
+    "from (select  * from main.package_privilege_info  m union select * from  Global.package_privilege_info g WHERE m.package=g.package AND m.privilege=g.privilege)"  
+
+
+
 char *pkgtype = "rpm";
 __thread sqlite3 *manifest_db = NULL;
 __thread sqlite3 *datacontrol_db = NULL;
 __thread sqlite3 *cert_db = NULL;
 
-static int __open_manifest_db();
+static int __open_manifest_db(uid_t uid);
 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);
@@ -289,6 +331,163 @@ static int __delete_certinfo(const char *pkgid);
 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 _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
+{
+       char *error_message = NULL;
+       char query_attach[MAX_QUERY_LEN] = {'\0'};
+       char query_view[MAX_QUERY_LEN] = {'\0'};
+
+    if(uid != GLOBAL_USER){
+               snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
+               if (SQLITE_OK !=
+                       sqlite3_exec(handle, query_attach,
+                                NULL, NULL, &error_message)) {
+                       _LOGD("Don't execute query = %s error message = %s\n",
+                                  query_attach, error_message);
+                       sqlite3_free(error_message);
+               }
+               struct dbtable {
+                       char *name_table;
+                       char *primary_key;
+               };
+
+               snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select distinct * from (select  * from main.%s  m union select * from  Global.%s g WHERE m.%s=g.%s)", "package_cert_index_info", "package_cert_index_info", "package_cert_index_info", "cert_id");
+               if (SQLITE_OK !=
+                       sqlite3_exec(handle, query_view,
+                               NULL, NULL, &error_message)) {
+                       _LOGD("Don't execute query = %s error message = %s\n",
+                               query_view, error_message);
+                       sqlite3_free(error_message);
+               }
+               snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select distinct * from (select  * from main.%s  m union select * from  Global.%s g WHERE m.%s=g.%s)", "package_cert_info", "package_cert_info", "package_cert_info", "package");
+               if (SQLITE_OK !=
+                       sqlite3_exec(handle, query_view,
+                               NULL, NULL, &error_message)) {
+                       _LOGD("Don't execute query = %s error message = %s\n",
+                               query_view, error_message);
+                       sqlite3_free(error_message);
+               }
+    }
+    return 0;
+}
+
+
+static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
+{
+       char *error_message = NULL;
+       char query_attach[MAX_QUERY_LEN] = {'\0'};
+       char query_view[MAX_QUERY_LEN] = {'\0'};
+       if(uid != GLOBAL_USER){
+               snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
+               if (SQLITE_OK !=
+                       sqlite3_exec(handle, query_attach,
+                                NULL, NULL, &error_message)) {
+                       _LOGD("Don't execute query = %s error message = %s\n",
+                                  query_attach, error_message);
+                       sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+                       sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
+                               NULL, NULL, &error_message)) {
+                       _LOGD("Don't execute query = %s error message = %s\n",
+                               QUERY_CREATE_VIEW_1, error_message);
+                       sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_2, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_3, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_4, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_5, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_6, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_7, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_8, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_9, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_10, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_11, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_12, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_13, error_message);
+               sqlite3_free(error_message);
+               }
+               if (SQLITE_OK !=
+               sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
+                       NULL, NULL, &error_message)) {
+               _LOGD("Don't execute query = %s error message = %s\n",
+                       QUERY_CREATE_VIEW_14, error_message);
+               sqlite3_free(error_message);
+               }
+       }
+       return 0;
+}
+
 
 
 static int _check_create_Cert_db( sqlite3 *certdb)
@@ -303,6 +502,207 @@ static int _check_create_Cert_db( sqlite3 *certdb)
 
 
 
+API char *getIconPath(uid_t uid)
+{
+       char  *result = NULL;
+       if(uid  == GLOBAL_USER) //retrieve global icon path
+       {
+               result = tzplatform_getenv(TZ_SYS_RW_ICONS);
+       }
+       else
+       {
+               //if is_admin
+               static char result_psswd[4096];
+               const char *name = "users";
+               struct passwd *userinfo = NULL;
+               struct group *grpinfo = NULL;
+
+               userinfo = getpwuid(uid);
+               if(userinfo == NULL)
+                       _LOGE("getpwuid(%d) returns NULL !", uid);
+
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL)
+                       _LOGE("getgrnam(users) returns NULL !");
+
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid) {
+                       _LOGE("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }
+               snprintf(result_psswd, sizeof(result_psswd), tzplatform_getenv(TZ_USER_ICONS));
+               result = result_psswd;
+       }
+  if (result == NULL)
+         fprintf(stdout,"result = NULL\n");
+  fprintf(stdout,"result = %s\n", result);
+  return result;
+}
+
+API char *getUserDBLabel(void)
+{
+       char *result;
+       if(__is_admin())
+               result = strdup("System");
+       else
+               result = strdup("User");
+       return result;
+}
+
+API char *getUserPkgParserDBPath(void)
+{
+   return getUserPkgParserDBPathUID(GLOBAL_USER);
+}
+
+API char *getUserPkgParserDBPathUID(uid_t uid)
+{
+       
+       char  *result = NULL;
+       if(uid == GLOBAL_USER)
+       {
+               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
+       }
+       else
+       {
+               static char result_psswd[4096];
+               char userpath[4096];
+               const char *name = "users";
+               struct passwd *userinfo = NULL;
+               struct group *grpinfo = NULL;
+
+               userinfo = getpwuid(uid);
+               if(userinfo == NULL) {
+                       _LOGE("getpwuid(%d) returns NULL !", uid);
+                       return NULL;
+               }
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL) {
+                       _LOGE("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid) {
+                       _LOGE("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }       
+               snprintf(userpath, sizeof(userpath), "%s/.applications/dbspace", userinfo->pw_dir);
+               if(access(userpath, F_OK)) {
+                       struct group *grpinfo = NULL;
+                       const char *name = "users";
+                       int ret;
+                       char buf[BUFSIZE];
+                       mkdir(userpath, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+                       grpinfo = getgrnam(name);
+                       if(grpinfo == NULL)
+                               _LOGD("getgrnam(users) returns NULL !");
+
+                       ret = chown(userpath, uid, grpinfo->gr_gid);
+                       if (ret == -1) {
+                               strerror_r(errno, buf, sizeof(buf));
+                               _LOGD("FAIL : chown %s %d.%d, because %s", userpath, uid, grpinfo->gr_gid, buf);
+                       }       
+               }
+               snprintf(result_psswd, sizeof(result_psswd), "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
+               result = result_psswd;
+       }
+  return result;
+}
+
+API char *getUserPkgParserJournalDBPath(uid_t uid)
+{
+       char *result;
+       if(uid != GLOBAL_USER)
+               result = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser-journal.db");
+       else
+               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
+    return result;
+}
+
+API char *getUserPkgCertDBPath(void)
+{
+   return getUserPkgCertDBPathUID(GLOBAL_USER);
+}
+
+API char *getUserPkgCertDBPathUID(uid_t uid)
+{
+       char  *result = NULL;
+       if(uid == GLOBAL_USER)
+       {
+               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
+       }
+       else
+       {
+               static char result_psswd[4096];
+               const char *name = "users";
+               struct passwd *userinfo = NULL;
+               struct group *grpinfo = NULL;
+
+               userinfo = getpwuid(uid);
+               if(userinfo == NULL) {
+                       _LOGE("getpwuid(%d) returns NULL !", uid);
+                       return NULL;
+               }
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL) {
+                       _LOGE("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid){
+                       _LOGE("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }
+               snprintf(result_psswd, sizeof(result_psswd), "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
+               result = result_psswd;
+       }
+  return result;
+}
+
+API char *getUserPkgCertJournalDBPath(uid_t uid)
+{
+       char *result;
+       //isadmin
+       if(uid != GLOBAL_USER)
+               result = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert-journal.db");
+       else
+               result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert-journal.db");
+    return result;
+}
+
+API const char* getUserDesktopPath(uid_t uid)
+{
+       //is_admin
+       const char* desktop_path;
+       if(uid != GLOBAL_USER)
+  {
+    desktop_path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
+  }
+  else
+  {
+    desktop_path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
+  }
+
+  _LOGD("uid: [%d] / desktop_path: [%s]\n", uid, desktop_path);
+  return desktop_path;
+}
+
+API const char* getUserManifestPath(uid_t uid)
+{
+       const char* manifest_path;
+       //is_admin
+       if(uid != GLOBAL_USER)
+  {
+    manifest_path = tzplatform_mkpath(TZ_USER_HOME, ".config/xwalk-service/applications/");
+  }
+  else
+  {
+    manifest_path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
+  }
+
+  _LOGD("uid: [%d] / manifest_path: [%s]\n", uid, manifest_path);
+  return manifest_path;
+}
+
 static gint __compare_func(gconstpointer data1, gconstpointer data2)
 {
        pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
@@ -525,14 +925,14 @@ static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
        return;
 }
 
-static int __open_manifest_db()
+static int __open_manifest_db(uid_t uid)
 {
        int ret = -1;
-       if (access(getUserPkgParserDBPath(), F_OK) == 0) {
+       if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
                ret =
-                   db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
+                   db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
                                 SQLITE_OPEN_READONLY, NULL);
-               retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", getUserPkgParserDBPath());
+               retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
                return 0;
        }
        _LOGE("Manifest DB does not exists !!\n");
@@ -2268,7 +2668,7 @@ 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;
@@ -2296,7 +2696,7 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
                goto err;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(uid);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
                ret = PMINFO_R_ERROR;
@@ -2419,118 +2819,380 @@ err:
        return ret;
 }
 
-
-API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
+API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
 {
-       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
-       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-       pkgmgr_pkginfo_x *pkginfo = NULL;
+       retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
+       char *error_message = NULL;
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
        char *syslocale = NULL;
        char *locale = NULL;
-       int exist = 0;
+       pkgmgr_pkginfo_x *pkginfo = NULL;
        label_x *tmp1 = NULL;
        icon_x *tmp2 = NULL;
        description_x *tmp3 = NULL;
        author_x *tmp4 = NULL;
        privilege_x *tmp5 = NULL;
-       sqlite3 *pkginfo_db = NULL;
-
-       /*validate pkgid*/
-       ret = db_util_open_with_options(getUserPkgParserDBPath(), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
-       retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
-
-       /*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);
-       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
-       tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
 
-       /*get system locale*/
        syslocale = vconf_get_str(VCONFKEY_LANGSET);
-       tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
-
-       /*get locale on db*/
-       locale = __convert_system_locale_to_manifest_locale(syslocale);
-       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
-
-       pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
-       tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
-
-       pkginfo->locale = strdup(locale);
-
-       pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
-       tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
-
-       pkginfo->manifest_info->package = strdup(pkgid);
-       pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
-       tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
-
-       /*populate manifest_info from DB*/
-       snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
-       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
-       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
-
-       memset(query, '\0', MAX_QUERY_LEN);
-       /*populate privilege_info from DB*/
-       snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
-       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
-       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
-
-       memset(query, '\0', MAX_QUERY_LEN);
-       snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
-               " package='%s' and package_locale='%s'", pkgid, locale);
-       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
-       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
-
-       /*Also store the values corresponding to default locales*/
-       memset(query, '\0', MAX_QUERY_LEN);
-       snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
-               " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
-       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
-       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
-
-       if (pkginfo->manifest_info->label) {
-               LISTHEAD(pkginfo->manifest_info->label, tmp1);
-               pkginfo->manifest_info->label = tmp1;
-       }
-       if (pkginfo->manifest_info->icon) {
-               LISTHEAD(pkginfo->manifest_info->icon, tmp2);
-               pkginfo->manifest_info->icon = tmp2;
-       }
-       if (pkginfo->manifest_info->description) {
-               LISTHEAD(pkginfo->manifest_info->description, tmp3);
-               pkginfo->manifest_info->description = tmp3;
-       }
-       if (pkginfo->manifest_info->author) {
-               LISTHEAD(pkginfo->manifest_info->author, tmp4);
-               pkginfo->manifest_info->author = tmp4;
+       if (syslocale == NULL) {
+               _LOGE("current locale is NULL\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
-       if (pkginfo->manifest_info->privileges->privilege) {
-               LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
-               pkginfo->manifest_info->privileges->privilege = tmp5;
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       if (locale == NULL) {
+               _LOGE("manifest locale is NULL\n");
+               ret = PMINFO_R_EINVAL;
+               goto err;
        }
 
-catch:
-       if (ret == PMINFO_R_OK)
-               *handle = (void*)pkginfo;
-       else {
-               *handle = NULL;
-               __cleanup_pkginfo(pkginfo);
+       ret = __open_manifest_db(GLOBAL_USER);
+       if (ret == -1) {
+               _LOGE("Fail to open manifest DB\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
        }
-       sqlite3_close(pkginfo_db);
+       pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       pkgmgr_pkginfo_x *node = NULL;
+       pkgmgr_pkginfo_x *temp_node = NULL;
 
-       if (syslocale) {
-               free(syslocale);
-               syslocale = NULL;
-       }
-       if (locale) {
-               free(locale);
-               locale = NULL;
+       snprintf(query, MAX_QUERY_LEN, "select * from package_info");
+       if (SQLITE_OK !=
+           sqlite3_exec(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;
        }
-       return ret;
-}
+
+       LISTHEAD(tmphead, node);
+
+       for(node = node->next; node ; node = node->next) {
+               pkginfo = node;
+               pkginfo->locale = strdup(locale);
+               pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
+               if (pkginfo->manifest_info->privileges == NULL) {
+                       _LOGE("Failed to allocate memory for privileges info\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               /*populate manifest_info from DB*/
+               snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
+               ret = __exec_pkginfo_query(query, (void *)pkginfo);
+               if (ret == -1) {
+                       _LOGE("Package Info DB Information retrieval failed\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               memset(query, '\0', MAX_QUERY_LEN);
+               /*populate privilege_info from DB*/
+               snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
+               ret = __exec_pkginfo_query(query, (void *)pkginfo);
+               if (ret == -1) {
+                       _LOGE("Package Privilege Info DB Information retrieval failed\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               memset(query, '\0', MAX_QUERY_LEN);
+               snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
+                       " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
+               ret = __exec_pkginfo_query(query, (void *)pkginfo);
+               if (ret == -1) {
+                       _LOGE("Package Info DB Information retrieval failed\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               /*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'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
+               ret = __exec_pkginfo_query(query, (void *)pkginfo);
+               if (ret == -1) {
+                       _LOGE("Package Info DB Information retrieval failed\n");
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               if (pkginfo->manifest_info->label) {
+                       LISTHEAD(pkginfo->manifest_info->label, tmp1);
+                       pkginfo->manifest_info->label = tmp1;
+               }
+               if (pkginfo->manifest_info->icon) {
+                       LISTHEAD(pkginfo->manifest_info->icon, tmp2);
+                       pkginfo->manifest_info->icon = tmp2;
+               }
+               if (pkginfo->manifest_info->description) {
+                       LISTHEAD(pkginfo->manifest_info->description, tmp3);
+                       pkginfo->manifest_info->description = tmp3;
+               }
+               if (pkginfo->manifest_info->author) {
+                       LISTHEAD(pkginfo->manifest_info->author, tmp4);
+                       pkginfo->manifest_info->author = tmp4;
+               }
+               if (pkginfo->manifest_info->privileges->privilege) {
+                       LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
+                       pkginfo->manifest_info->privileges->privilege = tmp5;
+               }
+       }
+
+       LISTHEAD(tmphead, node);
+
+       for(node = node->next; node ; node = node->next) {
+               pkginfo = node;
+               ret = pkg_list_cb( (void *)pkginfo, user_data);
+               if(ret < 0)
+                       break;
+       }
+
+       ret = PMINFO_R_OK;
+
+err:
+       sqlite3_close(manifest_db);
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       LISTHEAD(tmphead, node);
+       temp_node = node->next;
+       node = temp_node;
+       while (node) {
+               temp_node = node->next;
+               __cleanup_pkginfo(node);
+               node = temp_node;
+       }
+       __cleanup_pkginfo(tmphead);
+       return ret;
+}
+
+API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, 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");
+       pkgmgr_pkginfo_x *pkginfo = NULL;
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char *syslocale = NULL;
+       char *locale = NULL;
+       int exist = 0;
+       label_x *tmp1 = NULL;
+       icon_x *tmp2 = NULL;
+       description_x *tmp3 = NULL;
+       author_x *tmp4 = NULL;
+       privilege_x *tmp5 = NULL;
+       sqlite3 *pkginfo_db = NULL;
+
+       /*validate pkgid*/
+       ret = db_util_open_with_options(getUserPkgParserDBPath(), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
+
+       /*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);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
+       tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
+
+       /*get system locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
+
+       /*get locale on db*/
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
+
+       pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
+
+       pkginfo->locale = strdup(locale);
+
+       pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
+
+       pkginfo->manifest_info->package = strdup(pkgid);
+       pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
+       tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
+
+       /*populate manifest_info from DB*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       /*populate privilege_info from DB*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
+               " package='%s' and package_locale='%s'", pkgid, locale);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       /*Also store the values corresponding to default locales*/
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
+               " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       if (pkginfo->manifest_info->label) {
+               LISTHEAD(pkginfo->manifest_info->label, tmp1);
+               pkginfo->manifest_info->label = tmp1;
+       }
+       if (pkginfo->manifest_info->icon) {
+               LISTHEAD(pkginfo->manifest_info->icon, tmp2);
+               pkginfo->manifest_info->icon = tmp2;
+       }
+       if (pkginfo->manifest_info->description) {
+               LISTHEAD(pkginfo->manifest_info->description, tmp3);
+               pkginfo->manifest_info->description = tmp3;
+       }
+       if (pkginfo->manifest_info->author) {
+               LISTHEAD(pkginfo->manifest_info->author, tmp4);
+               pkginfo->manifest_info->author = tmp4;
+       }
+       if (pkginfo->manifest_info->privileges->privilege) {
+               LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
+               pkginfo->manifest_info->privileges->privilege = tmp5;
+       }
+
+catch:
+       if (ret == PMINFO_R_OK)
+               *handle = (void*)pkginfo;
+       else {
+               *handle = NULL;
+               __cleanup_pkginfo(pkginfo);
+       }
+       sqlite3_close(pkginfo_db);
+
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       return ret;
+}
+
+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");
+       pkgmgr_pkginfo_x *pkginfo = NULL;
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char *syslocale = NULL;
+       char *locale = NULL;
+       int exist = 0;
+       label_x *tmp1 = NULL;
+       icon_x *tmp2 = NULL;
+       description_x *tmp3 = NULL;
+       author_x *tmp4 = NULL;
+       privilege_x *tmp5 = NULL;
+       sqlite3 *pkginfo_db = NULL;
+
+       /*validate pkgid*/
+       ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
+
+       /*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);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
+       tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
+
+       /*get system locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
+
+       /*get locale on db*/
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
+
+       pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
+
+       pkginfo->locale = strdup(locale);
+
+       pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
+
+       pkginfo->manifest_info->package = strdup(pkgid);
+       pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
+       tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
+
+       /*populate manifest_info from DB*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       /*populate privilege_info from DB*/
+       snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
+               " package='%s' and package_locale='%s'", pkgid, locale);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       /*Also store the values corresponding to default locales*/
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
+               " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
+       ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
+
+       if (pkginfo->manifest_info->label) {
+               LISTHEAD(pkginfo->manifest_info->label, tmp1);
+               pkginfo->manifest_info->label = tmp1;
+       }
+       if (pkginfo->manifest_info->icon) {
+               LISTHEAD(pkginfo->manifest_info->icon, tmp2);
+               pkginfo->manifest_info->icon = tmp2;
+       }
+       if (pkginfo->manifest_info->description) {
+               LISTHEAD(pkginfo->manifest_info->description, tmp3);
+               pkginfo->manifest_info->description = tmp3;
+       }
+       if (pkginfo->manifest_info->author) {
+               LISTHEAD(pkginfo->manifest_info->author, tmp4);
+               pkginfo->manifest_info->author = tmp4;
+       }
+       if (pkginfo->manifest_info->privileges->privilege) {
+               LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
+               pkginfo->manifest_info->privileges->privilege = tmp5;
+       }
+
+catch:
+       if (ret == PMINFO_R_OK)
+               *handle = (void*)pkginfo;
+       else {
+               *handle = NULL;
+               __cleanup_pkginfo(pkginfo);
+       }
+       sqlite3_close(pkginfo_db);
+
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       return ret;
+}
 
 
 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
@@ -3098,24 +3760,124 @@ API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **pat
        else
                return PMINFO_R_ERROR;
 
-       return PMINFO_R_OK;
-}
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       if (info->manifest_info->csc_path)
+               *path = (char *)info->manifest_info->csc_path;
+       else
+               *path = (char *)info->manifest_info->csc_path;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
+{
+       retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
+       retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
+       retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char *error_message = NULL;
+       pkgmgr_cert_x *info= NULL;
+       int lcert = 0;
+       int rcert = 0;
+       int exist = -1;
+       *compare_result = PMINFO_CERT_COMPARE_ERROR;
+       info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
+       retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
+
+       ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
+                                       SQLITE_OPEN_READWRITE, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+       _check_create_Cert_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)) {
+               _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;
+       }
+
+       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)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                          error_message);
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
 
-API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
-{
-       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
-       retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       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);
+                       ret = PMINFO_R_ERROR;
+                       goto err;
+               }
+               rcert = info->cert_id;
+       }
 
-       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
-       if (info->manifest_info->csc_path)
-               *path = (char *)info->manifest_info->csc_path;
-       else
-               *path = (char *)info->manifest_info->csc_path;
+       if ((lcert == 0) || (rcert == 0))
+       {
+               if ((lcert == 0) && (rcert == 0))
+                       *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
+               else if (lcert == 0)
+                       *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
+               else if (rcert == 0)
+                       *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
+       } else {
+               if (lcert == rcert)
+                       *compare_result = PMINFO_CERT_COMPARE_MATCH;
+               else
+                       *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
+       }
 
-       return PMINFO_R_OK;
+err:
+       sqlite3_free(error_message);
+       sqlite3_close(cert_db);
+       if (info) {
+               if (info->pkgid) {
+                       free(info->pkgid);
+                       info->pkgid = NULL;
+               }
+               free(info);
+               info = NULL;
+       }
+       return ret;
 }
 
-API int pkgmgrinfo_pkginfo_compare_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");
@@ -3132,14 +3894,15 @@ API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, con
        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(getUserPkgCertDBPath(), &cert_db,
-                                       SQLITE_OPEN_READONLY, NULL);
+       ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
+                                       SQLITE_OPEN_READWRITE, NULL);
        if (ret != SQLITE_OK) {
-               _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
+               _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
                ret = PMINFO_R_ERROR;
                goto err;
        }
        _check_create_Cert_db(cert_db);
+       _pkgmgr_parser_attach_create_view_certdb(cert_db,uid);
        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)) {
@@ -3215,7 +3978,6 @@ err:
        return ret;
 }
 
-
 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
 {
        retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
@@ -3323,6 +4085,114 @@ API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const c
        return ret;
 }
 
+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(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
+       retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
+       retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char *error_message = NULL;
+       pkgmgr_cert_x *info= NULL;
+       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 = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
+                                       SQLITE_OPEN_READONLY, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+    _pkgmgr_parser_attach_create_view_parserdb(manifest_db,uid);
+
+       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)) {
+               _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(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(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(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);
+       sqlite3_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");
@@ -3639,37 +4509,119 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
                _LOGE("Out of Memory!!!\n");
                return PMINFO_R_ERROR;
        }
-       if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
-               val = strndup("auto", PKG_STRING_LEN_MAX - 1);
-       else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
-               val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
-       else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
-               val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
-       else if (strcmp(value, "installed_internal") == 0)
-               val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
-       else if (strcmp(value, "installed_external") == 0)
-               val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
-       else
-               val = strndup(value, PKG_STRING_LEN_MAX - 1);
-       if (val == NULL) {
-               _LOGE("Out of Memory\n");
-               free(node);
-               node = NULL;
-               return PMINFO_R_ERROR;
+       if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
+               val = strndup("auto", PKG_STRING_LEN_MAX - 1);
+       else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
+               val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
+       else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
+               val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
+       else if (strcmp(value, "installed_internal") == 0)
+               val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
+       else if (strcmp(value, "installed_external") == 0)
+               val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
+       else
+               val = strndup(value, PKG_STRING_LEN_MAX - 1);
+       if (val == NULL) {
+               _LOGE("Out of Memory\n");
+               free(node);
+               node = NULL;
+               return PMINFO_R_ERROR;
+       }
+       node->prop = prop;
+       node->value = val;
+       /*If API is called multiple times for same property, we should override the previous values.
+       Last value set will be used for filtering.*/
+       link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
+       if (link)
+               filter->list = g_slist_delete_link(filter->list, link);
+       filter->list = g_slist_append(filter->list, (gpointer)node);
+       return PMINFO_R_OK;
+
+}
+
+API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
+       char *syslocale = NULL;
+       char *locale = NULL;
+       char *condition = NULL;
+       char *error_message = NULL;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char where[MAX_QUERY_LEN] = {'\0'};
+       GSList *list;
+       int ret = 0;
+
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+       /*Get current locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       if (syslocale == NULL) {
+               _LOGE("current locale is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       if (locale == NULL) {
+               _LOGE("manifest locale is NULL\n");
+               free(syslocale);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = __open_manifest_db(GLOBAL_USER);
+       if (ret == -1) {
+               _LOGE("Fail to open manifest DB\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+
+       /*Start constructing query*/
+       snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
+
+       /*Get where clause*/
+       for (list = filter->list; list; list = g_slist_next(list)) {
+               __get_filter_condition(list->data, &condition);
+               if (condition) {
+                       strncat(where, condition, sizeof(where) - strlen(where) -1);
+                       where[sizeof(where) - 1] = '\0';
+                       free(condition);
+                       condition = NULL;
+               }
+               if (g_slist_next(list)) {
+                       strncat(where, " and ", sizeof(where) - strlen(where) - 1);
+                       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';
        }
-       node->prop = prop;
-       node->value = val;
-       /*If API is called multiple times for same property, we should override the previous values.
-       Last value set will be used for filtering.*/
-       link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
-       if (link)
-               filter->list = g_slist_delete_link(filter->list, link);
-       filter->list = g_slist_append(filter->list, (gpointer)node);
-       return PMINFO_R_OK;
+       _LOGE("query = %s\n", query);
 
+       /*Execute Query*/
+       if (SQLITE_OK !=
+           sqlite3_exec(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;
+       }
+       ret = PMINFO_R_OK;
+err:
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       sqlite3_close(manifest_db);
+       return ret;
 }
-
-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");
@@ -3696,7 +4648,7 @@ 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;
@@ -3788,7 +4740,7 @@ API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h ha
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
                ret = PMINFO_R_ERROR;
@@ -4169,124 +5121,300 @@ API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_
                        ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
                        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
 
-                       if (appinfo->uiapp_info->label) {
-                               LISTHEAD(appinfo->uiapp_info->label, ptr2);
-                               appinfo->uiapp_info->label = ptr2;
-                       }
-                       if (appinfo->uiapp_info->icon) {
-                               LISTHEAD(appinfo->uiapp_info->icon, ptr1);
-                               appinfo->uiapp_info->icon = ptr1;
-                       }
-                       if (appinfo->uiapp_info->category) {
-                               LISTHEAD(appinfo->uiapp_info->category, ptr3);
-                               appinfo->uiapp_info->category = ptr3;
-                       }
-                       if (appinfo->uiapp_info->metadata) {
-                               LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
-                               appinfo->uiapp_info->metadata = ptr4;
-                       }
-                       if (appinfo->uiapp_info->permission) {
-                               LISTHEAD(appinfo->uiapp_info->permission, ptr5);
-                               appinfo->uiapp_info->permission = ptr5;
-                       }
-                       if (appinfo->uiapp_info->image) {
-                               LISTHEAD(appinfo->uiapp_info->image, ptr6);
-                               appinfo->uiapp_info->image = ptr6;
-                       }
-                       ret = app_func((void *)appinfo, user_data);
-                       if (ret < 0)
-                               break;
-                       tmp2 = tmp2->next;
-               }
+                       if (appinfo->uiapp_info->label) {
+                               LISTHEAD(appinfo->uiapp_info->label, ptr2);
+                               appinfo->uiapp_info->label = ptr2;
+                       }
+                       if (appinfo->uiapp_info->icon) {
+                               LISTHEAD(appinfo->uiapp_info->icon, ptr1);
+                               appinfo->uiapp_info->icon = ptr1;
+                       }
+                       if (appinfo->uiapp_info->category) {
+                               LISTHEAD(appinfo->uiapp_info->category, ptr3);
+                               appinfo->uiapp_info->category = ptr3;
+                       }
+                       if (appinfo->uiapp_info->metadata) {
+                               LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
+                               appinfo->uiapp_info->metadata = ptr4;
+                       }
+                       if (appinfo->uiapp_info->permission) {
+                               LISTHEAD(appinfo->uiapp_info->permission, ptr5);
+                               appinfo->uiapp_info->permission = ptr5;
+                       }
+                       if (appinfo->uiapp_info->image) {
+                               LISTHEAD(appinfo->uiapp_info->image, ptr6);
+                               appinfo->uiapp_info->image = ptr6;
+                       }
+                       ret = app_func((void *)appinfo, user_data);
+                       if (ret < 0)
+                               break;
+                       tmp2 = tmp2->next;
+               }
+
+               /*SVC Apps*/
+               appinfo->app_component = PMINFO_SVC_APP;
+               serviceapplication_x *tmp3 = NULL;
+               if (allinfo->manifest_info->serviceapplication) {
+                       LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
+                       allinfo->manifest_info->serviceapplication = tmp3;
+               }
+               /*Populate localized info for default locales and call callback*/
+               /*If the callback func return < 0 we break and no more call back is called*/
+               while(tmp3 != NULL)
+               {
+                       appinfo->locale = strdup(locale);
+                       appinfo->svcapp_info = tmp3;
+                       memset(query, '\0', MAX_QUERY_LEN);
+                       snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
+                       ret = __exec_db_query(appinfo_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);
+                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
+
+                       if (appinfo->svcapp_info->label) {
+                               LISTHEAD(appinfo->svcapp_info->label, ptr2);
+                               appinfo->svcapp_info->label = ptr2;
+                       }
+                       if (appinfo->svcapp_info->icon) {
+                               LISTHEAD(appinfo->svcapp_info->icon, ptr1);
+                               appinfo->svcapp_info->icon = ptr1;
+                       }
+                       if (appinfo->svcapp_info->category) {
+                               LISTHEAD(appinfo->svcapp_info->category, ptr3);
+                               appinfo->svcapp_info->category = ptr3;
+                       }
+                       if (appinfo->svcapp_info->metadata) {
+                               LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
+                               appinfo->svcapp_info->metadata = ptr4;
+                       }
+                       if (appinfo->svcapp_info->permission) {
+                               LISTHEAD(appinfo->svcapp_info->permission, ptr5);
+                               appinfo->svcapp_info->permission = ptr5;
+                       }
+                       ret = app_func((void *)appinfo, user_data);
+                       if (ret < 0)
+                               break;
+                       tmp3 = tmp3->next;
+               }
+               appinfo->app_component = PMINFO_ALL_APP;
+               break;
+
+       }
+
+       ret = PMINFO_R_OK;
+catch:
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       if (appinfo) {
+               if (appinfo->package) {
+                       free((void *)appinfo->package);
+                       appinfo->package = NULL;
+               }
+               free(appinfo);
+               appinfo = NULL;
+       }
+       __cleanup_pkginfo(allinfo);
+
+       sqlite3_close(appinfo_db);
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+{
+       retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
+
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       pkgmgr_appinfo_x *appinfo = NULL;
+       uiapplication_x *ptr1 = NULL;
+       serviceapplication_x *ptr2 = NULL;
+       sqlite3 *appinfo_db = NULL;
+
+       /*open db*/
+       ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
+
+       /*calloc pkginfo*/
+       pkgmgr_pkginfo_x *info = NULL;
+       info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
+
+       /*calloc manifest_info*/
+       info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
+
+       /*calloc appinfo*/
+       appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
+
+       snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
+       ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
+
+       if (info->manifest_info->uiapplication) {
+               LISTHEAD(info->manifest_info->uiapplication, ptr1);
+               info->manifest_info->uiapplication = ptr1;
+       }
+       if (info->manifest_info->serviceapplication) {
+               LISTHEAD(info->manifest_info->serviceapplication, ptr2);
+               info->manifest_info->serviceapplication = ptr2;
+       }
+
+       /*UI Apps*/
+       for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
+       {
+               appinfo->app_component = PMINFO_UI_APP;
+               appinfo->package = strdup(ptr1->package);
+               appinfo->uiapp_info = ptr1;
+
+               ret = app_func((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               free((void *)appinfo->package);
+               appinfo->package = NULL;
+       }
+       /*Service Apps*/
+       for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
+       {
+               appinfo->app_component = PMINFO_SVC_APP;
+               appinfo->package = strdup(ptr2->package);
+               appinfo->svcapp_info = ptr2;
+
+               ret = app_func((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               free((void *)appinfo->package);
+               appinfo->package = NULL;
+       }
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_close(appinfo_db);
+
+       if (appinfo) {
+               free(appinfo);
+               appinfo = NULL;
+       }
+       __cleanup_pkginfo(info);
+       return ret;
+}
+
+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");
+
+       int ret = PMINFO_R_OK;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       pkgmgr_appinfo_x *appinfo = NULL;
+       uiapplication_x *ptr1 = NULL;
+       serviceapplication_x *ptr2 = NULL;
+       sqlite3 *appinfo_db = NULL;
+
+       /*open db*/
+       ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
 
-               /*SVC Apps*/
-               appinfo->app_component = PMINFO_SVC_APP;
-               serviceapplication_x *tmp3 = NULL;
-               if (allinfo->manifest_info->serviceapplication) {
-                       LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
-                       allinfo->manifest_info->serviceapplication = tmp3;
-               }
-               /*Populate localized info for default locales and call callback*/
-               /*If the callback func return < 0 we break and no more call back is called*/
-               while(tmp3 != NULL)
-               {
-                       appinfo->locale = strdup(locale);
-                       appinfo->svcapp_info = tmp3;
-                       memset(query, '\0', MAX_QUERY_LEN);
-                       snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
-                       ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
-                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
+       /*calloc pkginfo*/
+       pkgmgr_pkginfo_x *info = NULL;
+       info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
 
-                       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);
-                       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
+       /*calloc manifest_info*/
+       info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
 
-                       if (appinfo->svcapp_info->label) {
-                               LISTHEAD(appinfo->svcapp_info->label, ptr2);
-                               appinfo->svcapp_info->label = ptr2;
-                       }
-                       if (appinfo->svcapp_info->icon) {
-                               LISTHEAD(appinfo->svcapp_info->icon, ptr1);
-                               appinfo->svcapp_info->icon = ptr1;
-                       }
-                       if (appinfo->svcapp_info->category) {
-                               LISTHEAD(appinfo->svcapp_info->category, ptr3);
-                               appinfo->svcapp_info->category = ptr3;
-                       }
-                       if (appinfo->svcapp_info->metadata) {
-                               LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
-                               appinfo->svcapp_info->metadata = ptr4;
-                       }
-                       if (appinfo->svcapp_info->permission) {
-                               LISTHEAD(appinfo->svcapp_info->permission, ptr5);
-                               appinfo->svcapp_info->permission = ptr5;
-                       }
-                       ret = app_func((void *)appinfo, user_data);
-                       if (ret < 0)
-                               break;
-                       tmp3 = tmp3->next;
-               }
-               appinfo->app_component = PMINFO_ALL_APP;
-               break;
+       /*calloc appinfo*/
+       appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       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);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
+       if (info->manifest_info->uiapplication) {
+               LISTHEAD(info->manifest_info->uiapplication, ptr1);
+               info->manifest_info->uiapplication = ptr1;
+       }
+       if (info->manifest_info->serviceapplication) {
+               LISTHEAD(info->manifest_info->serviceapplication, ptr2);
+               info->manifest_info->serviceapplication = ptr2;
        }
 
-       ret = PMINFO_R_OK;
-catch:
-       if (locale) {
-               free(locale);
-               locale = NULL;
+       /*UI Apps*/
+       for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
+       {
+               appinfo->app_component = PMINFO_UI_APP;
+               appinfo->package = strdup(ptr1->package);
+               appinfo->uiapp_info = ptr1;
+
+               ret = app_func((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               free((void *)appinfo->package);
+               appinfo->package = NULL;
        }
-       if (syslocale) {
-               free(syslocale);
-               syslocale = NULL;
+       /*Service Apps*/
+       for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
+       {
+               appinfo->app_component = PMINFO_SVC_APP;
+               appinfo->package = strdup(ptr2->package);
+               appinfo->svcapp_info = ptr2;
+
+               ret = app_func((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               free((void *)appinfo->package);
+               appinfo->package = NULL;
        }
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_close(appinfo_db);
+
        if (appinfo) {
-               if (appinfo->package) {
-                       free((void *)appinfo->package);
-                       appinfo->package = NULL;
-               }
                free(appinfo);
                appinfo = NULL;
        }
-       __cleanup_pkginfo(allinfo);
-
-       sqlite3_close(appinfo_db);
+       __cleanup_pkginfo(info);
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
+API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
 {
        retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
 
        int ret = PMINFO_R_OK;
        char query[MAX_QUERY_LEN] = {'\0'};
+       char *syslocale = NULL;
+       char *locale = NULL;
        pkgmgr_appinfo_x *appinfo = NULL;
        uiapplication_x *ptr1 = NULL;
        serviceapplication_x *ptr2 = NULL;
+       label_x *tmp1 = NULL;
+       icon_x *tmp2 = NULL;
+       category_x *tmp3 = NULL;
+       metadata_x *tmp4 = NULL;
+       permission_x *tmp5 = NULL;
+       image_x *tmp6 = NULL;
        sqlite3 *appinfo_db = NULL;
 
+       /*get system locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
+
+       /*get locale on db*/
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
+
        /*open db*/
        ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
        retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
@@ -4305,7 +5433,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(appinfo_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) {
@@ -4320,10 +5448,76 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, voi
        /*UI Apps*/
        for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
        {
+               appinfo->locale = strdup(locale);
                appinfo->app_component = PMINFO_UI_APP;
                appinfo->package = strdup(ptr1->package);
                appinfo->uiapp_info = ptr1;
+               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);
+               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);
+               }
+
+               memset(query, '\0', MAX_QUERY_LEN);
+               snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
+                               "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);
+               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 DISTINCT * " \
+                               "from package_app_localized_info where " \
+                               "app_id='%s' and app_locale='%s'",
+                               ptr1->appid, DEFAULT_LOCALE);
 
+               ret = __exec_db_query(appinfo_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);
+               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);
+               tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
+
+               if (appinfo->uiapp_info->label) {
+                       LISTHEAD(appinfo->uiapp_info->label, tmp1);
+                       appinfo->uiapp_info->label = tmp1;
+               }
+               if (appinfo->uiapp_info->icon) {
+                       LISTHEAD(appinfo->uiapp_info->icon, tmp2);
+                       appinfo->uiapp_info->icon= tmp2;
+               }
+               if (appinfo->uiapp_info->category) {
+                       LISTHEAD(appinfo->uiapp_info->category, tmp3);
+                       appinfo->uiapp_info->category = tmp3;
+               }
+               if (appinfo->uiapp_info->metadata) {
+                       LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
+                       appinfo->uiapp_info->metadata = tmp4;
+               }
+               if (appinfo->uiapp_info->permission) {
+                       LISTHEAD(appinfo->uiapp_info->permission, tmp5);
+                       appinfo->uiapp_info->permission = tmp5;
+               }
+               if (appinfo->uiapp_info->image) {
+                       LISTHEAD(appinfo->uiapp_info->image, tmp6);
+                       appinfo->uiapp_info->image = tmp6;
+               }
                ret = app_func((void *)appinfo, user_data);
                if (ret < 0)
                        break;
@@ -4333,10 +5527,53 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, voi
        /*Service Apps*/
        for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
        {
+               appinfo->locale = strdup(locale);
                appinfo->app_component = PMINFO_SVC_APP;
                appinfo->package = strdup(ptr2->package);
                appinfo->svcapp_info = ptr2;
+               memset(query, '\0', MAX_QUERY_LEN);
+               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);
+               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 DISTINCT * " \
+                               "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);
+               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 DISTINCT * " \
+                               "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);
+               tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
 
+               if (appinfo->svcapp_info->label) {
+                       LISTHEAD(appinfo->svcapp_info->label, tmp1);
+                       appinfo->svcapp_info->label = tmp1;
+               }
+               if (appinfo->svcapp_info->icon) {
+                       LISTHEAD(appinfo->svcapp_info->icon, tmp2);
+                       appinfo->svcapp_info->icon= tmp2;
+               }
+               if (appinfo->svcapp_info->category) {
+                       LISTHEAD(appinfo->svcapp_info->category, tmp3);
+                       appinfo->svcapp_info->category = tmp3;
+               }
+               if (appinfo->svcapp_info->metadata) {
+                       LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
+                       appinfo->svcapp_info->metadata = tmp4;
+               }
+               if (appinfo->svcapp_info->permission) {
+                       LISTHEAD(appinfo->svcapp_info->permission, tmp5);
+                       appinfo->svcapp_info->permission = tmp5;
+               }
                ret = app_func((void *)appinfo, user_data);
                if (ret < 0)
                        break;
@@ -4346,8 +5583,15 @@ API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, voi
        ret = PMINFO_R_OK;
 
 catch:
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
        sqlite3_close(appinfo_db);
-
        if (appinfo) {
                free(appinfo);
                appinfo = NULL;
@@ -4356,7 +5600,7 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *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");
 
@@ -4384,8 +5628,8 @@ 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(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
-       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
+       ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
 
        /*calloc pkginfo*/
        pkgmgr_pkginfo_x *info = NULL;
@@ -4568,7 +5812,7 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_appinfo_user(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
+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");
@@ -4587,18 +5831,11 @@ API int pkgmgrinfo_appinfo_get_appinfo_user(const char *appid, uid_t uid, pkgmgr
        char query[MAX_QUERY_LEN] = {'\0'};
        sqlite3 *appinfo_db = NULL;
 
-       if (uid != 0) {
-               /*open db*/
-               _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
-               ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
-               retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
-       }else
-       {
-               /*open db*/
-               _LOGD("getUserPkgParserDBPath() returns: [%s]", getUserPkgParserDBPath);
-               ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
-               retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
-       }
+       /*open db*/
+       _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
+       ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
+       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
+
   
        /*check appid exist on db*/
        snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
@@ -5414,6 +6651,190 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+       int i = 0;
+       int ret = -1;
+       int oc = 0;
+       int mc = 0;
+       int uc = 0;
+       int sc = 0;
+       char *pkgid = NULL;
+       char *manifest = NULL;
+       char **operation = NULL;
+       char **uri = NULL;
+       char **mime = NULL;
+       char **subapp = NULL;
+       appcontrol_x *appcontrol = NULL;
+       manifest_x *mfx = NULL;
+       operation_x *op = NULL;
+       uri_x *ui = NULL;
+       mime_x *mi = NULL;
+       subapp_x *sa = NULL;
+       pkgmgrinfo_app_component component;
+       pkgmgrinfo_appcontrol_x *ptr = NULL;
+       ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+       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_usr_manifest_file(pkgid, uid);
+       if (manifest == NULL) {
+               _LOGE("Failed to fetch package manifest file\n");
+               return PMINFO_R_ERROR;
+       }
+       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
+       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;
+                       }
+               }
+               break;
+       case PMINFO_SVC_APP:
+               if (mfx->serviceapplication) {
+                       if (mfx->serviceapplication->appsvc) {
+                               appcontrol = mfx->serviceapplication->appsvc;
+                       }
+               }
+               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;
+               }
+               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;
+}
+
 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
 {
@@ -5957,18 +7378,100 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                        filter->list = g_slist_append(filter->list, (gpointer)node);
                        memset(temp, '\0', PKG_STRING_LEN_MAX);
                }
-               break;
-       default:
-               node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
-               link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
-               if (link)
-                       filter->list = g_slist_delete_link(filter->list, link);
-               filter->list = g_slist_append(filter->list, (gpointer)node);
-               break;
+               break;
+       default:
+               node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
+               link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
+               if (link)
+                       filter->list = g_slist_delete_link(filter->list, link);
+               filter->list = g_slist_append(filter->list, (gpointer)node);
+               break;
+       }
+       return PMINFO_R_OK;
+}
+
+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");
+       char *syslocale = NULL;
+       char *locale = NULL;
+       char *condition = NULL;
+       char *error_message = NULL;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char where[MAX_QUERY_LEN] = {'\0'};
+       GSList *list;
+       int ret = 0;
+
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+       /*Get current locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       if (syslocale == NULL) {
+               _LOGE("current locale is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       if (locale == NULL) {
+               _LOGE("manifest locale is NULL\n");
+               free(syslocale);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = __open_manifest_db(uid);
+       if (ret == -1) {
+               _LOGE("Fail to open manifest DB\n");
+               ret = PMINFO_R_ERROR;
+               goto err;
+       }
+
+       /*Start constructing query*/
+       snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
+
+       /*Get where clause*/
+       for (list = filter->list; list; list = g_slist_next(list)) {
+               __get_filter_condition(list->data, &condition);
+               if (condition) {
+                       strncat(where, condition, sizeof(where) - strlen(where) -1);
+                       where[sizeof(where) - 1] = '\0';
+                       free(condition);
+                       condition = NULL;
+               }
+               if (g_slist_next(list)) {
+                       strncat(where, " and ", sizeof(where) - strlen(where) - 1);
+                       where[sizeof(where) - 1] = '\0';
+               }
        }
-       return PMINFO_R_OK;
-}
+       _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)) {
+               _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;
+       }
+       ret = PMINFO_R_OK;
+err:
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       sqlite3_close(manifest_db);
+       return ret;
+}
 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
@@ -5996,7 +7499,7 @@ API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
                ret = PMINFO_R_ERROR;
@@ -6081,7 +7584,7 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                return PMINFO_R_ERROR;
        }
 
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGE("Fail to open manifest DB\n");
                ret = PMINFO_R_ERROR;
@@ -6180,16 +7683,216 @@ 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)) {
-                       _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;
-               }
+               if (SQLITE_OK !=
+               sqlite3_exec(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;
+               }
+       }
+       if (filtinfo->manifest_info->uiapplication) {
+               LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
+               filtinfo->manifest_info->uiapplication = ptr1;
+       }
+       /*If the callback func return < 0 we break and no more call back is called*/
+       while(ptr1 != NULL)
+       {
+               appinfo->locale = strdup(locale);
+               appinfo->uiapp_info = ptr1;
+               appinfo->app_component = PMINFO_UI_APP;
+               ret = app_cb((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               ptr1 = ptr1->next;
+       }
+       /*Filtered Service Apps*/
+       if (filtinfo->manifest_info->serviceapplication) {
+               LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
+               filtinfo->manifest_info->serviceapplication = ptr2;
+       }
+       /*If the callback func return < 0 we break and no more call back is called*/
+       while(ptr2 != NULL)
+       {
+               appinfo->locale = strdup(locale);
+               appinfo->svcapp_info = ptr2;
+               appinfo->app_component = PMINFO_SVC_APP;
+               ret = app_cb((void *)appinfo, user_data);
+               if (ret < 0)
+                       break;
+               ptr2 = ptr2->next;
+       }
+       ret = PMINFO_R_OK;
+err:
+       if (locale) {
+               free(locale);
+               locale = NULL;
+       }
+       if (syslocale) {
+               free(syslocale);
+               syslocale = NULL;
+       }
+       sqlite3_close(manifest_db);
+       if (appinfo) {
+               free(appinfo);
+               appinfo = NULL;
+       }
+       __cleanup_pkginfo(info);
+       __cleanup_pkginfo(filtinfo);
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
+{
+       return (pkgmgrinfo_pkginfo_filter_create(handle));
+}
+
+API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
+{
+       return (pkgmgrinfo_pkginfo_filter_destroy(handle));
+}
+
+API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
+               const char *key, const char *value)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
+       retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
+       /*value can be NULL. In that case all apps with specified key should be displayed*/
+       int ret = 0;
+       char *k = NULL;
+       char *v = NULL;
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
+       retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
+       k = strdup(key);
+       tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+       node->key = k;
+       if (value) {
+               v = strdup(value);
+               tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+       }
+       node->value = v;
+       /*If API is called multiple times, we should OR all conditions.*/
+       filter->list = g_slist_append(filter->list, (gpointer)node);
+       /*All memory will be freed in destroy API*/
+       return PMINFO_R_OK;
+catch:
+       if (node) {
+               if (node->key) {
+                       free(node->key);
+                       node->key = NULL;
+               }
+               if (node->value) {
+                       free(node->value);
+                       node->value = NULL;
+               }
+               free(node);
+               node = NULL;
+       }
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
+               pkgmgrinfo_app_list_cb app_cb, void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
+       retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
+       char *syslocale = NULL;
+       char *locale = NULL;
+       char *condition = NULL;
+       char *error_message = NULL;
+       char query[MAX_QUERY_LEN] = {'\0'};
+       char where[MAX_QUERY_LEN] = {'\0'};
+       GSList *list;
+       int ret = 0;
+       pkgmgr_pkginfo_x *info = NULL;
+       pkgmgr_pkginfo_x *filtinfo = NULL;
+       pkgmgr_appinfo_x *appinfo = NULL;
+       uiapplication_x *ptr1 = NULL;
+       serviceapplication_x *ptr2 = NULL;
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
+
+       /*Get current locale*/
+       syslocale = vconf_get_str(VCONFKEY_LANGSET);
+       retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
+       locale = __convert_system_locale_to_manifest_locale(syslocale);
+       tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
+
+       ret = __open_manifest_db(GLOBAL_USER);
+       tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
+
+       /*Start constructing query*/
+       memset(where, '\0', MAX_QUERY_LEN);
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
+       /*Get where clause*/
+       for (list = filter->list; list; list = g_slist_next(list)) {
+               __get_metadata_filter_condition(list->data, &condition);
+               if (condition) {
+                       strncat(where, condition, sizeof(where) - strlen(where) -1);
+                       free(condition);
+                       condition = NULL;
+               }
+               if (g_slist_next(list)) {
+                       strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
+               }
+       }
+       _LOGE("where = %s (%d)\n", where, strlen(where));
+       if (strlen(where) > 0) {
+               strncat(query, where, sizeof(query) - strlen(query) - 1);
+       }
+       _LOGE("query = %s (%d)\n", query, strlen(query));
+       /*To get filtered list*/
+       info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       /*To get detail app info for each member of filtered list*/
+       filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
+       tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
+       tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
+       tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
+
+       ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
+       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
+       memset(query, '\0', MAX_QUERY_LEN);
+
+       if (info->manifest_info->uiapplication) {
+               LISTHEAD(info->manifest_info->uiapplication, ptr1);
+               info->manifest_info->uiapplication = ptr1;
+       }
+       if (info->manifest_info->serviceapplication) {
+               LISTHEAD(info->manifest_info->serviceapplication, ptr2);
+               info->manifest_info->serviceapplication = ptr2;
+       }
+
+       /*UI Apps*/
+       for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
+       {
+               snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
+                                                       ptr1->appid, "uiapp");
+               ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
+               tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
+               memset(query, '\0', MAX_QUERY_LEN);
+       }
+       /*Service Apps*/
+       for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
+       {
+               snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
+                                                       ptr2->appid, "svcapp");
+               ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
+               tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
+               memset(query, '\0', MAX_QUERY_LEN);
        }
+       /*Filtered UI Apps*/
        if (filtinfo->manifest_info->uiapplication) {
                LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
                filtinfo->manifest_info->uiapplication = ptr1;
@@ -6222,7 +7925,7 @@ API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h ha
                ptr2 = ptr2->next;
        }
        ret = PMINFO_R_OK;
-err:
+catch:
        if (locale) {
                free(locale);
                locale = NULL;
@@ -6231,6 +7934,7 @@ err:
                free(syslocale);
                syslocale = NULL;
        }
+       sqlite3_free(error_message);
        sqlite3_close(manifest_db);
        if (appinfo) {
                free(appinfo);
@@ -6240,59 +7944,8 @@ err:
        __cleanup_pkginfo(filtinfo);
        return ret;
 }
-
-API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
-{
-       return (pkgmgrinfo_pkginfo_filter_create(handle));
-}
-
-API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
-{
-       return (pkgmgrinfo_pkginfo_filter_destroy(handle));
-}
-
-API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
-               const char *key, const char *value)
-{
-       retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
-       retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
-       /*value can be NULL. In that case all apps with specified key should be displayed*/
-       int ret = 0;
-       char *k = NULL;
-       char *v = NULL;
-       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
-       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
-       retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
-       k = strdup(key);
-       tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
-       node->key = k;
-       if (value) {
-               v = strdup(value);
-               tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
-       }
-       node->value = v;
-       /*If API is called multiple times, we should OR all conditions.*/
-       filter->list = g_slist_append(filter->list, (gpointer)node);
-       /*All memory will be freed in destroy API*/
-       return PMINFO_R_OK;
-catch:
-       if (node) {
-               if (node->key) {
-                       free(node->key);
-                       node->key = NULL;
-               }
-               if (node->value) {
-                       free(node->value);
-                       node->value = NULL;
-               }
-               free(node);
-               node = NULL;
-       }
-       return ret;
-}
-
-API int pkgmgrinfo_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");
@@ -6317,7 +7970,7 @@ 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();
+       ret = __open_manifest_db(GLOBAL_USER);
        tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
 
        /*Start constructing query*/
@@ -6465,7 +8118,7 @@ API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_
 
        /*Open db.*/
        ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
-                                       SQLITE_OPEN_READONLY, NULL);
+                                       SQLITE_OPEN_READWRITE, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
                return PMINFO_R_ERROR;
@@ -6833,6 +8486,29 @@ err:
        return ret;
 }
 
+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;
+
+       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");
@@ -7065,6 +8741,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");
@@ -7086,7 +8780,7 @@ API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
        retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
        int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
-       ret = __open_manifest_db();
+       ret = __open_manifest_db(GLOBAL_USER);
 
        if (access(getUserPkgParserDBPath(), F_OK) == 0) {
                ret = db_util_open(MANIFEST_DB, &manifest_db,
@@ -7134,6 +8828,58 @@ API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
        return PMINFO_R_OK;
 }
 
+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(uid);
+
+       if (access(getUserPkgParserDBPathUID(uid), 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", getUserPkgParserDBPathUID(uid));
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       /*Begin transaction*/
+       ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to begin transaction\n");
+               sqlite3_close(manifest_db);
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("Transaction Begin\n");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN,
+               "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
+
+       char *error_message = NULL;
+       if (SQLITE_OK !=
+           sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+               sqlite3_free(error_message);
+               return PMINFO_R_ERROR;
+       }
+       sqlite3_free(error_message);
+
+       /*Commit transaction*/
+       ret = sqlite3_exec(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);
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("Transaction Commit and End\n");
+       sqlite3_close(manifest_db);
+
+       return PMINFO_R_OK;
+}
 
 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
 {
@@ -7180,13 +8926,65 @@ API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * typ
        return PMINFO_R_OK;
 }
 
+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(uid);
+
+       if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
+               ret = db_util_open(getUserPkgParserDBPathUID(uid), &manifest_db,
+                        DB_UTIL_REGISTER_HOOK_METHOD);
+               if (ret != SQLITE_OK) {
+                       _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPathUID(uid));
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       /*Begin transaction*/
+       ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to begin transaction\n");
+               sqlite3_close(manifest_db);
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("Transaction Begin\n");
+
+       memset(query, '\0', MAX_QUERY_LEN);
+       snprintf(query, MAX_QUERY_LEN,
+               "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)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+               sqlite3_free(error_message);
+               return PMINFO_R_ERROR;
+       }
+
+       /*Commit transaction*/
+       ret = sqlite3_exec(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);
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("Transaction Commit and End\n");
+       sqlite3_close(manifest_db);
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
 {
        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(GLOBAL_USER);
 
        if (access(getUserPkgParserDBPath(), F_OK) == 0) {
                ret = db_util_open(getUserPkgParserDBPath(), &manifest_db,
@@ -7301,6 +9099,56 @@ API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+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;
+       sqlite3 *pkgmgr_parser_db;
+
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       val = (char *)info->uiapp_info->guestmode_visibility;
+       if (val ) {
+                ret =
+                   db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
+                                SQLITE_OPEN_READWRITE, NULL);
+
+                if (ret != SQLITE_OK) {
+                       _LOGE("DB Open Failed\n");
+                       return PMINFO_R_ERROR;
+                }
+
+               /*TODO: Write to DB here*/
+               if (status == true)
+                       snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
+               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)) {
+                       _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_OK;
+}
+
 /* pkgmgrinfo client start*/
 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
 {