feedback: Add feedback_stop_type_internal() 10/298910/1
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 13 Sep 2023 01:39:30 +0000 (10:39 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 15 Sep 2023 06:01:18 +0000 (15:01 +0900)
To support feedback stop according to the feedback type.
With this, it is possible to stop sound feedback play.
"http://tizen.org/privilege/haptic" haptic privilege is required to stop the vibrator.

Change-Id: I4798f805be9f2a6bebc0d6f7da68011a98c3e4f1
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
include/feedback-internal.h
src/devices.c
src/devices.h
src/feedback.c

index 844b309..0562258 100755 (executable)
@@ -210,6 +210,23 @@ int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigned in
 int feedback_set_theme_index_internal(feedback_type_e feedback_type, unsigned int index_of_theme);
 
 /**
+ * @brief Stops various types of reactions by feedback type.
+ * @details This function can be used to stop reaction to pre-defined actions.
+ *          It stops system pre-defined vibration and sound patterns.
+ * @since_tizen 7.0
+ * @remarks To stop vibrator feedback, the privilege should be set to, %http://tizen.org/privilege/haptic.
+ * @param[in] feedback_type The feedback type
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #FEEDBACK_ERROR_NONE Successful
+ * @retval #FEEDBACK_ERROR_OPERATION_FAILED Operation not permitted
+ * @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
+ * @retval #FEEDBACK_ERROR_PERMISSION_DENIED Permission denied
+ */
+int feedback_stop_type_internal(feedback_type_e feedback_type);
+
+/**
  * @}
  */
 
index 1dc8252..f2daabd 100644 (file)
@@ -148,3 +148,16 @@ int devices_stop(void)
        return ret;
 }
 //LCOV_EXCL_STOP
+
+int devices_stop_by_type(feedback_type_e feedback_type)
+{
+       GList *elem;
+       const struct device_ops *dev;
+
+       SYS_G_LIST_FOREACH(dev_head, elem, dev) {
+               if (dev->type == feedback_type)
+                       return dev->stop();
+       }
+
+       return -ENOTSUP;
+}
index 6a9aedb..e7cca85 100644 (file)
@@ -44,6 +44,7 @@ void devices_exit(void);
 int devices_play(int pattern, bool always);
 int devices_play_soundpath(int pattern, const char *soundpath, bool always);
 int devices_stop(void);
+int devices_stop_by_type(feedback_type_e feedback_type);
 
 #define DEVICE_OPS_REGISTER(dev)       \
 static void __CONSTRUCTOR__ module_init(void)  \
index c0b6800..8750745 100644 (file)
@@ -638,3 +638,26 @@ API int feedback_set_theme_index_internal(feedback_type_e feedback_type, unsigne
        return FEEDBACK_ERROR_NONE;
 }
 //LCOV_EXCL_STOP
+
+API int feedback_stop_type_internal(feedback_type_e feedback_type)
+{
+       int err;
+
+       pthread_mutex_lock(&fmutex);
+       if (!init_cnt) {
+               _E("Not initialized");
+               pthread_mutex_unlock(&fmutex);
+               return FEEDBACK_ERROR_NOT_INITIALIZED;
+       }
+       pthread_mutex_unlock(&fmutex);
+
+       err = devices_stop_by_type(feedback_type);
+       if (err == -ENOTSUP)
+               return FEEDBACK_ERROR_NOT_SUPPORTED;
+       if (err == -ECOMM || err == -EACCES)
+               return FEEDBACK_ERROR_PERMISSION_DENIED;
+       if (err < 0)
+               return FEEDBACK_ERROR_OPERATION_FAILED;
+
+       return FEEDBACK_ERROR_NONE;
+}