standard: fix infinite vibration 22/222822/7 accepted/tizen/unified/20200129.022601 submit/tizen/20200121.090851 submit/tizen/20200122.232403
authorYunmi Ha <yunmi.ha@samsung.com>
Mon, 20 Jan 2020 10:07:33 +0000 (19:07 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Tue, 21 Jan 2020 02:56:56 +0000 (11:56 +0900)
- If feedbackd receives another vibration request
without stopping the previous vibration,
there's not way to stop the previous one, probably causing infinite vibration.

- So, feedbackd should override the previous effect id on a new request
to keep a single effect id.

Change-Id: I2ab714ac4e5103ca65d3b4697e82240b09d58996
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/haptic/standard.c

index af43425..d27139a 100644 (file)
@@ -73,6 +73,7 @@ static dd_list *ff_list;
 static dd_list *handle_list;
 static char ff_path[PATH_MAX];
 static int unique_number;
+static int current_effect_id = -1;
 
 static int stop_device(int device_handle);
 
@@ -253,10 +254,14 @@ static int ff_play(int fd, struct ff_effect *effect)
        }
 
        /* upload an effect */
-       if (ioctl(fd, EVIOCSFF, effect) == -1) {
-               _E("Failed to ioctl");
-               return -errno;
-       }
+       if (current_effect_id == -1) {
+               if (ioctl(fd, EVIOCSFF, effect) == -1) {
+                       _E("Failed to ioctl");
+                       return -errno;
+               }
+               current_effect_id = effect->id;
+       } else
+               effect->id = current_effect_id;
 
        /* play vibration*/
        play.type = EV_FF;
@@ -280,6 +285,12 @@ static int ff_stop(int fd, struct ff_effect *effect)
        if (fd < 0 || !effect)
                return -EINVAL;
 
+       if (effect->id == -1) {
+               if (current_effect_id == -1)
+                       return 0;
+               effect->id = current_effect_id;
+       }
+
        /* Stop vibration */
        stop.type = EV_FF;
        stop.code = effect->id;
@@ -294,6 +305,7 @@ static int ff_stop(int fd, struct ff_effect *effect)
 
        /* reset effect id */
        effect->id = -1;
+       current_effect_id = -1;
 
        return 0;
 }