#include "aul_error.h"
#include "launch.h"
#include "aul_widget.h"
+#include "aul_db.h"
struct aul_widget_info_s {
char *widget_id;
#define WIDGET_LOG_BUFFER_SIZE 10000
#define WIDGET_LOG_BUFFER_STRING_SIZE 256
+#define WIDGET_SERVICE_DB ".widget.db"
static int __log_index;
static int __log_fd;
return AUL_R_OK;
}
+
+API int aul_widget_service_set_disable(const char *widget_id, bool is_disable)
+{
+ int ret;
+ bundle *kb;
+ char ambient_mode[32] = {0, };
+
+ if (widget_id == NULL)
+ return AUL_R_EINVAL;
+
+ kb = bundle_create();
+ if (kb == NULL) {
+ _E("out of memory");
+ return AUL_R_ERROR;
+ }
+
+ snprintf(ambient_mode, sizeof(ambient_mode), "%d", (int)is_disable);
+
+ bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
+ bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
+ bundle_add_str(kb, AUL_K_WIDGET_DISABLE, ambient_mode);
+
+ ret = app_send_cmd(AUL_UTIL_PID, WIDGET_DISABLE, kb);
+ if (ret)
+ _E("widget disable send cmd error");
+
+ bundle_free(kb);
+
+ return ret;
+}
+
+static sqlite3 *__open_widget_service_db(uid_t uid, bool readonly)
+{
+ sqlite3 *db;
+ char *path;
+
+ path = aul_db_get_path(WIDGET_SERVICE_DB, uid);
+ if (!path) {
+ _E("Failed to get db path");
+ return NULL;
+ }
+
+ db = aul_db_open(path, readonly);
+ free(path);
+
+ return db;
+}
+
+API int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable)
+{
+ int ret;
+ sqlite3 *db;
+ sqlite3_stmt *stmt;
+ char *query;
+
+ query = sqlite3_mprintf("UPDATE widget_class SET is_disable= %d"
+ " WHERE classid = %Q", (int)is_disable, widget_id);
+
+ db = __open_widget_service_db(getuid(), false);
+ if (db == NULL) {
+ _E("widget db null");
+ sqlite3_free(query);
+ return AUL_R_ERROR;
+ }
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("widget db prepare error: %s", sqlite3_errmsg(db));
+ sqlite3_free(query);
+ sqlite3_close_v2(db);
+ return AUL_R_ERROR;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_DONE && ret != SQLITE_OK) {
+ _E("widget set disable db error: %s", sqlite3_errmsg(db));
+ sqlite3_free(query);
+ sqlite3_finalize(stmt);
+ sqlite3_close_v2(db);
+ return AUL_R_ERROR;
+ }
+
+ sqlite3_free(query);
+ sqlite3_finalize(stmt);
+ sqlite3_close_v2(db);
+
+ return AUL_R_OK;
+}