* @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_INVALID_PARAMETER Invalid argument
* @retval #WIDGET_ERROR_PERMISSION_DENIED Permission denied
*/
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);
+
/**
* @}
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
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)
{
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;
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;
}
_get_column_int(stmt, 0, &disable);
- *is_disable = (bool)disable;
+ *is_disabled = (bool)disable;
sqlite3_free(query);
sqlite3_finalize(stmt);
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;
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");
}
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,
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;
}