Multi user features :
[platform/core/appfw/ail.git] / src / ail_package.c
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();