[haptic]Add haptic feature 12/178812/4 accepted/tizen/unified/20180611.132136 submit/tizen/20180611.005638
authorpr.jung <pr.jung@samsung.com>
Mon, 14 May 2018 06:19:27 +0000 (15:19 +0900)
committerJung <pr.jung@samsung.com>
Thu, 31 May 2018 06:10:01 +0000 (06:10 +0000)
Change-Id: I260519fc2f56d9c5680d3b5e52b9050ade687f08
Signed-off-by: pr.jung <pr.jung@samsung.com>
doc/device_doc.h
src/haptic.c

index 6ffa258..854cd95 100755 (executable)
@@ -79,7 +79,7 @@
 /**
  * @ingroup CAPI_SYSTEM_DEVICE_MODULE
  * @defgroup CAPI_SYSTEM_DEVICE_HAPTIC_MODULE Haptic
- * @brief The Haptic API provides functions to control a vibrator.
+ * @brief The Haptic API provides functions to control vibration.
  *
  * @section CAPI_SYSTEM_DEVICE_HAPTIC_MODULE_HEADER Required Header
  *   \#include <device/haptic.h> \n
  * The Haptic API provides the way to control vibration functionality of a device.
  * It allows the management of the device's vibrator parameters, such as the vibration count and level.
  *
+ * @section CAPI_SYSTEM_DEVICE_HAPTIC_MODULE__FEATURE Related Features
+ * This API is related with the following features:\n
+ * - %http://tizen.org/feature/feedback.vibration\n
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature List</b>.</a>
+ *
+ *
  */
 
 /**
index b5a0ecd..14aaf03 100644 (file)
@@ -32,6 +32,8 @@
 #define METHOD_STOP_DEVICE                     "StopDevice"
 #define METHOD_VIBRATE_MONOTONE                "VibrateMonotone"
 
+#define VIBRATION_FEATURE              "http://tizen.org/feature/feedback.vibration"
+
 enum feedback_e {
        HAPTIC_FEEDBACK_MIN = 0,
        HAPTIC_FEEDBACK_MAX = 100,
@@ -50,6 +52,22 @@ struct haptic_handle {
 
 static dd_list *handle_list;
 
+static int is_haptic_supported(void)
+{
+       int ret;
+       bool haptic_avail;
+
+       ret = system_info_get_platform_bool(VIBRATION_FEATURE, &haptic_avail);
+       if (ret < 0) {
+               _E("Failed to get value of haptic feature");
+               return false;
+       } else if (ret == 0 && !haptic_avail) {
+               _D("Haptic is not supported");
+               return false;
+       } else
+               return true;
+}
+
 int device_haptic_get_count(int *device_number)
 {
        int ret;
@@ -57,6 +75,10 @@ int device_haptic_get_count(int *device_number)
        if (!device_number)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       ret = is_haptic_supported();
+       if (!ret)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        /* request to deviced to get haptic count */
        ret = dbus_method_sync(VIBRATOR_BUS_NAME,
                        VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC,
@@ -119,6 +141,10 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle)
        if (!device_handle)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       ret = is_haptic_supported();
+       if (!ret)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        snprintf(str_index, sizeof(str_index), "%d", device_index);
        arr[0] = str_index;
 
@@ -171,6 +197,10 @@ int device_haptic_close(haptic_device_h device_handle)
        if (!device_handle)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       ret = is_haptic_supported();
+       if (!ret)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        DD_LIST_FOREACH(handle_list, elem, temp) {
                if (temp->handle != handle->handle)
                        continue;
@@ -223,6 +253,10 @@ int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedb
        if (feedback < HAPTIC_FEEDBACK_MIN || feedback > HAPTIC_FEEDBACK_MAX)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       ret = is_haptic_supported();
+       if (!ret)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        priority = HAPTIC_PRIORITY_MIN;
 
        DD_LIST_FOREACH(handle_list, elem, temp) {
@@ -269,6 +303,10 @@ int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_han
        if (!device_handle)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       ret = is_haptic_supported();
+       if (!ret)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        DD_LIST_FOREACH(handle_list, elem, temp) {
                if (temp != handle)
                        continue;