#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <iniparser.h>
#include <glib.h>
#include <pwd.h>
#include <aul_widget.h>
+#include <aul_app_com.h>
#include <system_info.h>
#include "widget_errno.h"
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 ( \
} while (0)
#define WIDGET_TBL_COUNT 4
+#define DISABLE_ENDPOINT "widget.disable"
+
static char *_widget_table_list[WIDGET_TBL_COUNT] = {
"icon",
"label",
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)
{
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) {
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) {
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;
}
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;
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)
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;
+}