Multi user features : 18/25718/3 accepted/tizen/common/20140812.141121 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>
Wed, 18 Jun 2014 08:31:39 +0000 (10:31 +0200)
committerSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Mon, 11 Aug 2014 13:37:39 +0000 (15:37 +0200)
->Add/Use Usr App related fonctions instead of Global App related Functions

Change-Id: Icbe51b1a830c91b273de3309c13ec3fecfcb7405
Signed-off-by: Sabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
16 files changed:
CMakeLists.txt
desktop.conf [deleted file]
desktop.conf.in [new file with mode: 0644]
include/ail.h
initdb/src/initdb.c
packaging/ail.spec
src/ail_db.c
src/ail_db.h
src/ail_desktop.c
src/ail_filter.c
src/ail_package.c
src/ail_sql.h
tool/src/ail_filter.c
tool/src/ail_fota.c
tool/src/ail_package.c
tool/src/initdb.c

index cf9de2c..1f951eb 100644 (file)
@@ -52,6 +52,7 @@ CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc @ONL
 INSTALL(TARGETS ${LIBNAME} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/ail.h DESTINATION include)
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/desktop.conf.in ${CMAKE_SOURCE_DIR}/desktop.conf)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/desktop.conf DESTINATION share/install-info)
 
 # AIL init database
diff --git a/desktop.conf b/desktop.conf
deleted file mode 100644 (file)
index 3be783d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/opt/share/applications
diff --git a/desktop.conf.in b/desktop.conf.in
new file mode 100644 (file)
index 0000000..55dc5d7
--- /dev/null
@@ -0,0 +1 @@
+@TZ_SYS_RW_DESKTOP_APP@
index fab4ff9..3a04b79 100755 (executable)
 #include <sys/types.h>
 #include <pwd.h>
 #include <tzplatform_config.h>
+
 #define OWNER_ROOT 0
 #define GROUP_MENU 6010
+#define GLOBAL_USER 0 //tzplatform
 #define BUFSZE 1024
 #define OPT_DESKTOP_DIRECTORY tzplatform_getenv(TZ_SYS_RW_DESKTOP_APP)
 #define USR_DESKTOP_DIRECTORY tzplatform_getenv(TZ_SYS_RO_DESKTOP_APP)
 #define APP_INFO_DB_FILE tzplatform_mkpath(TZ_SYS_DB,".app_info.db")
 #define APP_INFO_DB_FILE_JOURNAL tzplatform_mkpath(TZ_SYS_DB,".app_info.db-journal")
-#define APP_INFO_DB_LABEL "ail::db"
+#define APP_INFO_DB_LABEL "_"
 
 #ifdef __cplusplus
 extern "C" {
@@ -442,7 +444,7 @@ typedef ail_cb_ret_e (*ail_list_appinfo_cb) (const ail_appinfo_h appinfo_h, void
 
 /**
  * @fn ail_error_e ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter, ail_list_appinfo_cb func, void *user_data)
- *
+ * @fn ail_error_e ail_error_e ail_filter_list_usr_appinfo_foreach(ail_filter_h filter, ail_list_appinfo_cb func, void *user_data, uid_t uid)
  * @brief Calls the callback function for each app filtered by given filter. If the filter is not given (i.e filter handle is NULL), it is invoked for all apps.
  *
  * @par Sync (or) Async : Synchronous API
@@ -450,6 +452,7 @@ typedef ail_cb_ret_e (*ail_list_appinfo_cb) (const ail_appinfo_h appinfo_h, void
  * @param[in] filter           a filter handle
  * @param[in] func                     the function to call with each app's appinfo
  * @param[in] user_data                user_data to pass to the function
+ * @param[in] uid      ID of the owner of the application
  *
  * @return  0 if success, negative value(<0) if fail\n
  * @retval AIL_ERROR_OK                                        success
@@ -513,18 +516,19 @@ int list_apps()
 ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter,
                                             ail_list_appinfo_cb appinfo_func,
                                             void *user_data);
-
-
-
+ail_error_e ail_filter_list_usr_appinfo_foreach(ail_filter_h filter,
+                                            ail_list_appinfo_cb appinfo_func,
+                                            void *user_data, uid_t uid);
 /**
- * @fn ail_error_e ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *count)
- *
+ * @fn ail_error_e ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *count, uid_t uid)
+ * @fn ail_error_e ail_error_e ail_filter_count_usr_appinfo(ail_filter_h filter, int *count)
  * @brief Gets the number of app which is filtered by the given filter. If the filter is not given (i.e filter handle is NULL), all app are counted.
  *
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in] filter   a filter handle
  * @param[in] count            the number of appinfo which is filtered
+ * @param[in] uid      ID of the owner of the application
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -578,12 +582,11 @@ int count_apps()
  * @endcode
  */
 ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *count);
-
-
+ail_error_e ail_filter_count_usr_appinfo(ail_filter_h filter, int *count, uid_t uid);
 
 /**
  * @fn ail_error_e ail_package_get_appinfo(const char *package, ail_appinfo_h *handle)
- *
+ * @fn ail_error_e ail_package_get_appinfo(const char *package, uid_t uid, ail_appinfo_h *handle)
  * @brief get an application information related to a package. 
        This API just retrieves all the information of the package from Application Information Database.
        All data related to the package are loaded in the memory after calling this function. 
@@ -592,6 +595,7 @@ ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *count);
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] package package name what you want to know about.
+ * @param[in] uid      ID of the owner of the application
  * @param[out] handle handle will be used with the functions of ail_appinfo_get_xxx. If no data, it will be NULL.
  *
  * @return 0 if success, negative value(<0) if fail\n
@@ -637,11 +641,10 @@ static ail_error_e _get_name(const char *package)
  * @endcode
  */
 ail_error_e ail_package_get_appinfo(const char *package, ail_appinfo_h *handle) __attribute__((deprecated));
-
-
+ail_error_e ail_package_get_usr_appinfo(const char *package, uid_t uid, ail_appinfo_h *handle) __attribute__((deprecated));
 /**
  * @fn ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *handle)
- *
+ * @fn ail_error_e ail_get_usr_appinfo(const char *appid, uid_t uid, ail_appinfo_h *handle)
  * @brief get an application information related to a appid.
        This API just retrieves all the information of the application from Application Information Database.
        All data related to the appid are loaded in the memory after calling this function.
@@ -695,7 +698,7 @@ static ail_error_e _get_name(const char *appid)
  * @endcode
  */
 ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *handle);
-
+ail_error_e ail_get_usr_appinfo(const char *appid, uid_t uid, ail_appinfo_h *handle);
 
 /**
  * @fn ail_error_e ail_appinfo_get_bool(const ail_appinfo_h handle, const char *property, bool *value)
@@ -809,11 +812,9 @@ static ail_error_e _get_x_slp_baselayoutwidth(const char *appid)
  */
 ail_error_e ail_appinfo_get_int(const ail_appinfo_h handle, const char *property, int *value);
 
-
-
 /**
- * @fn ail_error_e ail_appinfo_get_str(const ail_appinfo_h handle, const char *property, char **str)
- *
+ * @fn ail_error_e ail_appinfo_get_str(const ail_appinfo_h handle, const char *property, uid_t uid, char **str)
+ * @fn ail_error_e ail_appinfo_get_usr_str(const ail_appinfo_h handle, const char *property, char **str)
  * @brief get a string related to the property. 
        Before using this API, the handle is defined by calling ail_get_appinfo.
        This function needs a out-parameter for the value.
@@ -822,6 +823,7 @@ ail_error_e ail_appinfo_get_int(const ail_appinfo_h handle, const char *property
  *
  * @param[in] handle   the handle is defined by calling ail_get_appinfo.
  * @param[in] property a property type of string.
+ * @param[in]  uid     the addressee user id of the instruction
  * @param[out] str             a out-parameter string that is mapped with the property. The icon property contains the absolute file path. If there is no data, the value of str is NULL.
  *
  * @return 0 if success, negative value(<0) if fail\n
@@ -865,7 +867,7 @@ static ail_error_e _get_nodisplay(const char *appid)
  * @endcode
  */
 ail_error_e ail_appinfo_get_str(const ail_appinfo_h handle, const char *property, char **str);
-
+ail_error_e ail_appinfo_get_usr_str(const ail_appinfo_h handle, const char *property, uid_t uid, char **str);
 
 
 /**
@@ -1027,8 +1029,8 @@ ail_error_e ail_close_appinfo_db(void);
 
 
 /**
- * @fn ail_error_e ail_desktop_add(const char *appid)
- *
+ * @fn ail_error_e ail_desktop_add(const char *appid)
+ * @fn ail_error_e ail_usr_desktop_add(const char *appid, uid_t uid)
  * @brief add a app information into Application Information Database.
        A desktop file for this app has to be installed in the desktop directory before using this API.
        If there is no database for Application Information Database, this API will create the DB.
@@ -1038,6 +1040,7 @@ ail_error_e ail_close_appinfo_db(void);
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] appid
+ * @param[in]  uid     the addressee user id of the instruction
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -1071,12 +1074,12 @@ static ail_error_e _add_desktop(const char *appid)
  * @endcode
  */
 ail_error_e ail_desktop_add(const char *appid);
-
+ail_error_e ail_usr_desktop_add(const char *appid, uid_t uid);
 
 
 /**
  * @fn ail_error_e ail_desktop_update(const char *appid)
- *
+ * @fn ail_error_e ail_usr_desktop_update(const char *appid,  uid_t uid)
  * @brief update a app information in the Application Information Database.
        A desktop file for this app has to be installed in the desktop directory before using this API.
        And a notification is published to the applications who want to know about changing DB. 
@@ -1084,6 +1087,7 @@ ail_error_e ail_desktop_add(const char *appid);
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] appid
+ * @param[in] uid      ID of the owner of the application
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -1117,18 +1121,19 @@ static ail_error_e _update_desktop(const char *appid)
  * @endcode
  */
 ail_error_e ail_desktop_update(const char *appid);
-
+ail_error_e ail_usr_desktop_update(const char *appid, uid_t uid);
 
 
 /**
  * @fn ail_error_e ail_desktop_remove(const char *appid)
- *
+ * @fn ail_error_e ail_usr_desktop_remove(const char *appid, uid_t uid)
  * @brief remove a app information in the Application Information Database.
        And a notification is published to the applications who want to know about changing DB. 
  *
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] appid
+ * @param[in]  uid     the addressee user id of the instruction
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -1162,15 +1167,17 @@ static ail_error_e _remove_desktop(const char *appid)
  * @endcode
  */
 ail_error_e ail_desktop_remove(const char *appid);
+ail_error_e ail_usr_desktop_remove(const char *appid, uid_t uid);
 
 /**
  * @fn ail_error_e ail_desktop_clean(const char *pkgid)
- *
+ * @fn ail_error_e ail_usr_desktop_clean(const char *pkgid, uid_t uid))
  * @brief clean a pkg information in the Application Information Database.
  *
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] pkgid
+ * @param[in] uid      ID of the owner of the application
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -1204,11 +1211,11 @@ static ail_error_e _clean_desktop(const char *pkgid)
  * @endcode
  */
 ail_error_e ail_desktop_clean(const char *pkgid);
-
+ail_error_e ail_usr_desktop_clean(const char *pkgid, uid_t uid);
 
 /**
  * @fn ail_error_e ail_desktop_fota(const char *appid)
- *
+ * @fn ail_error_e ail_usr_desktop_fota(const char *appid, uid_t uid)
  * @brief add a app information into Application Information Database.
        A desktop file for this app has to be installed in the desktop directory before using this API.
        If there is no database for Application Information Database, this API will create the DB.
@@ -1218,6 +1225,7 @@ ail_error_e ail_desktop_clean(const char *pkgid);
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] appid
+ * @param[in]  uid     the addressee user id of the instruction
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -1251,16 +1259,17 @@ static ail_error_e _add_desktop_fota(const char *appid)
  * @endcode
  */
 ail_error_e ail_desktop_fota(const char *appid);
-
+ail_error_e ail_usr_desktop_fota(const char *appid, uid_t uid);
 /**
- * @fn ail_error_e ail_desktop_appinfo_modify_str(const char *appid, const char *property, const char *value, bool broadcast)
- *
+ *@fn ail_error_e ail_desktop_appinfo_modify_str(const char *appid, const char *property, const char *value, bool broadcast)
+ * @fn ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid, uid_t uid, const char *property, const char *value, bool broadcast)
  * @brief update a app information db.
        And a notification is published to the applications who want to know about changing DB.
  *
  * @par Sync (or) Async : Synchronous API.
  *
  * @param[in] appid
+ * @param[in] uid      ID of the owner of the application
  *
  * @return 0 if success, negative value(<0) if fail\n
  * @retval     AIL_ERROR_OK                                    success
@@ -1275,7 +1284,7 @@ ail_error_e ail_desktop_fota(const char *appid);
  * External Apps.
  *
  * @code
-static ail_error_e _appinfo_modify_str(const char *appid, const char *property, const char *value, bool broadcast)
+static ail_error_e _appinfo_modify_str(const char *appid, uid_t uid, const char *property, const char *value, bool broadcast)
 {
        ail_error_e ret;
 
@@ -1300,7 +1309,7 @@ static ail_error_e _appinfo_modify_str(const char *appid, const char *property,
  */
 
 ail_error_e ail_desktop_appinfo_modify_str(const char *appid, const char *property, const char *value, bool broadcast);
-
+ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid, uid_t uid, const char *property, const char *value, bool broadcast);
 /** @} */
 
 
index 673ca7d..02181e6 100755 (executable)
@@ -60,7 +60,7 @@ static int initdb_count_app(void)
                return -1;
        }
 
-       ret = ail_filter_count_appinfo(filter, &total);
+       ret = ail_filter_count_appinfo(filter, &total, getuid());
        if (ret != AIL_ERROR_OK) {
                ail_filter_destroy(filter);
                return -1;
@@ -135,7 +135,7 @@ int initdb_load_directory(const char *directory)
                        continue;
                }
 
-               if (ail_desktop_add(package) != AIL_ERROR_OK) {
+               if (ail_desktop_add(package, getuid()) != AIL_ERROR_OK) {
                        _E("Failed to add a package[%s]", package);
                } else {
                        ok_cnt++;
@@ -237,7 +237,7 @@ int main(int argc, char *argv[])
        if (!__is_authorized()) {
                fprintf(stderr, "You are not an authorized user!\n");
                _D("You are not root user!\n");
-
+               exit(-1);
     }
     else {
        const char *argv_rm[] = { "/bin/rm", APP_INFO_DB_FILE, NULL };
index 5da089d..c886865 100755 (executable)
@@ -40,8 +40,9 @@ export CXXFLAGS="$CXXFLAGS ?DTIZEN_ENGINEER_MODE"
 export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
 %endif
 
-%cmake .  -DBUILD_PKGTYPE=rpm \
-          -DSMACK=Off
+%cmake .  -DTZ_SYS_RW_DESKTOP_APP=%TZ_SYS_RW_DESKTOP_APP \
+          -DBUILD_PKGTYPE=rpm \
+                 -DSMACK=Off
 
 %__make %{?_smp_mflags}
 
index 4b2dafa..df5fc64 100755 (executable)
 #include <stdlib.h>
 #include <string.h>
 #include <db-util.h>
+#include <errno.h>
 #include <glib.h>
+#include <grp.h>
+#include <pwd.h>
+#include <sys/stat.h>
 #include "ail_private.h"
 #include "ail_db.h"
 
+#define GLOBAL_USER    0 //#define     tzplatform_getenv(TZ_GLOBAL) //TODO
+#define BUFSIZE 4096
+#define QUERY_ATTACH "attach database '%s' as Global"
+#define QUERY_CREATE_VIEW_APP "CREATE temp VIEW app_info as select distinct * from (select  * from main.app_info m union select * from Global.app_info g)"
+
+#define QUERY_CREATE_VIEW_LOCAL "CREATE temp VIEW localname as select distinct * from (select  * from main.localname m union select * from Global.localname g)"
+
 #define retv_with_dbmsg_if(expr, val) do { \
        if (expr) { \
-               _E("db_info.dbro: %s", sqlite3_errmsg(db_info.dbro)); \
-               _E("db_info.dbrw: %s", sqlite3_errmsg(db_info.dbrw)); \
-               _E("db_info.dbro errcode: %d", sqlite3_extended_errcode(db_info.dbro)); \
-               _E("db_info.dbrw errcode: %d", sqlite3_extended_errcode(db_info.dbrw)); \
+               _E("db_info.dbUserro: %s", sqlite3_errmsg(db_info.dbUserro)); \
+               _E("db_info.dbGlobalro: %s", sqlite3_errmsg(db_info.dbGlobalro)); \
+               _E("db_info.dbUserrw: %s", sqlite3_errmsg(db_info.dbUserrw)); \
+               _E("db_info.dbGlobalrw: %s", sqlite3_errmsg(db_info.dbGlobalrw)); \
+               _E("db_info.dbUserro errcode: %d", sqlite3_extended_errcode(db_info.dbUserro)); \
+               _E("db_info.dbGlobalro errcode: %d", sqlite3_extended_errcode(db_info.dbGlobalro)); \
+               _E("db_info.dbUserrw errcode: %d", sqlite3_extended_errcode(db_info.dbUserrw)); \
+               _E("db_info.dbGlobalrw errcode: %d", sqlite3_extended_errcode(db_info.dbGlobalrw)); \
                return (val); \
        } \
 } while (0)
 
-
 static __thread struct {
-        sqlite3         *dbro;
-        sqlite3         *dbrw;
+        sqlite3         *dbUserro;
+        sqlite3         *dbGlobalro;
+        sqlite3         *dbUserrw;
+        sqlite3         *dbGlobalrw;
 } db_info = {
-        .dbro = NULL,
-       .dbrw = NULL
+        .dbUserro = NULL,
+        .dbGlobalro = NULL,
+        .dbUserrw = NULL,
+        .dbGlobalrw = NULL
 };
+  static __thread      sqlite3         *dbInit = NULL;
+
+static int ail_db_change_perm(const char *db_file)
+{
+       char buf[BUFSIZE];
+       char journal_file[BUFSIZE];
+       char *files[3];
+       int ret, i;
+       struct group *grpinfo = NULL;
+       const char *name = "users";
+
+       files[0] = (char *)db_file;
+       files[1] = journal_file;
+       files[2] = NULL;
+
+       retv_if(!db_file, AIL_ERROR_FAIL);
+       if(getuid()) //At this time we should be root to apply this
+                       return AIL_ERROR_OK;
+
+       snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
+
+       for (i = 0; files[i]; i++) {
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL)
+                       _E("getgrnam(users) returns NULL !");
+
+               // Compare git_t type and not group name
+               ret = chown(files[i], OWNER_ROOT, grpinfo->gr_gid);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, grpinfo->gr_gid, buf);
+                       return AIL_ERROR_FAIL;
+               }
+
+               ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chmod %s 0664, because %s", db_file, buf);
+                       return AIL_ERROR_FAIL;
+               }
+       }
+
+       return AIL_ERROR_OK;
+}
+
+char* ail_get_icon_path(uid_t uid)
+{
+       char *result_psswd = NULL;
+       if(uid == GLOBAL_USER)
+       {
+               result_psswd = tzplatform_getenv(TZ_SYS_RW_ICONS);
+       }
+       else
+       {
+               const char *name = "users";
+               struct passwd *userinfo = NULL;
+               struct group *grpinfo = NULL;
+
+               userinfo = getpwuid(uid);
+               if(userinfo == NULL) {
+                       _E("getpwuid(%d) returns NULL !", uid);
+                       return NULL;
+               }
+               
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL) {
+                       _E("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid) {
+                       _E("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }
+               result_psswd = tzplatform_getenv(TZ_USER_ICONS);
+       }
+       return result_psswd;
+}
 
-static char* getUserAppDB(void) 
+static char* ail_get_app_DB(uid_t uid)
 {
-  if(getuid())
-    return tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.app_info.db"); 
-   else 
-    return APP_INFO_DB_FILE;
+       char *result_psswd = NULL;
+       struct group *grpinfo = NULL;
+       char * dir = NULL;
+       if(uid == GLOBAL_USER)
+       {
+               result_psswd = strdup(APP_INFO_DB_FILE);
+               grpinfo = getgrnam("root");
+               if(grpinfo == NULL) {
+                       _E("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+       }
+       else
+       {
+               struct passwd *userinfo = getpwuid(uid);
+               if(userinfo == NULL) {
+                       _E("getpwuid(%d) returns NULL !", uid);
+                       return NULL;
+               }
+               grpinfo = getgrnam("users");
+               if(grpinfo == NULL) {
+                       _E("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid) {
+                       _E("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }
+               asprintf(&result_psswd, "%s/.applications/dbspace/.app_info.db", userinfo->pw_dir);
+       }
+
+       dir = strrchr(result_psswd, '/');
+       if(!dir)
+               return result_psswd;
+
+       //Control if db exist create otherwise 
+       if(access(dir + 1, F_OK)) {
+               int ret;
+               mkdir(dir + 1, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+               ret = chown(dir + 1, uid, grpinfo->gr_gid);
+               if (ret == -1) {
+                       char buf[BUFSIZE];
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", dir + 1, uid, grpinfo->gr_gid, buf);
+               }
+       }       
+       return result_psswd;
 }
 
 static ail_error_e db_do_prepare(sqlite3 *db, const char *query, sqlite3_stmt **stmt)
@@ -72,37 +212,139 @@ static ail_error_e db_do_prepare(sqlite3 *db, const char *query, sqlite3_stmt **
                return AIL_ERROR_OK;
 }
 
-ail_error_e db_open(db_open_mode mode)
+ail_error_e db_open(db_open_mode mode, uid_t uid)
 {
        int ret;
        int changed = 0;
-
+       int i;
+       const char *tbls[3] = {
+               "CREATE TABLE app_info "
+               "(package TEXT PRIMARY KEY, "
+               "exec TEXT DEFAULT 'No Exec', "
+               "name TEXT DEFAULT 'No Name', "
+               "type TEXT DEFAULT 'Application', "
+               "icon TEXT DEFAULT 'No Icon', "
+               "categories TEXT, "
+               "version TEXT, "
+               "mimetype TEXT, "
+               "x_slp_service TEXT, "
+               "x_slp_packagetype TEXT, "
+               "x_slp_packagecategories TEXT, "
+               "x_slp_packageid TEXT, "
+               "x_slp_uri TEXT, "
+               "x_slp_svc TEXT, "
+               "x_slp_exe_path TEXT, "
+               "x_slp_appid TEXT, "
+               "x_slp_pkgid TEXT, "
+               "x_slp_domain TEXT, "
+               "x_slp_submodemainid TEXT, "
+               "x_slp_installedstorage TEXT, "
+               "x_slp_baselayoutwidth INTEGER DEFAULT 0, "
+               "x_slp_installedtime INTEGER DEFAULT 0, "
+               "nodisplay INTEGER DEFAULT 0, "
+               "x_slp_taskmanage INTEGER DEFAULT 1, "
+               "x_slp_multiple INTEGER DEFAULT 0, "
+               "x_slp_removable INTEGER DEFAULT 1, "
+               "x_slp_ishorizontalscale INTEGER DEFAULT 0, "
+               "x_slp_enabled INTEGER DEFAULT 1, "
+               "x_slp_submode INTEGER DEFAULT 0, "
+               "desktop TEXT UNIQUE NOT NULL);",
+               "CREATE TABLE localname (package TEXT NOT NULL, "
+               "locale TEXT NOT NULL, "
+               "name TEXT NOT NULL, "
+               "x_slp_pkgid TEXT NOT NULL, PRIMARY KEY (package, locale));",
+
+               NULL
+       };
+
+       if (access(ail_get_app_DB(uid), F_OK)) {
+               if (AIL_ERROR_OK == db_util_open_with_options(ail_get_app_DB(uid), &dbInit, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL))
+               {
+                       for (i = 0; tbls[i] != NULL; i++) {
+                               ret = do_db_exec(tbls[i], dbInit);
+                               retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+                       }
+               } else {
+                       dbInit = NULL;
+                       _E("Failed to create table %s\n",ail_get_app_DB(uid));
+               }
+       }
+       if(dbInit) {
+               if(AIL_ERROR_OK != ail_db_change_perm(ail_get_app_DB(uid))) {
+                               _E("Failed to change permission\n");
+               }
+               ret = sqlite3_close(dbInit);
+               retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+               dbInit = NULL;
+       }
        if(mode & DB_OPEN_RO) {
-               if (!db_info.dbro) {
-                       //ret = db_util_open_with_options(APP_INFO_DB, &db_info.dbro, SQLITE_OPEN_READONLY, NULL);
-                       ret = db_util_open(getUserAppDB(), &db_info.dbro, 0);
-                       retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+               if (!db_info.dbUserro) {
+                       db_util_open_with_options(ail_get_app_DB(uid), &db_info.dbUserro, SQLITE_OPEN_READONLY, NULL);
+                       char query_attach[AIL_SQL_QUERY_MAX_LEN];
+                       char query_view_app[AIL_SQL_QUERY_MAX_LEN];
+                       char query_view_local[AIL_SQL_QUERY_MAX_LEN];
+                       snprintf(query_attach, AIL_SQL_QUERY_MAX_LEN, QUERY_ATTACH, ail_get_app_DB(GLOBAL_USER));
+                       _E("info : execute query_attach : %s", query_attach );
+                       if (db_exec_usr_ro(query_attach) < 0) {
+                               return AIL_ERROR_DB_FAILED;
+                       }
+                       snprintf(query_view_app, AIL_SQL_QUERY_MAX_LEN, QUERY_CREATE_VIEW_APP);
+                       _E("info : execute query_attach : %s", query_view_app );
+                       if (db_exec_usr_ro(query_view_app) < 0) {
+                               return AIL_ERROR_DB_FAILED;
+                       }
+
+                       snprintf(query_view_local, AIL_SQL_QUERY_MAX_LEN, QUERY_CREATE_VIEW_LOCAL);
+                       _E("info : execute query_attach : %s", query_view_local );
+                       if (db_exec_usr_ro(query_view_local) < 0) {
+                               return AIL_ERROR_DB_FAILED;
+                       }
                }
+               if (!db_info.dbGlobalro) {
+                               ret = db_util_open_with_options(ail_get_app_DB(GLOBAL_USER), &db_info.dbGlobalro, SQLITE_OPEN_READONLY, NULL);
+                               retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+                       }
        }
 
        if(mode & DB_OPEN_RW) {
-               if (!db_info.dbrw) {
-                       ret = db_util_open(getUserAppDB(), &db_info.dbrw, 0);
-                       retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+               //if (__is_admin) {
+               if(uid != GLOBAL_USER) {//TOCHANGETO is_admin
+                       if(!db_info.dbUserrw){
+                               ret = db_util_open(ail_get_app_DB(uid), &db_info.dbUserrw, 0);
+                       }
+               } else {
+                       if(!db_info.dbGlobalrw){
+                               ret = db_util_open(ail_get_app_DB(GLOBAL_USER), &db_info.dbGlobalrw, 0);
+                       }
                }
+               retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+       
+               //}
        }
 
        return AIL_ERROR_OK;
 }
 
+
 ail_error_e db_prepare(const char *query, sqlite3_stmt **stmt)
 {
-       return db_do_prepare(db_info.dbro, query, stmt);
+       return db_do_prepare(db_info.dbUserro, query, stmt);
+}
+
+ail_error_e db_prepare_globalro(const char *query, sqlite3_stmt **stmt)
+{
+       return db_do_prepare(db_info.dbGlobalro, query, stmt);
 }
 
 ail_error_e db_prepare_rw(const char *query, sqlite3_stmt **stmt)
 {
-       return db_do_prepare(db_info.dbrw, query, stmt);
+       return db_do_prepare(db_info.dbUserrw, query, stmt);
+}
+
+
+ail_error_e db_prepare_globalrw(const char *query, sqlite3_stmt **stmt)
+{
+       return db_do_prepare(db_info.dbGlobalrw, query, stmt);
 }
 
 
@@ -233,15 +475,15 @@ ail_error_e db_finalize(sqlite3_stmt *stmt)
 
 
 
-ail_error_e db_exec(const char *query)
+ail_error_e do_db_exec(const char *query, sqlite3 * fileSQL)
 {
        int ret;
        char *errmsg;
 
        retv_if(!query, AIL_ERROR_INVALID_PARAMETER);
-       retv_if(!db_info.dbrw, AIL_ERROR_DB_FAILED);
+       retv_if(!fileSQL, AIL_ERROR_DB_FAILED);
 
-       ret = sqlite3_exec(db_info.dbrw, query, NULL, NULL, &errmsg);
+       ret = sqlite3_exec(fileSQL, query, NULL, NULL, &errmsg);
        if (ret != SQLITE_OK) {
                _E("Cannot execute this query - %s. because %s",
                                query, errmsg? errmsg:"uncatched error");
@@ -254,21 +496,49 @@ ail_error_e db_exec(const char *query)
 
 
 
+ail_error_e db_exec_usr_rw(const char *query)
+{
+       return do_db_exec(query, db_info.dbUserrw);
+}
+
+
+ail_error_e db_exec_usr_ro(const char *query)
+{
+       return do_db_exec(query, db_info.dbUserro);
+}
+
+ail_error_e db_exec_glo_ro(const char *query)
+{
+       return do_db_exec(query, db_info.dbGlobalro);
+}
+
+ail_error_e db_exec_glo_rw(const char *query)
+{
+       return do_db_exec(query, db_info.dbGlobalrw);
+}
+
+
 ail_error_e db_close(void)
 {
        int ret;
 
-       if(db_info.dbro) {
-               ret = sqlite3_close(db_info.dbro);
+       if(db_info.dbUserro) {
+               ret = sqlite3_close(db_info.dbUserro);
+               retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
+
+               db_info.dbUserro = NULL;
+       }
+       if(db_info.dbGlobalrw) {
+               ret = sqlite3_close(db_info.dbGlobalrw);
                retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
 
-               db_info.dbro = NULL;
+               db_info.dbGlobalrw = NULL;
        }
-       if(db_info.dbrw) {
-               ret = sqlite3_close(db_info.dbrw);
+       if(db_info.dbUserrw) {
+               ret = sqlite3_close(db_info.dbUserrw);
                retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
 
-               db_info.dbrw = NULL;
+               db_info.dbUserrw = NULL;
        }
 
        return AIL_ERROR_OK;
@@ -282,12 +552,23 @@ EXPORT_API ail_error_e ail_db_close(void)
 int db_exec_sqlite_query(char *query, sqlite_query_callback callback, void *data)
 {
        char *error_message = NULL;
-       if (SQLITE_OK !=
-           sqlite3_exec(db_info.dbro, query, callback, data, &error_message)) {
-               _E("Don't execute query = %s error message = %s\n", query,
-                      error_message);
-               sqlite3_free(error_message);
-               return -1;
+       if(db_info.dbUserro) {
+               if (SQLITE_OK !=
+                       sqlite3_exec(db_info.dbUserro, query, callback, data, &error_message)) {
+                       _E("Don't execute query = %s error message = %s\n", query,
+                               error_message);
+                       sqlite3_free(error_message);
+                       return -1;
+               }
+       }
+       if(db_info.dbUserro) {
+               if (SQLITE_OK !=
+                       sqlite3_exec(db_info.dbUserro, query, callback, data, &error_message)) {
+                       _E("Don't execute query = %s error message = %s\n", query,
+                               error_message);
+                       sqlite3_free(error_message);
+                       return -1;
+               }
        }
        sqlite3_free(error_message);
        return 0;
index a8b8b4b..e1ec80a 100755 (executable)
@@ -36,9 +36,13 @@ typedef enum {
 } db_open_mode;
 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
 
-ail_error_e db_open(db_open_mode mode);
+static int ail_db_change_perm(const char *db_file);
+char* ail_get_icon_path(uid_t uid);
+ail_error_e db_open(db_open_mode mode, uid_t uid);
 ail_error_e db_prepare(const char *query, sqlite3_stmt **stmt);
+ail_error_e db_prepare_globalro(const char *query, sqlite3_stmt **stmt);
 ail_error_e db_prepare_rw(const char *query, sqlite3_stmt **stmt);
+ail_error_e db_prepare_globalrw(const char *query, sqlite3_stmt **stmt);
 
 ail_error_e db_bind_bool(sqlite3_stmt *stmt, int idx, bool value);
 ail_error_e db_bind_int(sqlite3_stmt *stmt, int idx, int value);
@@ -53,8 +57,9 @@ ail_error_e db_column_str(sqlite3_stmt *stmt, int index, char **str);
 ail_error_e db_reset(sqlite3_stmt *stmt);
 ail_error_e db_finalize(sqlite3_stmt *stmt);
 
-
-ail_error_e db_exec(const char *query);
+ail_error_e do_db_exec(const char *query,sqlite3 * fileSQL);
+ail_error_e db_exec_usr_rw(const char *query);
+ail_error_e db_exec_usr_ro(const char *query);
 ail_error_e db_close(void);
 int db_exec_sqlite_query(char *query, sqlite_query_callback callback, void *data);
 #endif
index d79e288..769bd13 100755 (executable)
@@ -22,6 +22,7 @@
 
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
 #include <vconf.h>
 #include <glib.h>
+#include <grp.h>
+#include <pwd.h>
 
 #include "ail_private.h"
 #include "ail_db.h"
 #include "ail_sql.h"
 #include "ail.h"
 
-#define BUFSZE 4096
+#define BUFSIZE 4096
 
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
 #define argsdelimiter  " \t"
@@ -239,7 +242,7 @@ _get_package_from_icon(char* icon)
 
 
 static char*
-_get_icon_with_path(char* icon)
+_get_icon_with_path(char* icon, uid_t uid)
 {
        retv_if(!icon, NULL);
 
@@ -277,27 +280,27 @@ _get_icon_with_path(char* icon)
 
                memset(icon_with_path, 0, len);
 
-               sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
+               sqlite3_snprintf( len, icon_with_path,"%s/%q/small/%q", ail_get_icon_path(uid), theme, icon);
                do {
                        if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
+                       sqlite3_snprintf( len, icon_with_path,"%s/%q/small/%q", tzplatform_getenv(TZ_SYS_RO_ICONS), theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        _D("cannot find icon %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
+                       sqlite3_snprintf( len, icon_with_path, "%s/default/small/%q", ail_get_icon_path(uid), icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
+                       sqlite3_snprintf( len, icon_with_path, "%s/default/small/%q", tzplatform_getenv(TZ_SYS_RO_ICONS), icon);
                        if (access(icon_with_path, R_OK) == 0) break;
 
                        #if 1 /* this will be remove when finish the work for moving icon path */
                        _E("icon file must be moved to %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path,  "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
+                       sqlite3_snprintf( len, icon_with_path,  "%s/%q/res/icons/%q/small/%q", tzplatform_getenv(TZ_SYS_RW_APP), package, theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
+                       sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/%q/small/%q", tzplatform_getenv(TZ_SYS_RO_APP), package, theme, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        _D("cannot find icon %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
+                       sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/default/small/%q", tzplatform_getenv(TZ_SYS_RW_APP), package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
+                       sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/default/small/%q", tzplatform_getenv(TZ_SYS_RO_APP), package, icon);
                        if (access(icon_with_path, R_OK) == 0) break;
                        #endif
                } while (0);
@@ -318,14 +321,14 @@ _get_icon_with_path(char* icon)
 }
 
 
-static ail_error_e _read_icon(void *data, char *tag, char *value)
+static ail_error_e _read_icon(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
        retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
        retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
 
-       info->icon = _get_icon_with_path(value);
+       info->icon = _get_icon_with_path(value, uid);
 
        retv_if (!info->icon, AIL_ERROR_OUT_OF_MEMORY);
 
@@ -772,12 +775,15 @@ static struct entry_parser entry_parsers[] = {
 
 
 /* Utility functions */
-static int _count_all(void)
+static int _count_all(uid_t uid)
 {
        ail_error_e ret;
        int count;
 
-       ret = ail_filter_count_appinfo(NULL, &count);
+       if (uid != GLOBAL_USER)
+               ret = ail_filter_count_usr_appinfo(NULL, &count, uid);
+       else
+               ret = ail_filter_count_appinfo(NULL, &count);   
        if(ret != AIL_ERROR_OK) {
                _E("cannot count appinfo");
                count = -1;
@@ -788,21 +794,53 @@ static int _count_all(void)
        return count;
 }
 
-char *_pkgname_to_desktop(const char *package)
+char *_pkgname_to_desktop(const char *package, uid_t uid)
 {
        char *desktop;
-  char *desktop_path;
+       char *desktop_path;
        int size;
 
        retv_if(!package, NULL);
 
-       if(getuid() > 0)
-  {
+       if(uid != GLOBAL_USER)
+    {
     desktop_path = tzplatform_mkpath(TZ_USER_HOME, ".applications/desktop");
+    if(access(desktop_path, F_OK)) {
+               struct group *grpinfo = NULL;
+               const char *name = "users"; //to change
+               int ret;
+               char buf[BUFSIZE];
+               mkdir(desktop_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL)
+                       _E("getgrnam(users) returns NULL !");
+
+               ret = chown(desktop_path, uid, grpinfo->gr_gid);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", desktop_path, uid, grpinfo->gr_gid, buf);
+               }       
+       }
   }
   else
   {
     desktop_path = tzplatform_getenv(TZ_SYS_RW_DESKTOP_APP);
+    if(access(desktop_path, F_OK)) {
+               struct group *grpinfo = NULL;
+               const char *name = "root"; //to change
+               int ret;
+               char buf[BUFSIZE];
+               mkdir(desktop_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+               grpinfo = getgrnam(name);
+               if(grpinfo == NULL)
+                       _E("getgrnam(users) returns NULL !");
+
+               ret = chown(desktop_path, uid, grpinfo->gr_gid);
+               if (ret == -1) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", desktop_path, uid, grpinfo->gr_gid, buf);
+               }       
+       }
   }
 
        size = strlen(desktop_path) + strlen(package) + 10;
@@ -811,7 +849,7 @@ char *_pkgname_to_desktop(const char *package)
 
   snprintf(desktop, size, "%s/%s.desktop", desktop_path, package);
 
-  _D("uid: %d / desktop: [%s]\n",  getuid(), desktop);
+  _D("uid: %d / desktop: [%s]\n",  uid, desktop);
 
        return desktop;
 }
@@ -860,7 +898,7 @@ static inline int _len_local_info(desktop_info_s* info)
 }
 
 
-static inline int _insert_local_info(desktop_info_s* info)
+static inline int _insert_local_info(desktop_info_s* info, uid_t uid)
 {
        int len_query = SQL_INSERT_LOCALNAME_STR_LEN;
        int nb_locale_args;
@@ -884,7 +922,10 @@ static inline int _insert_local_info(desktop_info_s* info)
                strcat(query, SQL_LOCALNAME_TRIPLET_STR);
 
        do {
-               ret = db_prepare_rw(query, &stmt);
+               if(uid != GLOBAL_USER)
+                       ret = db_prepare_rw(query, &stmt);
+               else 
+                       ret = db_prepare_globalrw(query, &stmt);
                if (ret < 0) break;
 
                ret = _bind_local_info(info, stmt);
@@ -947,7 +988,7 @@ int __is_ail_initdb(void)
 }
 
 /* Manipulating desktop_info functions */
-static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
+static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package, uid_t uid)
 {
        static int is_initdb = -1;
 
@@ -985,7 +1026,7 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
 
        info->x_slp_enabled = 1;
 
-       info->desktop = _pkgname_to_desktop(package);
+       info->desktop = _pkgname_to_desktop(package, uid);
        retv_if(!info->desktop, AIL_ERROR_FAIL);
 
   _D("desktop - [%s].", info->desktop);
@@ -1129,7 +1170,7 @@ NEXT:
 }
 
 
-static ail_error_e _load_desktop_info(desktop_info_s* info)
+static ail_error_e _load_desktop_info(desktop_info_s* info, uid_t uid)
 {
        ail_error_e ret;
        char query[AIL_SQL_QUERY_MAX_LEN];
@@ -1143,10 +1184,11 @@ static ail_error_e _load_desktop_info(desktop_info_s* info)
        snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s",SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w);
 
        do {
-               ret = db_open(DB_OPEN_RO);
+               ret = db_open(DB_OPEN_RO, uid);
                if (ret < 0) break;
-
+//is_admin
                ret = db_prepare(query, &stmt);
+               //ret = db_prepare_globalro(query, &stmt);
                if (ret < 0) break;
 
                ret = db_step(stmt);
@@ -1234,65 +1276,7 @@ static ail_error_e _modify_desktop_info_str(desktop_info_s* info,
 }
 
 
-
-
-static ail_error_e _create_table(void)
-{
-       int i;
-       ail_error_e ret;
-       const char *tbls[3] = {
-               "CREATE TABLE app_info "
-               "(package TEXT PRIMARY KEY, "
-               "exec TEXT DEFAULT 'No Exec', "
-               "name TEXT DEFAULT 'No Name', "
-               "type TEXT DEFAULT 'Application', "
-               "icon TEXT DEFAULT 'No Icon', "
-               "categories TEXT, "
-               "version TEXT, "
-               "mimetype TEXT, "
-               "x_slp_service TEXT, "
-               "x_slp_packagetype TEXT, "
-               "x_slp_packagecategories TEXT, "
-               "x_slp_packageid TEXT, "
-               "x_slp_uri TEXT, "
-               "x_slp_svc TEXT, "
-               "x_slp_exe_path TEXT, "
-               "x_slp_appid TEXT, "
-               "x_slp_pkgid TEXT, "
-               "x_slp_domain TEXT, "
-               "x_slp_submodemainid TEXT, "
-               "x_slp_installedstorage TEXT, "
-               "x_slp_baselayoutwidth INTEGER DEFAULT 0, "
-               "x_slp_installedtime INTEGER DEFAULT 0, "
-               "nodisplay INTEGER DEFAULT 0, "
-               "x_slp_taskmanage INTEGER DEFAULT 1, "
-               "x_slp_multiple INTEGER DEFAULT 0, "
-               "x_slp_removable INTEGER DEFAULT 1, "
-               "x_slp_ishorizontalscale INTEGER DEFAULT 0, "
-               "x_slp_enabled INTEGER DEFAULT 1, "
-               "x_slp_submode INTEGER DEFAULT 0, "
-               "desktop TEXT UNIQUE NOT NULL);",
-               "CREATE TABLE localname (package TEXT NOT NULL, "
-               "locale TEXT NOT NULL, "
-               "name TEXT NOT NULL, "
-               "x_slp_pkgid TEXT NOT NULL, PRIMARY KEY (package, locale));",
-
-               NULL
-       };
-
-       ret = db_open(DB_OPEN_RW);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
-
-       for (i = 0; tbls[i] != NULL; i++) {
-               ret = db_exec(tbls[i]);
-               retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
-       }
-
-       return AIL_ERROR_OK;
-}
-
-
-static inline void _insert_localname(gpointer data, gpointer user_data)
+static inline void _insert_localname(gpointer data, gpointer user_data, uid_t uid)
 {
        char query[512];
 
@@ -1302,11 +1286,16 @@ static inline void _insert_localname(gpointer data, gpointer user_data)
        sqlite3_snprintf(sizeof(query), query, "insert into localname (package, locale, name, x_slp_pkgid) "
                        "values ('%q', '%q', '%q', '%q');",
                        info->package, item->locale, item->name, info->x_slp_pkgid);
-       if (db_exec(query) < 0)
-               _E("Failed to insert local name of package[%s]",info->package);
+       if(uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0)
+                       _E("Failed to insert local name of package[%s]",info->package);
+       } else {
+               if (db_exec_glo_rw(query) < 0)
+                       _E("Failed to insert local name of package[%s]",info->package);
+       }
 }
 
-static ail_error_e _insert_desktop_info(desktop_info_s *info)
+static ail_error_e _insert_desktop_info(desktop_info_s *info, uid_t uid)
 {
        char *query;
        int len;
@@ -1386,19 +1375,22 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info)
                info->desktop
                );
 
-       ret = db_open(DB_OPEN_RW);
+       ret = db_open(DB_OPEN_RW, uid);
        if(ret != AIL_ERROR_OK) {
                _E("(tmp == NULL) return\n");
                free(query);
                return AIL_ERROR_DB_FAILED;
        }
-
-       ret = db_exec(query);
+       if (uid != GLOBAL_USER)
+               ret = db_exec_usr_rw(query);
+       else
+               ret = db_exec_glo_rw(query);
+       
        free(query);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
 
        if (info->localname)
-               _insert_local_info(info);
+               _insert_local_info(info, uid);
 
        _D("Add (%s).", query);
 
@@ -1407,14 +1399,14 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info)
 
 
 
-static ail_error_e _update_desktop_info(desktop_info_s *info)
+static ail_error_e _update_desktop_info(desktop_info_s *info, uid_t uid)
 {
        char *query;
        int len;
 
        retv_if (NULL == info, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RW) < 0) {
+       if (db_open(DB_OPEN_RW, uid) < 0) {
                return AIL_ERROR_DB_FAILED;
        }
 
@@ -1484,20 +1476,31 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
                info->desktop,
                info->package);
 
-       if (db_exec(query) < 0) {
-               free (query);
-               return AIL_ERROR_DB_FAILED;
+       if(uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free (query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free (query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        snprintf(query, len, "delete from localname where package = '%s'", info->package);
-
-       if (db_exec(query) < 0) {
-               free (query);
-               return AIL_ERROR_DB_FAILED;
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free (query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free (query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        if (info->localname)
-               _insert_local_info(info);
+               _insert_local_info(info, uid);
 
        _D("Update (%s).", info->package);
 
@@ -1508,14 +1511,14 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
 
 
 
-static ail_error_e _remove_package(const char* package)
+static ail_error_e _remove_package(const char* package, uid_t uid)
 {
        char *query;
        int size;
 
        retv_if(!package, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RW) < 0) {
+       if (db_open(DB_OPEN_RW, uid) < 0) {
                return AIL_ERROR_DB_FAILED;
        }
 
@@ -1525,33 +1528,45 @@ static ail_error_e _remove_package(const char* package)
 
        snprintf(query, size, "delete from app_info where package = '%s'", package);
 
-       if (db_exec(query) < 0) {
-               free(query);
-               return AIL_ERROR_DB_FAILED;
+       if(uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        snprintf(query, size, "delete from localname where package = '%s'", package);
        _D("query=%s",query);
-
-       if (db_exec(query) < 0) {
-               free(query);
-               return AIL_ERROR_DB_FAILED;
+       
+       if(uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        _D("Remove (%s).", package);
        free(query);
 
        return AIL_ERROR_OK;
 }
 
-static ail_error_e _clean_pkgid_data(const char* pkgid)
+static ail_error_e _clean_pkgid_data(const char* pkgid, uid_t uid)
 {
        char *query;
        int size;
 
        retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RW) < 0) {
+       if (db_open(DB_OPEN_RW, uid) ){
                return AIL_ERROR_DB_FAILED;
        }
 
@@ -1561,19 +1576,31 @@ static ail_error_e _clean_pkgid_data(const char* pkgid)
 
        snprintf(query, size, "delete from app_info where x_slp_pkgid = '%s'", pkgid);
 
-       if (db_exec(query) < 0) {
-               free(query);
-               return AIL_ERROR_DB_FAILED;
+       if(uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        snprintf(query, size, "delete from localname where x_slp_pkgid = '%s'", pkgid);
        _D("query=%s",query);
 
-       if (db_exec(query) < 0) {
-               free(query);
-               return AIL_ERROR_DB_FAILED;
+       if(uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }       
        }
-
        _D("Clean pkgid data (%s).", pkgid);
        free(query);
 
@@ -1669,28 +1696,20 @@ static int __is_authorized()
 
 
 /* Public functions */
-EXPORT_API ail_error_e ail_desktop_add(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_add(const char *appid, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
-       int count;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
-       count = _count_all();
-       if (count <= 0) {
-               ret = _create_table();
-               if (ret != AIL_ERROR_OK) {
-                       _D("Cannot create a table. Maybe there is already a table.");
-               }
-       }
-       ret = _init_desktop_info(&info, appid);
+       ret = _init_desktop_info(&info, appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _read_desktop_info(&info);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
-       ret = _insert_desktop_info(&info);
+       ret = _insert_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _send_db_done_noti(NOTI_ADD, appid);
@@ -1701,22 +1720,25 @@ EXPORT_API ail_error_e ail_desktop_add(const char *appid)
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_desktop_add(const char *appid)
+{
+       return ail_usr_desktop_add(appid,GLOBAL_USER);
+}
 
-
-EXPORT_API ail_error_e ail_desktop_update(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_update(const char *appid, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
-       ret = _init_desktop_info(&info, appid);
+       ret = _init_desktop_info(&info, appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _read_desktop_info(&info);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
-       ret = _update_desktop_info(&info);
+       ret = _update_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _send_db_done_noti(NOTI_UPDATE, appid);
@@ -1727,15 +1749,19 @@ EXPORT_API ail_error_e ail_desktop_update(const char *appid)
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_desktop_update(const char *appid)
+{
+       return ail_usr_desktop_update(appid,GLOBAL_USER);
+}
 
 
-EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_remove(const char *appid, uid_t uid)
 {
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
-       ret = _remove_package(appid);
+       ret = _remove_package(appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _send_db_done_noti(NOTI_REMOVE, appid);
@@ -1744,7 +1770,13 @@ EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
        return AIL_ERROR_OK;
 }
 
-EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
+EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
+{
+       return ail_usr_desktop_remove(appid, GLOBAL_USER);
+}
+
+
+EXPORT_API ail_error_e ail_usr_desktop_clean(const char *pkgid, uid_t uid)
 {
        ail_error_e ret;
 
@@ -1752,36 +1784,31 @@ EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
 
        _D("ail_desktop_clean=%s",pkgid);
 
-       ret = _clean_pkgid_data(pkgid);
+       ret = _clean_pkgid_data(pkgid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
+{
+       return ail_usr_desktop_clean(pkgid, GLOBAL_USER);
+}
 
-EXPORT_API ail_error_e ail_desktop_fota(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_fota(const char *appid, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
-       int count;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
-       count = _count_all();
-       if (count <= 0) {
-               ret = _create_table();
-               if (ret != AIL_ERROR_OK) {
-                       _D("Cannot create a table. Maybe there is already a table.");
-               }
-       }
-
-       ret = _init_desktop_info(&info, appid);
+       ret = _init_desktop_info(&info, appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _read_desktop_info(&info);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
-       ret = _insert_desktop_info(&info);
+       ret = _insert_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        _fini_desktop_info(&info);
@@ -1789,10 +1816,16 @@ EXPORT_API ail_error_e ail_desktop_fota(const char *appid)
        return AIL_ERROR_OK;
 }
 
-EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
+EXPORT_API ail_error_e ail_desktop_fota(const char *appid)
+{
+       return ail_usr_desktop_fota(appid, GLOBAL_USER);
+}
+
+
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_bool(const char *appid,
                                                             const char *property,
                                                             bool value,
-                                                            bool broadcast)
+                                                            bool broadcast, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
@@ -1802,16 +1835,16 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
        retv_if(strcmp(property, AIL_PROP_X_SLP_ENABLED_BOOL),
                AIL_ERROR_INVALID_PARAMETER);
 
-       ret = _init_desktop_info(&info, appid);
+       ret = _init_desktop_info(&info, appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
-       ret = _load_desktop_info(&info);
+       ret = _load_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _modify_desktop_info_bool(&info, property, value);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
-       ret = _update_desktop_info(&info);
+       ret = _update_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        if (broadcast) {
@@ -1824,8 +1857,17 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
+                                                            const char *property,
+                                                            bool value,
+                                                            bool broadcast)
+{
+       return ail_desktop_appinfo_modify_usr_bool(appid, property, value, broadcast,
+                       GLOBAL_USER);
+}
+
 
-EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid, uid_t uid,
                                                             const char *property,
                                                             const char *value,
                                                             bool broadcast)
@@ -1835,10 +1877,10 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
-       ret = _init_desktop_info(&info, appid);
+       ret = _init_desktop_info(&info, appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
-       ret = _load_desktop_info(&info);
+       ret = _load_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        _D("info.name [%s], value [%s]", info.name, value);
@@ -1846,7 +1888,7 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
        _D("info.name [%s], value [%s]", info.name, value);
 
-       ret = _update_desktop_info(&info);
+       ret = _update_desktop_info(&info, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        if (broadcast) {
@@ -1859,4 +1901,13 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
+                                                            const char *property,
+                                                            const char *value,
+                                                            bool broadcast)
+{
+       return ail_desktop_appinfo_modify_usr_str(appid, GLOBAL_USER, property, value,
+                               broadcast);
+}
+
 // End of File
index 1c64201..627cd2c 100755 (executable)
@@ -252,7 +252,7 @@ EXPORT_API ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *cnt)
 
        retv_if(!cnt, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RO) != AIL_ERROR_OK)
+       if (db_open(DB_OPEN_RO, GLOBAL_USER) != AIL_ERROR_OK)
                return AIL_ERROR_DB_FAILED;
 
        snprintf(q, sizeof(q), "SELECT %s FROM %s", SQL_FLD_APP_INFO_WITH_LOCALNAME, SQL_TBL_APP_INFO_WITH_LOCALNAME);
@@ -278,12 +278,78 @@ EXPORT_API ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *cnt)
        }
        else
                _D("No filter exists. All records are retreived");
-
+//is_admin
        if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
                _E("db_prepare fail for query = %s",q);
                return AIL_ERROR_DB_FAILED;
        }
+/*     if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
+               _E("db_prepare fail for query = %s",q);
+               return AIL_ERROR_DB_FAILED;
+       }*/
+       ai = appinfo_create();
+
+       appinfo_set_stmt(ai, stmt);
+       while (db_step(stmt) == AIL_ERROR_OK) {
+
+               if(_appinfo_check_installed_storage(ai) != AIL_ERROR_OK)
+                       continue;
+
+               filter_count++;
+       }
+
+       db_finalize(stmt);
+
+       appinfo_destroy(ai);
+       *cnt = filter_count;
+
+       return AIL_ERROR_OK;
+}
+
+EXPORT_API ail_error_e ail_filter_count_usr_appinfo(ail_filter_h filter, int *cnt, uid_t uid)
+{
+       char q[AIL_SQL_QUERY_MAX_LEN];
+       char *w;
+       char *tmp_q;
+       char *l;
+       ail_cb_ret_e r;
+       sqlite3_stmt *stmt;
+       ail_appinfo_h ai;
+       int filter_count = 0;
+
+       retv_if(!cnt, AIL_ERROR_INVALID_PARAMETER);
 
+       if (db_open(DB_OPEN_RO, uid) != AIL_ERROR_OK)
+               return AIL_ERROR_DB_FAILED;
+
+       snprintf(q, sizeof(q), "SELECT %s FROM %s", SQL_FLD_APP_INFO_WITH_LOCALNAME, SQL_TBL_APP_INFO_WITH_LOCALNAME);
+
+       tmp_q = strdup(q);
+       retv_if (NULL == tmp_q, AIL_ERROR_OUT_OF_MEMORY);
+       l = sql_get_locale();
+       if (NULL == l) {
+               _E("Failed to get locale string");
+               free(tmp_q);
+               return AIL_ERROR_FAIL;
+       }
+       snprintf(q, sizeof(q), tmp_q, l);
+       free(l);
+       free(tmp_q);
+
+       if (filter && filter->list) {
+               w = _get_where_clause(filter);
+               retv_if (NULL == w, AIL_ERROR_FAIL);
+               strncat(q, w, sizeof(q)-strlen(q)-1);
+               q[sizeof(q)-1] = '\0';
+               free(w);
+       }
+       else
+               _D("No filter exists. All records are retreived");
+
+       if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
+               _E("db_prepare fail for query = %s",q);
+               return AIL_ERROR_DB_FAILED;
+       }
        ai = appinfo_create();
 
        appinfo_set_stmt(ai, stmt);
@@ -303,6 +369,7 @@ EXPORT_API ail_error_e ail_filter_count_appinfo(ail_filter_h filter, int *cnt)
        return AIL_ERROR_OK;
 }
 
+
 EXPORT_API ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter, ail_list_appinfo_cb cb, void *user_data)
 {
        char q[AIL_SQL_QUERY_MAX_LEN];
@@ -315,7 +382,7 @@ EXPORT_API ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter, ail_
 
        retv_if (NULL == cb, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RO) != AIL_ERROR_OK)
+       if (db_open(DB_OPEN_RO, GLOBAL_USER) != AIL_ERROR_OK)
                return AIL_ERROR_DB_FAILED;
 
        snprintf(q, sizeof(q), "SELECT %s FROM %s", SQL_FLD_APP_INFO_WITH_LOCALNAME, SQL_TBL_APP_INFO_WITH_LOCALNAME);
@@ -345,17 +412,21 @@ EXPORT_API ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter, ail_
                _D("No filter exists. All records are retreived");
 
 //     _D("Query = %s",q);
-
-       if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
+//is_admin
+       if (db_prepare_globalro(q, &stmt) != AIL_ERROR_OK) {
                _E("db_prepare fail for query = %s",q);
                return AIL_ERROR_DB_FAILED;
        }
-
+       /*if (db_prepare_globalro(q, &stmt) != AIL_ERROR_OK) {
+               _E("db_prepare fail for query = %s",q);
+               return AIL_ERROR_DB_FAILED;
+       }*/
        ai = appinfo_create();
 
        appinfo_set_stmt(ai, stmt);
-       while (db_step(stmt) == AIL_ERROR_OK) {
-
+       uint i = 0;
+       while (i = db_step(stmt) == AIL_ERROR_OK) {
+               _E("------------------------dbstep : %u\n", i);
                if(_appinfo_check_installed_storage(ai) != AIL_ERROR_OK)
                        continue;
 
@@ -366,7 +437,68 @@ EXPORT_API ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter, ail_
        appinfo_destroy(ai);
 
        db_finalize(stmt);
-
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_filter_list_usr_appinfo_foreach(ail_filter_h filter, ail_list_appinfo_cb cb, void *user_data, uid_t uid)
+{
+       char q[AIL_SQL_QUERY_MAX_LEN];
+       char *tmp_q;
+       char *w;
+       char *l;
+       ail_cb_ret_e r;
+       sqlite3_stmt *stmt;
+       ail_appinfo_h ai;
+
+       retv_if (NULL == cb, AIL_ERROR_INVALID_PARAMETER);
+
+       if (db_open(DB_OPEN_RO, uid) != AIL_ERROR_OK)
+               return AIL_ERROR_DB_FAILED;
+
+       snprintf(q, sizeof(q), "SELECT %s FROM %s", SQL_FLD_APP_INFO_WITH_LOCALNAME, SQL_TBL_APP_INFO_WITH_LOCALNAME);
+
+       tmp_q = strdup(q);
+       retv_if (NULL == tmp_q, AIL_ERROR_OUT_OF_MEMORY);
+       l = sql_get_locale();
+       if (NULL == l) {
+               _E("Failed to get locale string");
+               free(tmp_q);
+               return AIL_ERROR_FAIL;
+       }
+       snprintf(q, sizeof(q), tmp_q, l);
+       free(l);
+       free(tmp_q);
+
+       if (filter && filter->list) {
+               w = _get_where_clause(filter);
+               retv_if (NULL == w, AIL_ERROR_FAIL);
+               strncat(q, w, sizeof(q)-strlen(q)-1);
+               q[sizeof(q)-1] = '\0';
+               strncat(q, " order by app_info.package", sizeof(q)-strlen(q)-1);
+               q[sizeof(q)-1] = '\0';
+               free(w);
+       }
+       else
+               _D("No filter exists. All records are retreived");
+
+//is_admin
+       if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
+               _E("db_prepare fail for query = %s",q);
+               return AIL_ERROR_DB_FAILED;
+       }
+       ai = appinfo_create();
+       appinfo_set_stmt(ai, stmt);
+       uint i = 0;
+       while (i = db_step(stmt) == AIL_ERROR_OK) {
+               if(_appinfo_check_installed_storage(ai) != AIL_ERROR_OK)
+                       continue;
+
+               r = cb(ai, user_data);
+               if (AIL_CB_RET_CANCEL == r)
+                       break;
+       }
+       appinfo_destroy(ai);
+
+       db_finalize(stmt);
+       return AIL_ERROR_OK;
+}
index 711c8de..15e1078 100755 (executable)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <db-util.h>
+#include <tzplatform_config.h>
 #include <vconf.h>
 #include "ail.h"
 #include "ail_private.h"
@@ -37,7 +38,7 @@
 #define LANGUAGE_LENGTH 2
 #define DEFAULT_LOCALE         "No Locale"
 #define MAX_QUERY_LEN  4096
-#define PKG_SD_PATH "/opt/storage/sdcard/app2sd/"
+#define PKG_SD_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard/app2sd/")
 #define QUERY_GET_LOCALNAME "select name from localname where package='%s' and locale='%s'"
 
 struct ail_appinfo {
@@ -301,6 +302,13 @@ EXPORT_API ail_error_e ail_package_get_appinfo(const char *package, ail_appinfo_
        return ail_get_appinfo(package, ai);
 }
 
+EXPORT_API ail_error_e ail_package_get_usr_appinfo(const char *package, uid_t uid, ail_appinfo_h *ai)
+{
+       return ail_get_usr_appinfo(package, uid, ai);
+}
+
+
+
 EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai)
 {
        ail_error_e ret;
@@ -319,11 +327,14 @@ EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai)
        snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s",SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w);
 
        do {
-               ret = db_open(DB_OPEN_RO);
+               ret = db_open(DB_OPEN_RO, GLOBAL_USER);
                if (ret < 0) break;
-
+//is_admin
                ret = db_prepare(query, &stmt);
                if (ret < 0) break;
+//             ret = db_prepare(query, &stmt);
+//             if (ret < 0) break;
+
 
                ret = db_step(stmt);
                if (ret < 0) {
@@ -357,7 +368,64 @@ EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai)
        return ret;
 }
 
+EXPORT_API ail_error_e ail_get_usr_appinfo(const char *appid, uid_t uid, ail_appinfo_h *ai)
+{
+       ail_error_e ret;
+       char query[AIL_SQL_QUERY_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+       char w[AIL_SQL_QUERY_MAX_LEN];
+
+       retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!ai, AIL_ERROR_INVALID_PARAMETER);
+
+       *ai = appinfo_create();
+       retv_if(!*ai, AIL_ERROR_OUT_OF_MEMORY);
+
+       snprintf(w, sizeof(w), sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR), appid);
+
+       snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s",SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w);
+
+       do {
+               ret = db_open(DB_OPEN_RO, uid);
+               if (ret < 0) break;
+//is_admin
+               ret = db_prepare(query, &stmt);
+               if (ret < 0) break;
+//             ret = db_prepare(query, &stmt);
+//             if (ret < 0) break;
 
+
+               ret = db_step(stmt);
+               if (ret < 0) {
+                       db_finalize(stmt);
+                       break;
+               }
+
+               (*ai)->stmt = stmt;
+
+               ret = _appinfo_check_installed_storage(*ai);
+               if (ret < 0) {
+                       db_finalize((*ai)->stmt);
+                       break;
+               }
+
+               ret = __retrieve_all_column(*ai);
+               if (ret < 0) {
+                       db_finalize((*ai)->stmt);
+                       break;
+               }
+
+               ret = db_finalize((*ai)->stmt);
+               if (ret < 0) break;
+               (*ai)->stmt = NULL;
+
+               return AIL_ERROR_OK;
+       } while(0);
+
+       appinfo_destroy(*ai);
+
+       return ret;
+}
 EXPORT_API ail_error_e ail_appinfo_get_bool(const ail_appinfo_h ai, const char *property, bool *value)
 {
        ail_prop_bool_e prop;
@@ -384,8 +452,6 @@ EXPORT_API ail_error_e ail_appinfo_get_bool(const ail_appinfo_h ai, const char *
        return AIL_ERROR_OK;
 }
 
-
-
 EXPORT_API ail_error_e ail_appinfo_get_int(const ail_appinfo_h ai, const char *property, int *value)
 {
        ail_prop_int_e prop;
@@ -410,9 +476,9 @@ EXPORT_API ail_error_e ail_appinfo_get_int(const ail_appinfo_h ai, const char *p
        return AIL_ERROR_OK;
 }
 
-char *appinfo_get_localname(const char *package, char *locale)
+char *appinfo_get_localname(const char *package, char *locale, uid_t uid)
 {
-       db_open(DB_OPEN_RO);
+       db_open(DB_OPEN_RO, uid);
        sqlite3_stmt *stmt;
        char *str = NULL;
        char *localname;
@@ -421,7 +487,9 @@ char *appinfo_get_localname(const char *package, char *locale)
        snprintf(query, sizeof(query), QUERY_GET_LOCALNAME, package, locale);
 
 //     _D("Query = %s",query);
+//is_admin
        retv_if (db_prepare(query, &stmt) < 0, NULL);
+       //retv_if (db_prepare(query, &stmt) < 0, NULL);
 
        do {
                if (db_step(stmt) < 0)
@@ -442,7 +510,6 @@ char *appinfo_get_localname(const char *package, char *locale)
        return NULL;
 }
 
-
 EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *property, char **str)
 {
        int index;
@@ -483,7 +550,98 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p
                                }
 
                                locale_new = __get_app_locale_by_fallback(pkg, locale);
-                               localname = (char *)appinfo_get_localname(pkg,locale_new);
+                               localname = (char *)appinfo_get_localname(pkg, locale_new, GLOBAL_USER);
+                               free(locale);
+                               free(locale_new);
+                       } else {
+                               if (db_column_str(ai->stmt, SQL_LOCALNAME_IDX, &localname) < 0)
+                                       return AIL_ERROR_DB_FAILED;
+                       }
+               } else {
+                       pkg_type = ai->values[E_AIL_PROP_X_SLP_PACKAGETYPE_STR];
+                       pkg = ai->values[E_AIL_PROP_PACKAGE_STR];
+                       retv_if (NULL == pkg, AIL_ERROR_FAIL);
+
+                       locale = sql_get_locale();
+                       retv_if (NULL == locale, AIL_ERROR_FAIL);
+
+                       if(pkg_type && (strcasecmp(pkg_type, "tpk") ==0))
+                       {
+                               locale_new = __get_app_locale_by_fallback(pkg, locale);
+                               localname = (char *)appinfo_get_localname(pkg, locale_new, GLOBAL_USER);
+                               free(locale);
+                               free(locale_new);
+                       } else {
+                               localname = (char *)appinfo_get_localname(pkg, locale, GLOBAL_USER);
+                               free(locale);
+                       }
+               }
+
+               if (localname) {
+                       if (!ai->stmt) {
+                               if (ai->values) {
+                                       if (ai->values[prop])
+                                               free(ai->values[prop]);
+                                       ai->values[prop] = localname;
+                               }
+                       }
+                       *str = localname;
+                       return AIL_ERROR_OK;
+               }
+       }
+
+       if (ai->stmt) {
+               index = sql_get_app_info_idx(prop);
+               if (db_column_str(ai->stmt, index, &value) < 0){
+                       return AIL_ERROR_DB_FAILED;
+               }
+               *str = value;
+       } else
+               *str = ai->values[prop];
+
+       return AIL_ERROR_OK;
+}
+EXPORT_API ail_error_e ail_appinfo_get_usr_str(const ail_appinfo_h ai, const char *property, uid_t uid, char **str)
+{
+       int index;
+       char *value;
+       char *pkg;
+       char *pkg_type;
+       char *locale, *localname;
+       ail_prop_str_e prop;
+       char *locale_new;
+
+       retv_if(!ai, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!str, AIL_ERROR_INVALID_PARAMETER);
+
+       prop = _ail_convert_to_prop_str(property);
+
+       if (prop < E_AIL_PROP_STR_MIN || prop > E_AIL_PROP_STR_MAX)
+               return AIL_ERROR_INVALID_PARAMETER;
+
+       localname = NULL;
+
+       if (E_AIL_PROP_NAME_STR == prop) {
+               if (ai->stmt) {
+                       if (db_column_str(ai->stmt, E_AIL_PROP_X_SLP_PACKAGETYPE_STR, &pkg_type) < 0)
+                               return AIL_ERROR_DB_FAILED;
+                       if(pkg_type && (strcasecmp(pkg_type, "tpk") ==0))
+                       {
+                               locale = sql_get_locale();
+                               retv_if (NULL == locale, AIL_ERROR_FAIL);
+
+                               if (db_column_str(ai->stmt, E_AIL_PROP_PACKAGE_STR, &pkg) < 0){
+                                       free(locale);
+                                       return AIL_ERROR_DB_FAILED;
+                               }
+                               if (pkg == NULL){
+                                       free(locale);
+                                       return AIL_ERROR_DB_FAILED;
+                               }
+
+                               locale_new = __get_app_locale_by_fallback(pkg, locale);
+                               localname = (char *)appinfo_get_localname(pkg, locale_new, uid);
                                free(locale);
                                free(locale_new);
                        } else {
@@ -501,11 +659,11 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p
                        if(pkg_type && (strcasecmp(pkg_type, "tpk") ==0))
                        {
                                locale_new = __get_app_locale_by_fallback(pkg, locale);
-                               localname = (char *)appinfo_get_localname(pkg,locale_new);
+                               localname = (char *)appinfo_get_localname(pkg, locale_new, uid);
                                free(locale);
                                free(locale_new);
                        } else {
-                               localname = (char *)appinfo_get_localname(pkg,locale);
+                               localname = (char *)appinfo_get_localname(pkg, locale, uid);
                                free(locale);
                        }
                }
@@ -535,6 +693,7 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p
        return AIL_ERROR_OK;
 }
 
+
 EXPORT_API ail_error_e ail_close_appinfo_db(void)
 {
        return db_close();
index 37eb0ee..79a00a0 100755 (executable)
@@ -29,7 +29,7 @@
 #define SQL_TBL_APP_INFO "app_info"
 #define SQL_TBL_APP_INFO_WITH_LOCALNAME "app_info LEFT OUTER JOIN localname " \
                                        "ON app_info.package=localname.package " \
-                                       "and locale='%s'"
+                                       "and localname.locale='%s'"
 
 #define SQL_FLD_APP_INFO "app_info.PACKAGE," \
                        "app_info.EXEC," \
index 7196980..b6ecaf6 100644 (file)
@@ -150,7 +150,7 @@ static int _get_cmd(const char *arg)
        return r;
 }
 
-ail_cb_ret_e appinfo_list_func(const ail_appinfo_h appinfo, void *user_data)
+ail_cb_ret_e appinfo_list_func(const ail_appinfo_h appinfo,  void *user_data)
 {
        char *rs = NULL;
        int t=-1;
index 64cc9d8..e48121e 100644 (file)
@@ -42,7 +42,7 @@
 #endif
 #define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
 
-static int initdb_count_app(void)
+static int initdb_count_app(uid_t uid)
 {
        ail_filter_h filter;
        ail_error_e ret;
@@ -58,8 +58,9 @@ static int initdb_count_app(void)
                ail_filter_destroy(filter);
                return -1;
        }
-
-       ret = ail_filter_count_appinfo(filter, &total);
+//__isadmin
+       ret = ail_filter_count_usr_appinfo(filter,  &total, uid);
+       //ret = ail_filter_count_appinfo(filter,  &total);
        if (ret != AIL_ERROR_OK) {
                ail_filter_destroy(filter);
                return -1;
@@ -246,7 +247,7 @@ int main(int argc, char *argv[])
        ret = setenv("AIL_INITDB", "1", 1);
        _D("AIL_INITDB : %d", ret);
 
-       ret = initdb_count_app();
+       ret = initdb_count_app(getuid());
        if (ret > 0) {
                _D("Some Apps in the App Info DB.");
        }
index 8a2a717..a73aadd 100644 (file)
@@ -102,7 +102,7 @@ static int _get_property(const char *property)
 
 
 
-static ail_error_e _get_appinfo(const char *package, const char *property)
+static ail_error_e _get_appinfo(const char *package, const char *property, uid_t uid)
 {
        ail_appinfo_h handle;
        ail_error_e ret;
@@ -112,7 +112,7 @@ static ail_error_e _get_appinfo(const char *package, const char *property)
        struct element e;
        struct element *p;
        int t;
-
+    //__isadmin)
        ret = ail_package_get_appinfo(package, &handle);
        if (ret != AIL_ERROR_OK) {
                return AIL_ERROR_FAIL;
@@ -163,7 +163,7 @@ int main(int argc, char** argv)
 
        if (4 == argc) {
                if (!strncmp(argv[1], "get", 3)) {
-                       ret = _get_appinfo(argv[2], argv[3]);
+                       ret = _get_appinfo(argv[2], argv[3], getuid());
                }
        }
        else {
index d8b7373..2743b34 100755 (executable)
@@ -59,7 +59,6 @@ static int initdb_count_app(void)
                ail_filter_destroy(filter);
                return -1;
        }
-
        ret = ail_filter_count_appinfo(filter, &total);
        if (ret != AIL_ERROR_OK) {
                ail_filter_destroy(filter);