Add cmd for to set widget disable
authorSukHyung, Kang <shine.kang@samsung.com>
Thu, 27 Feb 2020 10:29:03 +0000 (19:29 +0900)
committerSukHyung, Kang <shine.kang@samsung.com>
Tue, 3 Mar 2020 23:47:58 +0000 (08:47 +0900)
Change-Id: I3294e162833b305b6f064d4dae42522f8fd6aad9
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
Conflicts:
src/widget.c

include/aul_cmd.h
include/aul_key.h
include/aul_widget.h
src/aul_cmd.c
src/widget.c

index bf7160a..bf21132 100755 (executable)
@@ -178,6 +178,8 @@ enum app_cmd {
        APP_SEND_RESUME_REQUEST = 139,
        APP_PREPARE_APP_DEFINED_LOADER = 140,
 
+       WIDGET_DISABLE = 141,
+
        APP_CMD_MAX
 };
 
index ead9ed3..60f84c8 100644 (file)
 #define AUL_K_LAUNCHER_SERVICE_EVENT    "__K_LAUNCHER_SERVICE_EVENT__"
 
 /**
- * @brief Definition for AUL: The name of the app-defined loader
+ * @brief Definition for AUL: The name of the app-defined loader.
  * @since_tizen 5.5
  */
 #define AUL_K_APP_DEFINED_LOADER        "__K_APP_DEFINED_LOADER__"
+
+/**
+ * @brief Definition for AUL: The widget disable.
+ * @since_tizen 5.5
+ */
+#define AUL_K_WIDGET_DISABLE "__AUL_WIDGET_DISABLE__"
index 2b0dd0d..3fd6eff 100755 (executable)
@@ -148,6 +148,10 @@ int aul_widget_instance_change_status(const char *widget_id, const char *status)
  */
 int aul_widget_write_log(const char *tag, const char *format, ...);
 
+int aul_widget_service_set_disable(const char *widget_id, bool is_disable);
+
+int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable);
+
 #ifdef __cplusplus
 }
 #endif
index 46d071c..cacf378 100755 (executable)
@@ -306,6 +306,8 @@ API const char *aul_cmd_convert_to_string(int cmd)
                return "APP_SEND_RESUME_REQUEST";
        case APP_PREPARE_APP_DEFINED_LOADER:
                return "APP_PREPARE_APP_DEFINED_LOADER";
+       case WIDGET_DISABLE:
+               return "WIDGET_DISABLE";
        default:
                return "CUSTOM_COMMAND";
        }
index 7e25a85..913f732 100644 (file)
@@ -34,6 +34,7 @@
 #include "aul_error.h"
 #include "launch.h"
 #include "aul_widget.h"
+#include "aul_db.h"
 
 struct aul_widget_info_s {
        char *widget_id;
@@ -52,6 +53,7 @@ struct widget_cb_info {
 
 #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;
@@ -625,3 +627,91 @@ API int aul_widget_instance_change_status(const char *widget_id,
 
        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;
+}