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
*/
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;
/**
*/
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
#include <gio/gio.h>
#include <pkgmgr-info.h>
+#include <sqlite3.h>
+#include <tzplatform_config.h>
#include "app2sd_client_interface.h"
#include "app2sd_utils.h"
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.*/
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;
}
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;
+}