From 97e845e72079be00a5674e3569cd8dcd356dc027 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 18 Jul 2016 20:15:54 +0900 Subject: [PATCH] get external path using storage api. Change-Id: I57a4060fc6c88806e76a3af576ccc34d86c160e3 Signed-off-by: jongmyeongko --- CMakeLists.txt | 2 +- include/aul.h | 1 + packaging/aul.spec | 1 + src/aul_path.c | 76 ++++++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 65 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0a1a7d..6eb43f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ ENDIF (with_x11) # Set required packages INCLUDE(FindPkgConfig) -SET(AUL-1_LIB_PKG_CHECK_MODULES dlog bundle xdgmime libtzplatform-config pkgmgr-info capi-system-info vconf sqlite3 iniparser gio-2.0 glib-2.0 libxml-2.0 ttrace) +SET(AUL-1_LIB_PKG_CHECK_MODULES dlog bundle xdgmime libtzplatform-config pkgmgr-info capi-system-info vconf sqlite3 iniparser gio-2.0 glib-2.0 libxml-2.0 ttrace storage) IF (with_wayland) pkg_check_modules(libpkgs REQUIRED ${AUL-1_LIB_PKG_CHECK_MODULES} wayland-client tizen-extension-client ecore-wayland wayland-tbm-client tizen-remote-surface-client ecore) ENDIF (with_wayland) diff --git a/include/aul.h b/include/aul.h index a9d0a15..477b8e4 100644 --- a/include/aul.h +++ b/include/aul.h @@ -31,6 +31,7 @@ extern "C" { * @brief Return values in AUL. */ typedef enum _aul_return_val { + AUL_R_ENOENT = -15, /**< App directory entry error */ AUL_R_EREJECTED = -14, /**< App disable for mode */ AUL_R_ENOAPP = -13, /**< Failed to find app ID or pkg ID */ AUL_R_EHIDDENFORGUEST = -11, /**< App hidden for guest mode */ diff --git a/packaging/aul.spec b/packaging/aul.spec index aeef17e..1bfa965 100644 --- a/packaging/aul.spec +++ b/packaging/aul.spec @@ -30,6 +30,7 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(storage) BuildRequires: pkgconfig(ttrace) %if %{with wayland} BuildRequires: pkgconfig(ecore) diff --git a/src/aul_path.c b/src/aul_path.c index 9f629a8..cf23ab1 100644 --- a/src/aul_path.c +++ b/src/aul_path.c @@ -26,6 +26,7 @@ #include #include +#include #include "aul_api.h" #include "aul_util.h" @@ -33,13 +34,6 @@ #define ROOT_UID 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define _EXTERNAL_APP_SPECIFIC_PATH(uid) ({ \ - tzplatform_set_user(uid); \ - const char *path = tzplatform_mkpath3(TZ_SYS_MEDIA, \ - "SDCardA1/apps", tzplatform_getenv(TZ_USER_NAME)); \ - tzplatform_reset_user(); \ - path; }) -#define _APP_SPECIFIC_PATH tzplatform_getenv(TZ_USER_APP) static const char _DATA_DIR[] = "data/"; static const char _CACHE_DIR[] = "cache/"; @@ -49,6 +43,8 @@ static const char _SHARED_DATA_DIR[] = "shared/data/"; static const char _SHARED_TRUSTED_DIR[] = "shared/trusted/"; static const char _SHARED_RESOURCE_DIR[] = "shared/res/"; +static char ext_specific_path[PATH_MAX]; + static const char * __get_specific_path(const char *pkgid, uid_t uid) { const char * path; @@ -97,25 +93,62 @@ static int __get_pkgid(char *pkgid, int len, const char *appid, uid_t uid) return AUL_R_OK; } +/* return value should be freed after use. */ +static char *__get_sdcard_path(void) +{ + char *sdpath = NULL; + char *result_path = NULL; + int storage_id = 0; + int ret; + + ret = storage_get_primary_sdcard(&storage_id, &sdpath); + if (ret != STORAGE_ERROR_NONE) { + _E("failed to get primary sdcard (%d)", ret); + if (sdpath) + free(sdpath); + return NULL; + } + + if (sdpath) + result_path = sdpath; + else + result_path = NULL; + + return result_path; +} + static int __get_external_path(char **path, const char *appid, const char *dir_name, uid_t uid) { char buf[PATH_MAX]; char pkgid[NAME_MAX]; + char *ext_path; int ret; ret = __get_pkgid(pkgid, sizeof(pkgid), appid, uid); if (ret != AUL_R_OK) return ret; - snprintf(buf, sizeof(buf), "%s/%s/%s", - _EXTERNAL_APP_SPECIFIC_PATH(uid), - pkgid, dir_name ? dir_name : ""); - assert(path); - *path = strdup(buf); - return AUL_R_OK; + ext_path = __get_sdcard_path(); + if (ext_path) { + tzplatform_set_user(uid); + snprintf(buf, sizeof(buf), "%s/apps/%s/%s/%s", + ext_path, tzplatform_getenv(TZ_USER_NAME), + pkgid, dir_name ? dir_name : ""); + tzplatform_reset_user(); + free(ext_path); + ext_path = NULL; + + *path = strdup(buf); + ret = AUL_R_OK; + } else { + *path = NULL; + ret = AUL_R_ENOENT; + } + + return ret; } static int __get_path(char **path, const char *appid, const char *dir_name, @@ -315,7 +348,22 @@ API const char *aul_get_app_specific_path(void) API const char *aul_get_app_external_specific_path(void) { - return _EXTERNAL_APP_SPECIFIC_PATH(getuid()); + char *ext_path; + char *result_path = NULL; + + ext_path = __get_sdcard_path(); + if (ext_path) { + tzplatform_set_user(getuid()); + snprintf(ext_specific_path, sizeof(ext_specific_path), + "%s/apps/%s", ext_path, + tzplatform_getenv(TZ_USER_NAME)); + tzplatform_reset_user(); + result_path = ext_specific_path; + free(ext_path); + ext_path = NULL; + } + + return result_path; } API int aul_get_app_shared_data_path_by_appid(const char *appid, char **path) -- 2.7.4