From: SukHyung, Kang Date: Thu, 2 Apr 2020 09:39:13 +0000 (+0900) Subject: Move widget disable/enable api to public X-Git-Tag: submit/tizen/20200409.012141~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F28%2F229628%2F9;p=platform%2Fcore%2Fappfw%2Fwidget-service.git Move widget disable/enable api to public Change-Id: Ibd4c71ab60c204bb5fdebec63220298c65bb850b Signed-off-by: SukHyung, Kang --- diff --git a/include/widget_service.h b/include/widget_service.h index e1421e2..17ed6e7 100644 --- a/include/widget_service.h +++ b/include/widget_service.h @@ -615,7 +615,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 @c 0 on success, * otherwise a negative error value * @retval #WIDGET_ERROR_NONE Successfully done * @retval #WIDGET_ERROR_NOT_SUPPORTED Not supported @@ -661,6 +661,90 @@ int widget_service_unset_lifecycle_event_cb(const char *widget_id, void **user_d */ 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); + /** * @} diff --git a/include/widget_service_internal.h b/include/widget_service_internal.h index ce9f549..a9a8251 100644 --- a/include/widget_service_internal.h +++ b/include/widget_service_internal.h @@ -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 diff --git a/src/widget_service.c b/src/widget_service.c index d8d3d87..e8e6bf8 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -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) { @@ -2775,8 +2774,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; @@ -2790,21 +2789,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; @@ -2844,7 +2847,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); @@ -2853,8 +2856,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; @@ -2868,9 +2871,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"); } @@ -2878,9 +2884,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, @@ -2897,30 +2903,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; }