Add a new API for getting external image path 67/145167/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Fri, 1 Sep 2017 10:04:27 +0000 (19:04 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 1 Sep 2017 10:27:50 +0000 (19:27 +0900)
Change-Id: I20d1a32c3c9879885ed90e1e35221c61aaf394d0
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
inc/app2ext_interface.h
plugin/app2sd/lib/app2sd_client_interface.c
src/app2ext_interface.c

index a12925a..35a6eb1 100644 (file)
@@ -372,6 +372,18 @@ typedef char *(*app2ext_client_usr_getname_image)(const char *pkgid,
                uid_t uid);
 
 /**
+ * @brief : This function type is for a function that is implemented by plugin
+ * and called to get the external image path.
+ *
+ * @param[in]   pkgid           application package name
+ * @param[in]   uid           target user id
+ * @return      the path of external image
+ * @remark     the path should be freed after the use.
+ */
+typedef char *(*app2ext_client_usr_get_image_path)(const char *pkgid,
+               uid_t uid);
+
+/**
  * This structure defines the app2ext interfaces.
  * Plugins have to implement these functions
  */
@@ -406,6 +418,7 @@ typedef struct app2ext_interface_t {
        app2ext_client_usr_getname_image        client_usr_getname_image;
        app2ext_client_usr_pre_migrate_legacy   client_usr_pre_migrate_legacy;
        app2ext_client_usr_post_migrate_legacy  client_usr_post_migrate_legacy;
+       app2ext_client_usr_get_image_path       client_usr_get_image_path;
 } app2ext_interface;
 
 /**
@@ -499,6 +512,15 @@ API int app2ext_migrate_legacy_all(void);
  */
 API char *app2ext_usr_getname_image(const char *pkgid, uid_t uid);
 
+/**
+ * @brief : This API get the external image path
+ * @param[in]   pkgid           application package name
+ * @param[in]   uid           target user id
+ * @return      the path of external image
+ * @remark     the path should be freed after the use.
+ */
+API char *app2ext_usr_get_image_path(const char *pkgid, uid_t uid);
+
 #ifdef __cplusplus
 }
 #endif
index a104255..4d5efad 100644 (file)
@@ -28,6 +28,8 @@
 #include <gio/gio.h>
 
 #include <pkgmgr-info.h>
+#include <sqlite3.h>
+#include <tzplatform_config.h>
 
 #include "app2sd_client_interface.h"
 #include "app2sd_utils.h"
@@ -650,6 +652,59 @@ char *app2sd_client_usr_getname_image(const char *pkgid, uid_t uid)
        return _app2sd_get_encoded_name(pkgid, uid);
 }
 
+char *app2sd_client_usr_get_image_path(const char *pkgid, uid_t uid)
+{
+       static const char query[] =
+               "SELECT filename FROM app2sd_info WHERE pkgid=? AND uid=?";
+       int ret;
+       sqlite3 *db;
+       sqlite3_stmt *stmt;
+       const char *dbpath;
+       char *image_path = NULL;
+
+       dbpath = tzplatform_mkpath(TZ_SYS_DB, ".app2sd.db");
+       if (dbpath == NULL)
+               return NULL;
+
+       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("open failed: %s", sqlite3_errmsg(db));
+               return NULL;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               sqlite3_close_v2(db);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               return NULL;
+       }
+
+       ret = sqlite3_bind_int(stmt, 2, uid);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               return NULL;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_ROW)
+               image_path = strdup((char *)sqlite3_column_text(stmt, 0));
+
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+
+       return image_path;
+}
+
 void app2ext_on_load(app2ext_interface *interface)
 {
        /* Plug-in Binding.*/
@@ -682,4 +737,5 @@ void app2ext_on_load(app2ext_interface *interface)
        interface->client_usr_getname_image = app2sd_client_usr_getname_image;
        interface->client_usr_pre_migrate_legacy = app2sd_client_usr_pre_migrate_legacy;
        interface->client_usr_post_migrate_legacy = app2sd_client_usr_post_migrate_legacy;
+       interface->client_usr_get_image_path = app2sd_client_usr_get_image_path;
 }
index 07b70c2..5c893e9 100644 (file)
@@ -282,3 +282,26 @@ char *app2ext_usr_getname_image(const char *pkgid, uid_t uid)
 
        return image_name;
 }
+
+char *app2ext_usr_get_image_path(const char *pkgid, uid_t uid)
+{
+       app2ext_handle *handle;
+       char *image_path;
+
+       /* validate the function parameter received */
+       if (pkgid == NULL) {
+               _E("invalid func parameters");
+               return NULL;
+       }
+
+       handle = app2ext_init(APP2EXT_SD_CARD);
+       if (handle == NULL) {
+               _E("app2ext init failed");
+               return NULL;
+       }
+
+       image_path = handle->interface.client_usr_get_image_path(pkgid, uid);
+       app2ext_deinit(handle);
+
+       return image_path;
+}