From: Hwankyu Jhun Date: Mon, 3 Oct 2016 23:43:20 +0000 (+0900) Subject: Add new APIs to activate/deactivate alias info X-Git-Tag: accepted/tizen/3.0/ivi/20161011.053549^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F90683%2F2;p=platform%2Fcore%2Fappfw%2Faul-1.git Add new APIs to activate/deactivate alias info Change-Id: I6869bcc74963fd3f855062c93fbdada8ade76382 Signed-off-by: Hwankyu Jhun --- diff --git a/data/appsvc_db.sql b/data/appsvc_db.sql index e94bffc..4f8c06e 100755 --- a/data/appsvc_db.sql +++ b/data/appsvc_db.sql @@ -11,6 +11,7 @@ CREATE TABLE IF NOT EXISTS appsvc ( CREATE TABLE IF NOT EXISTS alias_info ( alias_appid TEXT NOT NULL, appid TEXT NOT NULL, + enable TEXT NOT NULL DEFAULT 'true', PRIMARY KEY (alias_appid) ); diff --git a/include/aul.h b/include/aul.h index 5b3d09e..9a0e362 100644 --- a/include/aul.h +++ b/include/aul.h @@ -2945,6 +2945,34 @@ int aul_set_alias_appid(const char *alias_appid, const char *appid); */ int aul_unset_alias_appid(const char *alias_appid); +/** + * @par Description: + * This API activates the alias information based on the given appid. + * + * @privlevel platform + * @privilege %http://tizen.org/privilege/systemsettings.admin + * @param[in] appid an application ID + * @return 0 if success, negative value(<0) if fail + * + * @remark + * This API is only available to User Session. + */ +int aul_enable_alias_info(const char *appid); + +/** + * @par Description: + * This API deactivates the alias information based on the given appid. + * + * @privlebel platform + * @privilege %http://tizen.org/privilege/systemsettings.admin + * @param[in] appid an application ID + * @return 0 if success, negative value(<0) if fail + * + * @remark + * This API is only available to User Session. + */ +int aul_disable_alias_info(const char *appid); + /* * This API is only for Appfw internally. */ diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 9fea3bd..108c729 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -113,6 +113,8 @@ enum app_cmd { APP_UNSET_ALIAS_APPID, APP_LISTEN_STATUS, APP_STATUS_NOTIFICATION, + APP_ENABLE_ALIAS_INFO, + APP_DISABLE_ALIAS_INFO, APP_CMD_MAX }; diff --git a/include/aul_svc.h b/include/aul_svc.h index 6e2e133..d92b76f 100755 --- a/include/aul_svc.h +++ b/include/aul_svc.h @@ -1170,6 +1170,26 @@ int aul_svc_foreach_alias_info_for_uid(void (*callback)(const char *alias_appid, const char *appid, void *data), uid_t uid, void *user_data); +/** + * @par Description: + * This API activates the alias information based on the given appid. + * + * @param[in] appid an application ID + * @return 0 if success, negative value(<0) if fail + */ +int aul_svc_enable_alias_info(const char *appid); +int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid); + +/** + * @par Description: + * This API deactivates the alias information based on the given appid. + * + * @param[in] appid an application ID + * @return 0 if success, negative value(<0) if fail + */ +int aul_svc_disable_alias_info(const char *appid); +int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid); + #ifdef __cplusplus } #endif diff --git a/include/aul_svc_db.h b/include/aul_svc_db.h index 824a526..e7c5158 100755 --- a/include/aul_svc_db.h +++ b/include/aul_svc_db.h @@ -58,6 +58,8 @@ int _svc_db_get_appid_from_alias_info(const char *alias_appid, int _svc_db_foreach_alias_info(void (*callback)(const char *alias_appid, const char *appid, void *data), uid_t uid, void *user_data); +int _svc_db_enable_alias_info(const char *appid, uid_t uid); +int _svc_db_disable_alias_info(const char *appid, uid_t uid); #ifdef __cplusplus } diff --git a/src/pkginfo.c b/src/pkginfo.c index 48c203d..be0df27 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -526,3 +526,54 @@ API int aul_unset_alias_appid(const char *alias_appid) return AUL_R_OK; } +API int aul_enable_alias_info(const char *appid) +{ + int ret; + bundle *b; + + if (appid == NULL) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + b = bundle_create(); + if (b == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + bundle_add(b, AUL_K_APPID, appid); + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), + APP_ENABLE_ALIAS_INFO, b, AUL_SOCK_NONE); + bundle_free(b); + if (ret != AUL_R_OK) + return aul_error_convert(ret); + + return AUL_R_OK; +} + +API int aul_disable_alias_info(const char *appid) +{ + int ret; + bundle *b; + + if (appid == NULL) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + b = bundle_create(); + if (b == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + bundle_add(b, AUL_K_APPID, appid); + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), + APP_DISABLE_ALIAS_INFO, b, AUL_SOCK_NONE); + bundle_free(b); + if (ret != AUL_R_OK) + return aul_error_convert(ret); + + return AUL_R_OK; +} diff --git a/src/service.c b/src/service.c index c353d91..a8818ec 100755 --- a/src/service.c +++ b/src/service.c @@ -1500,3 +1500,46 @@ API int aul_svc_foreach_alias_info_for_uid(void (*callback)( return AUL_SVC_RET_OK; } +API int aul_svc_enable_alias_info(const char *appid) +{ + return aul_svc_enable_alias_info_for_uid(appid, getuid()); +} + +API int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid) +{ + int ret; + + ret = _svc_db_check_perm(uid, false); + if (ret < 0) { + _E("Permission error: %d", ret); + return AUL_SVC_RET_EILLACC; + } + + ret = _svc_db_enable_alias_info(appid, uid); + if (ret < 0) + return AUL_SVC_RET_ERROR; + + return AUL_SVC_RET_OK; +} + +API int aul_svc_disable_alias_info(const char *appid) +{ + return aul_svc_disable_alias_info_for_uid(appid, getuid()); +} + +API int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid) +{ + int ret; + + ret = _svc_db_check_perm(uid, false); + if (ret < 0) { + _E("Permission error: %d", ret); + return AUL_SVC_RET_EILLACC; + } + + ret = _svc_db_disable_alias_info(appid, uid); + if (ret < 0) + return AUL_SVC_RET_ERROR; + + return AUL_SVC_RET_OK; +} diff --git a/src/service_db.c b/src/service_db.c index ce6f1a8..bd3924e 100755 --- a/src/service_db.c +++ b/src/service_db.c @@ -882,7 +882,8 @@ int _svc_db_get_appid_from_alias_info(const char *alias_appid, int ret; sqlite3_stmt *stmt = NULL; const char *query = - "SELECT appid FROM alias_info WHERE alias_appid = ?;"; + "SELECT appid FROM alias_info WHERE " \ + "alias_appid = ? AND enable = 'true';"; const char *real_appid; int result = 0; @@ -1020,3 +1021,69 @@ int _svc_db_foreach_alias_info(void (*callback)(const char *alias_appid, return 0; } +static int __enable_disable_alias_info(const char *appid, uid_t uid, + bool enable) +{ + int ret; + sqlite3_stmt *stmt = NULL; + const char *query = + "UPDATE alias_info set enable = ? WHERE appid = ?;"; + int result = 0; + + if (appid == NULL) { + _E("Invalid parameter"); + return -1; + } + + if (__init(uid, false) < 0) + return -1; + + ret = sqlite3_prepare_v2(svc_db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + _E("sqlite3_prepare_v2() error: %d(%s)", + ret, sqlite3_errmsg(svc_db)); + __fini(); + return ret; + } + + if (enable) + ret = sqlite3_bind_text(stmt, 1, "true", -1, SQLITE_TRANSIENT); + else + ret = sqlite3_bind_text(stmt, 1, "false", -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + _E("sqlite3_bind_text() error: %d(%s)", + ret, sqlite3_errmsg(svc_db)); + result = -1; + goto end; + } + + ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + _E("sqlite3_bind_text() error: %d(%s)", + ret, sqlite3_errmsg(svc_db)); + result = -1; + goto end; + } + + ret = sqlite3_step(stmt); + if (ret != SQLITE_DONE) { + _E("sqlite3_step() error: %d(%s)", + ret, sqlite3_errmsg(svc_db)); + result = -1; + } +end: + sqlite3_finalize(stmt); + __fini(); + + return result; +} + +int _svc_db_enable_alias_info(const char *appid, uid_t uid) +{ + return __enable_disable_alias_info(appid, uid, true); +} + +int _svc_db_disable_alias_info(const char *appid, uid_t uid) +{ + return __enable_disable_alias_info(appid, uid, false); +}