Move widget disable/enable api to public
authorSukHyung, Kang <shine.kang@samsung.com>
Thu, 2 Apr 2020 09:39:13 +0000 (18:39 +0900)
committerSukHyung, Kang <shine.kang@samsung.com>
Thu, 16 Apr 2020 04:58:54 +0000 (13:58 +0900)
Change-Id: Ibd4c71ab60c204bb5fdebec63220298c65bb850b
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
include/widget_service.h
include/widget_service_internal.h
src/widget_service.c

index 4c9314aa1c01af9b86393835734d9d528004d4a8..6cbf5fa43c87c806df205618258bee2a2af95e9f 100644 (file)
@@ -550,7 +550,7 @@ typedef int (*widget_lifecycle_event_cb)(const char *widget_id, widget_lifecycle
  * @param[in] widget_id appid of widget application
  * @param[in] cb Callback function
  * @param[in] data user Data
- * @return @0 on success,
+ * @return @0 on success,
  *         otherwise a negative error value
  * @retval #WIDGET_ERROR_INVALID_PARAMETER Invalid argument
  * @retval #WIDGET_ERROR_PERMISSION_DENIED Permission denied
@@ -589,6 +589,90 @@ extern int widget_service_unset_lifecycle_event_cb(const char *widget_id, void *
  */
 extern int widget_service_get_content_of_widget_instance(const char *widget_id, const char *widget_instance_id, bundle **b);
 
+/**
+ * @brief Called when a widget is disabled or enabled.
+ * @since_tizen 5.5
+ * @param[in] widget_id The widget id\n
+ *            The @a widget_id can be used only in the callback. To use outside, make a copy.
+ * @param[in] is_disabled The new value of the 'disabled' state of the widget
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see widget_service_set_disable_event_cb()
+ * @see widget_service_unset_disable_event_cb()
+ */
+typedef void (*widget_disable_event_cb)(const char *widget_id, bool is_disabled, void *user_data);
+
+/**
+ * @platform
+ * @brief Sets the 'disabled' state of a widget.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/packagemanager.admin
+ * @param[in] widget_id The widget id
+ * @param[in] is_disabled @c true, the widget will be disabled
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval WIDGET_ERROR_NONE Successfully done
+ * @retval WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval WIDGET_ERROR_PERMISSION_DENIED Permission denied
+ * @retval WIDGET_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval WIDGET_ERROR_FAULT Fault
+ */
+int widget_service_set_widget_disabled(const char *widget_id, bool disabled);
+
+/**
+ * @brief Gets the 'disabled' state of a widget.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/widget.viewer
+ * @param[in] widget_id The widget id
+ * @param[out] is_disabled The disable state of widget
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval WIDGET_ERROR_NONE Successfully done
+ * @retval WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval WIDGET_ERROR_PERMISSION_DENIED Permission denied
+ * @retval WIDGET_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval WIDGET_ERROR_IO_ERROR Failed to access DB
+ * @retval WIDGET_ERROR_FAULT Fault
+ */
+int widget_service_get_widget_disabled(const char *widget_id, bool *is_disabled);
+
+/**
+ * @brief Sets the callback function for widget disable event.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/widget.viewer
+ * @remarks The @a callback should be unset using widget_service_unset_disable_event_cb() before the application exits.
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval WIDGET_ERROR_NONE Successfully done
+ * @retval WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval WIDGET_ERROR_PERMISSION_DENIED Permission denied
+ * @retval WIDGET_ERROR_INVALID_PARAMETER Invalid argument
+ * @retval WIDGET_ERROR_IO_ERROR IO error
+ * @see widget_disable_event_cb()
+ * @see widget_service_unset_disable_event_cb()
+ */
+int widget_service_set_disable_event_cb(widget_disable_event_cb callback, void *user_data);
+
+/**
+ * @brief Unsets the callback function for widget disable event.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/widget.viewer
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval WIDGET_ERROR_NONE Successfully done
+ * @retval WIDGET_ERROR_NOT_SUPPORTED Not supported
+ * @retval WIDGET_ERROR_PERMISSION_DENIED Permission denied
+ * @retval WIDGET_ERROR_IO_ERROR IO error
+ * @see widget_disable_event_cb()
+ * @see widget_service_set_disable_event_cb()
+ */
+int widget_service_unset_disable_event_cb(void);
+
 
 /**
  * @}
index ce9f549c4109c234c1674170241f166f6f1756f6..a9a8251c40ac0207243568d2b214144fe3c15319 100644 (file)
@@ -768,13 +768,6 @@ 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 15c7a7e9c2d5e9e8d58843f3116f3d6e76bf3b63..8cd0cab56d11eff12c4c39aec229ea49bbdefd9e 100644 (file)
@@ -132,7 +132,6 @@ 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)
 {
@@ -2758,8 +2757,8 @@ 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)
+EAPI int widget_service_set_widget_disabled(const char *widget_id,
+               bool disabled)
 {
        int ret;
 
@@ -2773,21 +2772,25 @@ EAPI int widget_service_set_widget_disable(const char *widget_id,
                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, disabled);
+       if (ret) {
+               _E("set disable error : %d", ret);
+               switch (ret) {
+               case AUL_R_ECOMM:
+                       ret = WIDGET_ERROR_IO_ERROR;
+                       break;
+               case AUL_R_EILLACC:
+                       ret = WIDGET_ERROR_PERMISSION_DENIED;
+                       break;
+               default:
+                       ret = WIDGET_ERROR_FAULT;
+               }
        }
 
-       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)
+static int _get_disable(const char *widget_id, bool *is_disabled, uid_t uid)
 {
        int ret;
        sqlite3 *db;
@@ -2827,7 +2830,7 @@ static int _get_disable(const char *widget_id, bool *is_disable, uid_t uid)
        }
        _get_column_int(stmt, 0, &disable);
 
-       *is_disable = (bool)disable;
+       *is_disabled = (bool)disable;
 
        sqlite3_free(query);
        sqlite3_finalize(stmt);
@@ -2836,8 +2839,8 @@ static int _get_disable(const char *widget_id, bool *is_disable, uid_t uid)
        return WIDGET_ERROR_NONE;
 }
 
-EAPI int widget_service_get_widget_disable(const char *widget_id,
-               bool *is_disable)
+EAPI int widget_service_get_widget_disabled(const char *widget_id,
+               bool *is_disabled)
 {
        int ret;
 
@@ -2851,9 +2854,12 @@ EAPI int widget_service_get_widget_disable(const char *widget_id,
                return WIDGET_ERROR_INVALID_PARAMETER;
        }
 
-       ret = _get_disable(widget_id, is_disable, getuid());
+       if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0)
+               return WIDGET_ERROR_PERMISSION_DENIED;
+
+       ret = _get_disable(widget_id, is_disabled, getuid());
        if (ret != WIDGET_ERROR_NONE && !_is_global(getuid())) {
-               ret = _get_disable(widget_id, is_disable, GLOBALAPP_USER);
+               ret = _get_disable(widget_id, is_disabled, GLOBALAPP_USER);
                if (ret)
                        _E("failed to get disable");
        }
@@ -2861,9 +2867,9 @@ EAPI int widget_service_get_widget_disable(const char *widget_id,
        return ret;
 }
 
-static void __notify_disable(const char *widget_id, bool is_disable)
+static void __notify_disable(const char *widget_id, bool is_disabled)
 {
-       _disable_event_cb(widget_id, is_disable, _disable_user_data);
+       _disable_event_cb(widget_id, is_disabled, _disable_user_data);
 }
 
 static int __disable_cb(const char *endpoint, aul_app_com_result_e e,
@@ -2880,30 +2886,51 @@ static int __disable_cb(const char *endpoint, aul_app_com_result_e e,
        return WIDGET_ERROR_NONE;
 }
 
-EAPI int widget_service_set_disable_event_cb(widget_disable_event_cb cb,
+EAPI int widget_service_set_disable_event_cb(widget_disable_event_cb callback,
                void *user_data)
 {
+       if (callback == NULL) {
+               _E("invalid parameter");
+               return WIDGET_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!_is_widget_feature_enabled()) {
+               _E("Not supported");
+               return WIDGET_ERROR_NOT_SUPPORTED;
+       }
+
+       if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0)
+               return WIDGET_ERROR_PERMISSION_DENIED;
+
        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_event_cb = callback;
        _disable_user_data = user_data;
 
        return WIDGET_ERROR_NONE;
 }
 
-EAPI int widget_service_unset_disable_event_cb()
+EAPI int widget_service_unset_disable_event_cb(void)
 {
        int ret = WIDGET_ERROR_NONE;
 
+       if (!_is_widget_feature_enabled()) {
+               _E("not supported");
+               return WIDGET_ERROR_NOT_SUPPORTED;
+       }
+
+       if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0)
+               return WIDGET_ERROR_PERMISSION_DENIED;
+
        if (_conn) {
                if (aul_app_com_leave(_conn) < 0)
                        _E("failed to leave app com disable");
                _conn = NULL;
-               ret = WIDGET_ERROR_FAULT;
+               ret = WIDGET_ERROR_IO_ERROR;
                goto out;
        }