Add widget enable/disable api 35/223135/17
authorSukHyung, Kang <shine.kang@samsung.com>
Thu, 23 Jan 2020 07:14:37 +0000 (16:14 +0900)
committerSukHyung, Kang <shine.kang@samsung.com>
Mon, 2 Mar 2020 09:54:42 +0000 (18:54 +0900)
Change-Id: Ia9998779f12e8b6b09881c0f65a5d58eff983e56
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
include/widget_service_internal.h
packaging/libwidget_service.spec
src/widget_service.c

index 891995c..ce9f549 100644 (file)
@@ -767,6 +767,14 @@ extern int widget_service_get_auto_align(const char *widget_id);
 extern int widget_service_get_hw_accelerated(const char *widget_id);
 extern int widget_service_set_sdk_util(bundle *data);
 extern int widget_service_check_db_integrity(bool is_init);
+
+typedef void (*widget_disable_event_cb)(const char *widget_id, bool is_disable, void *user_data);
+
+extern int widget_service_set_widget_disable(const char *widget_id, bool is_disable);
+extern int widget_service_get_widget_disable(const char *widget_id, bool *is_disable);
+extern int widget_service_set_disable_event_cb(widget_disable_event_cb cb, void *user_data);
+extern int widget_service_unset_disable_event_cb();
+
 #ifdef __cplusplus
 }
 #endif
index d51459a..43e6a17 100644 (file)
@@ -83,10 +83,10 @@ mkdir -p %{buildroot}%{_sysconfdir}/skel/.applications/dbspace
 cat /dev/null > .widget.db
 cat /dev/null > .widget.db-journal
 
-install -m 0644 .widget.db %{buildroot}%{TZ_SYS_DB}
-install -m 0644 .widget.db-journal %{buildroot}%{TZ_SYS_DB}
-install -m 0644 .widget.db %{buildroot}%{_sysconfdir}/skel/.applications/dbspace
-install -m 0644 .widget.db-journal %{buildroot}%{_sysconfdir}/skel/.applications/dbspace
+install -m 0666 .widget.db %{buildroot}%{TZ_SYS_DB}
+install -m 0666 .widget.db-journal %{buildroot}%{TZ_SYS_DB}
+install -m 0666 .widget.db %{buildroot}%{_sysconfdir}/skel/.applications/dbspace
+install -m 0666 .widget.db-journal %{buildroot}%{_sysconfdir}/skel/.applications/dbspace
 
 %if 0%{?gcov:1}
 mkdir -p %{buildroot}%{_datadir}/gcov/obj
index c0cd85e..813d9e0 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdbool.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <iniparser.h>
 
 #include <glib.h>
@@ -40,6 +41,7 @@
 #include <pwd.h>
 
 #include <aul_widget.h>
+#include <aul_app_com.h>
 #include <system_info.h>
 
 #include "widget_errno.h"
@@ -71,6 +73,7 @@ CREATE TABLE widget_class ( \
        nodisplay     INTEGER DEFAULT 0, \
        max_instance  INTEGER DEFAULT 0, \
        prime         INTEGER DEFAULT 0, \
+       is_disable    INTEGER DEFAULT 0, \
        PRIMARY KEY(classid) \
 ); \
 CREATE TABLE support_size ( \
@@ -105,6 +108,8 @@ do { \
 } while (0)
 
 #define WIDGET_TBL_COUNT 4
+#define DISABLE_ENDPOINT "widget.disable"
+
 static char *_widget_table_list[WIDGET_TBL_COUNT] = {
        "icon",
        "label",
@@ -124,6 +129,10 @@ static const char *_iso3lang;
 static char _country[ULOC_COUNTRY_CAPACITY];
 static char *_syslang;
 static bool _is_corrupted = false;
+static aul_app_com_connection_h _conn;
+static widget_disable_event_cb _disable_event_cb;
+static void *_disable_user_data;
+static bool _is_disabled = false;
 
 static inline bool _is_widget_feature_enabled(void)
 {
@@ -256,6 +265,7 @@ static int __change_own(uid_t uid, const char *path)
        uid_t new_uid;
        char buf[MAX_BUF_SIZE];
        char journal_path[PATH_MAX];
+       mode_t mode;
 
        ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
        if (result == NULL) {
@@ -277,6 +287,13 @@ static int __change_own(uid_t uid, const char *path)
                return WIDGET_ERROR_FAULT;
        }
 
+       mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+       ret = chmod(path, mode);
+       if (ret == -1) {
+               printf("chmod failed : %s", path);
+               return WIDGET_ERROR_FAULT;;
+       }
+
        snprintf(journal_path, sizeof(journal_path), "%s-journal", path);
        ret = chown(journal_path, new_uid, pwd.pw_gid);
        if (ret == -1) {
@@ -284,6 +301,12 @@ static int __change_own(uid_t uid, const char *path)
                return WIDGET_ERROR_FAULT;
        }
 
+       ret = chmod(journal_path, mode);
+       if (ret == -1) {
+               printf("chmod failed : %s", path);
+               return WIDGET_ERROR_FAULT;;
+       }
+
        return WIDGET_ERROR_NONE;
 }
 
@@ -1083,9 +1106,9 @@ static void __free_widget_list(gpointer data)
 static int _get_widget_list(const char *pkgid, uid_t uid, GList **list)
 {
        static const char query[] =
-               "SELECT classid, pkgid, prime FROM widget_class";
-       static const char query_where[] =
-               " WHERE pkgid = ?";
+               "SELECT classid, pkgid, prime FROM widget_class WHERE is_disable = 0";
+       static const char query_pkgid[] =
+               " AND pkgid = ?";
        char query_buf[MAX_BUF_SIZE];
        int ret;
        int len;
@@ -1095,7 +1118,7 @@ static int _get_widget_list(const char *pkgid, uid_t uid, GList **list)
 
        len = snprintf(query_buf, sizeof(query_buf), "%s", query);
        if (pkgid != NULL)
-               strncat(query_buf, query_where, MAX_BUF_SIZE - len - 1);
+               strncat(query_buf, query_pkgid, MAX_BUF_SIZE - len - 1);
 
        db = _open_db(uid);
        if (db == NULL)
@@ -2751,3 +2774,162 @@ EAPI int widget_service_get_instance_count(const char *widget_id, const char *cl
 
        return ret;
 }
+
+EAPI int widget_service_set_widget_disable(const char *widget_id,
+               bool is_disable)
+{
+       int ret;
+
+       if (!_is_widget_feature_enabled()) {
+               _E("Not supported");
+               return WIDGET_ERROR_NOT_SUPPORTED;
+       }
+
+       if (widget_id == NULL) {
+               _E("Invalid parameter");
+               return WIDGET_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_is_disabled == is_disable) {
+               _E("already udpated");
+               return WIDGET_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = aul_widget_service_set_disable(widget_id, is_disable);
+       if (ret)
+               _E("set disable error");
+
+       _is_disabled = is_disable;
+
+       return ret;
+}
+
+static int _get_disable(const char *widget_id, bool *is_disable, uid_t uid)
+{
+       int ret;
+       sqlite3 *db;
+       sqlite3_stmt *stmt;
+       char *query;
+       int disable;
+
+       query = sqlite3_mprintf("SELECT is_disable FROM widget_class"
+            " WHERE classid = %Q", widget_id);
+
+       db = _open_db(uid);
+       if (db == NULL) {
+               _E("_get_disable db null");
+               sqlite3_free(query);
+               return WIDGET_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _E("prepare error: %s", sqlite3_errmsg(db));
+               sqlite3_free(query);
+               sqlite3_close_v2(db);
+               return WIDGET_ERROR_FAULT;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               sqlite3_free(query);
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               if (ret == SQLITE_DONE) {
+                       return WIDGET_ERROR_NOT_EXIST;
+               } else {
+                       _E("step error: %s, %d", sqlite3_errmsg(db), ret);
+                       return WIDGET_ERROR_FAULT;
+               }
+       }
+       _get_column_int(stmt, 0, &disable);
+
+       *is_disable = (bool)disable;
+
+       sqlite3_free(query);
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+
+       return WIDGET_ERROR_NONE;
+}
+
+EAPI int widget_service_get_widget_disable(const char *widget_id,
+               bool *is_disable)
+{
+       int ret;
+
+       if (!_is_widget_feature_enabled()) {
+               _E("Not supported");
+               return WIDGET_ERROR_NOT_SUPPORTED;
+       }
+
+       if (widget_id == NULL) {
+               _E("Invalid parameter");
+               return WIDGET_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _get_disable(widget_id, is_disable, getuid());
+       if (ret != WIDGET_ERROR_NONE && !_is_global(getuid())) {
+               ret = _get_disable(widget_id, is_disable, GLOBALAPP_USER);
+               if (ret)
+                       _E("failed to get disable");
+       }
+
+       return ret;
+}
+
+static void __notify_disable(const char *widget_id, bool is_disable)
+{
+       _disable_event_cb(widget_id, is_disable, _disable_user_data);
+}
+
+static int __disable_cb(const char *endpoint, aul_app_com_result_e e,
+               bundle *widget_info, void *user_data)
+{
+       char *disable = NULL;
+       char *widget_id = NULL;
+
+       bundle_get_str(widget_info, AUL_K_WIDGET_DISABLE, &disable);
+       bundle_get_str(widget_info, AUL_K_WIDGET_ID, &widget_id);
+
+       __notify_disable(widget_id, (bool)atoi(disable));
+
+       return WIDGET_ERROR_NONE;
+}
+
+EAPI int widget_service_set_disable_event_cb(widget_disable_event_cb cb,
+               void *user_data)
+{
+       if (aul_app_com_create(DISABLE_ENDPOINT, NULL,
+                       __disable_cb, NULL, &_conn) < 0) {
+               _E("failed to create app com endpoint");
+               return WIDGET_ERROR_IO_ERROR;
+       }
+
+       _disable_event_cb = cb;
+       _disable_user_data = user_data;
+
+       return WIDGET_ERROR_NONE;
+}
+
+EAPI int widget_service_unset_disable_event_cb()
+{
+       int ret = WIDGET_ERROR_NONE;
+
+       if (_conn) {
+               if (aul_app_com_leave(_conn) < 0)
+                       _E("failed to leave app com disable");
+               _conn = NULL;
+               ret = WIDGET_ERROR_FAULT;
+               goto out;
+       }
+
+out:
+       if (_disable_event_cb)
+               _disable_event_cb = NULL;
+
+       if (_disable_user_data)
+               _disable_user_data = NULL;
+
+       return ret;
+}