Add new APIs to activate/deactivate alias info 83/90683/2 accepted/tizen/3.0/ivi/20161011.053549 accepted/tizen/3.0/mobile/20161015.032346 accepted/tizen/3.0/tv/20161016.003403 accepted/tizen/3.0/wearable/20161015.080408 accepted/tizen/common/20161004.081054 accepted/tizen/ivi/20161004.232552 accepted/tizen/mobile/20161004.232507 accepted/tizen/tv/20161004.232522 accepted/tizen/wearable/20161004.232537 submit/tizen/20161004.045053 submit/tizen_3.0_ivi/20161010.000000 submit/tizen_3.0_ivi/20161010.000010 submit/tizen_3.0_mobile/20161015.000000 submit/tizen_3.0_tv/20161015.000000 submit/tizen_3.0_wearable/20161015.000000
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 3 Oct 2016 23:43:20 +0000 (08:43 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 4 Oct 2016 00:21:02 +0000 (09:21 +0900)
Change-Id: I6869bcc74963fd3f855062c93fbdada8ade76382
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
data/appsvc_db.sql
include/aul.h
include/aul_cmd.h
include/aul_svc.h
include/aul_svc_db.h
src/pkginfo.c
src/service.c
src/service_db.c

index e94bffc..4f8c06e 100755 (executable)
@@ -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)
 );
 
index 5b3d09e..9a0e362 100644 (file)
@@ -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.
  */
index 9fea3bd..108c729 100644 (file)
@@ -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
 };
 
index 6e2e133..d92b76f 100755 (executable)
@@ -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
index 824a526..e7c5158 100755 (executable)
@@ -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
 }
index 48c203d..be0df27 100644 (file)
@@ -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;
+}
index c353d91..a8818ec 100755 (executable)
@@ -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;
+}
index ce6f1a8..bd3924e 100755 (executable)
@@ -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);
+}