Add new feature to change app's icon 33/140333/3
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 24 Jul 2017 13:11:42 +0000 (22:11 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 8 Aug 2017 11:25:36 +0000 (11:25 +0000)
Change-Id: Iad572be3e54a3fa758b7653014ba4a400efa0a8b
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
parser/include/pkgmgr_parser_db.h
parser/src/pkgmgr_parser_db.c

index 298bd79..0e91f62 100644 (file)
@@ -332,6 +332,33 @@ int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *lab
 int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label);
 
 /**
+ * @fn int pkgmgr_parser_update_app_icon_info_in_db(const char *appid, const char *icon_path)
+ * @brief      This API updates icon info of application
+ *
+ * @par                This API is only for internal usage
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  appid           application ID to change label
+ * @param[in]  icon_path       icon path to change
+ * @return     0 if success, error code(<0) if fail
+ */
+int pkgmgr_parser_update_app_icon_info_in_db(const char *appid, const char *icon_path);
+
+/**
+ * @fn int pkgmgr_parser_update_app_icon_info_in_usr_db(const char *appid, uid_t uid, const char *icon_path)
+ * @brief      This API updates icon info of application for user specified by uid
+ *
+ * @par                This API is only for internal usage
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  appid           application ID to change label
+ * @param[in]  uid             user ID
+ * @param[in]  icon_path       icon path to change
+ * @return     0 if success, error code(<0) if fail
+ */
+int pkgmgr_parser_update_app_icon_info_in_usr_db(const char *appid, uid_t uid, const char *icon_path);
+
+/**
  * @fn int pkgmgr_parser_register_pkg_update_info_in_usr_db(pkgmgrinfo_updateinfo_h handle, uid_t uid)
  * @brief      This API registers update informations of given packages for user specified by uid
  *
index 0163fae..7b9d10e 100644 (file)
@@ -2473,6 +2473,72 @@ API int pkgmgr_parser_update_app_label_info_in_db(const char *appid,
                        label);
 }
 
+static int __set_app_icon(sqlite3 *db, const char *appid, const char *icon_path)
+{
+       static const char query[] =
+               "UPDATE package_app_localized_info SET app_icon=? "
+               "WHERE app_id=? AND app_icon IS NOT NULL";
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx = 1;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       __BIND_TEXT(db, stmt, idx++, icon_path);
+       __BIND_TEXT(db, stmt, idx++, appid);
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_DONE) {
+               _LOGE("step failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return -1;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return 0;
+}
+
+API int pkgmgr_parser_update_app_icon_info_in_usr_db(const char *appid,
+               uid_t uid, const char *icon_path)
+{
+       int ret;
+       const char *dbpath;
+       sqlite3 *db;
+
+       if (appid == NULL) {
+               _LOGE("invalid parameter");
+               return PM_PARSER_R_EINVAL;
+       }
+
+       dbpath = __get_parser_db_path(uid);
+
+       ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
+       if (ret != SQLITE_OK) {
+               _LOGE("open db failed: %d", ret);
+               return PM_PARSER_R_ERROR;
+       }
+
+       __BEGIN_TRANSACTION(db);
+       __DO_TRANSACTION(db, __set_app_icon(db, appid, icon_path));
+       __END_TRANSACTION(db);
+
+       sqlite3_close_v2(db);
+
+       return PM_PARSER_R_OK;
+}
+
+API int pkgmgr_parser_update_app_icon_info_in_db(const char *appid,
+               const char *icon_path)
+{
+       return pkgmgr_parser_update_app_icon_info_in_usr_db(appid, __getuid(),
+                       icon_path);
+}
+
 static int __set_tep_path(sqlite3 *db, const char *pkgid, const char *tep_path)
 {
        static const char query[] =