feedback: Add vconfkey notifier callback from multi-theme selection 95/297595/1
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 18 Aug 2023 02:45:42 +0000 (11:45 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 21 Aug 2023 07:45:31 +0000 (16:45 +0900)
Support vconfkey notifier to inform feedback current theme value is changed.

Change-Id: I2d8d7cb52e844ff498c4294ae1b955b01042ed4b
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/sound.c
src/vibrator.c

index d5e2a8d..c2f2fd4 100644 (file)
@@ -117,6 +117,18 @@ static void feedback_keytone_sndstatus_cb(keynode_t *key, void* data)
 }
 //LCOV_EXCL_STOP
 
+static void feedback_sound_theme_changed_cb(keynode_t *key, void* data)
+{
+       int vconf_sound_theme_index = vconf_keynode_get_int(key);
+
+       if (vconf_sound_theme_index <= 0) {
+               current_theme_index = 0;
+               return;
+       }
+
+       current_theme_index = vconf_keynode_get_int(key) - 1;
+}
+
 static int feedback_parse_sound_multi_theme_section(const struct parse_result *result, void *data)
 {
        struct section_property *extracted_section_prop = NULL;
@@ -253,6 +265,9 @@ static void sound_init(void)
        number_of_theme = 0;
        current_theme_index = 0;
 
+       if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME, &current_theme_index) < 0)
+               _W("Failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME");
+
        ret = sound_get_config();
        if (ret < 0)
                _W("Failed to load configuration file(%s): %d", SOUND_CONF_FILE, ret);
@@ -279,6 +294,9 @@ static void sound_init(void)
        ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, feedback_keytone_sndstatus_cb, NULL);
        if (ret != 0)
                _W("Add watch for VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL failed"); //LCOV_EXCL_LINE
+       ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME, feedback_sound_theme_changed_cb, NULL);
+       if (ret != 0)
+               _W("Add watch for VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME failed");
 }
 
 static void sound_put_config(void)
@@ -308,6 +326,9 @@ static void sound_exit(void)
        ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, feedback_keytone_sndstatus_cb);
        if (ret != 0)
                _W("Remove watch for VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL failed"); //LCOV_EXCL_LINE
+       ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME, feedback_sound_theme_changed_cb);
+       if (ret != 0)
+               _W("Remove watch for VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME failed");
 
        sound_put_config();
 }
@@ -615,9 +636,17 @@ static int sound_get_theme_index(unsigned int *index_of_theme)
 
 static int sound_set_theme_index(unsigned int index_of_theme)
 {
+       int ret = 0;
+
        if (index_of_theme > number_of_theme || index_of_theme <= 0)
                return -EINVAL;
 
+       ret = vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME, current_theme_index+1);
+       if (ret < 0) {
+               _E("Failed to set vconf value for VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME");
+               return -EPERM;
+       }
+
        current_theme_index = index_of_theme - 1;
 
        return 0;
index 7ad95c5..f25f584 100644 (file)
@@ -55,6 +55,7 @@ enum haptic_iteration {
 
 static int vibstatus;
 static unsigned int v_handle;
+static int current_theme_index = 0;
 
 static inline char *trim_str(char *s)
 {
@@ -146,11 +147,19 @@ static void feedback_vibstatus_cb(keynode_t *key, void* data)
 }
 //LCOV_EXCL_STOP
 
+static void feedback_vibration_theme_changed_cb(keynode_t *key, void* data)
+{
+       current_theme_index = vconf_keynode_get_int(key) - 1;
+}
+
 static void vibrator_init(void)
 {
        int ret_val;
        bool haptic_avail;
 
+       if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_VIBRATION_FEEDBACK_THEME, &current_theme_index) < 0)
+               _W("Failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_VIBRATION_FEEDBACK_THEME");
+
        ret_val = system_info_get_platform_bool(VIBRATION_FEATURE, &haptic_avail);
        if (ret_val < 0) { //LCOV_EXCL_LINE
                v_handle = -ENOTSUP; //LCOV_EXCL_LINE
@@ -179,6 +188,9 @@ static void vibrator_init(void)
        ret_val = vconf_notify_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, feedback_vibstatus_cb, NULL);
        if (ret_val != 0)
                _W("Add watch for VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL failed"); //LCOV_EXCL_LINE
+       ret_val = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_VIBRATION_FEEDBACK_THEME, feedback_vibration_theme_changed_cb, NULL);
+       if (ret_val != 0)
+               _W("Add watch for VCONFKEY_SETAPPL_ACCESSIBILITY_VIBRATION_FEEDBACK_THEME failed");
 }
 
 
@@ -196,6 +208,9 @@ static void vibrator_exit(void)
        ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, feedback_vibstatus_cb);
        if (ret != 0)
                _W("Remove watch for VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL failed"); //LCOV_EXCL_LINE
+       ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_VIBRATION_FEEDBACK_THEME, feedback_vibration_theme_changed_cb);
+       if (ret != 0)
+               _W("Remove watch for VCONFKEY_SETAPPL_ACCESSIBILITY_VIBRATION_FEEDBACK_THEME failed");
 }
 
 static int vibrator_play(feedback_pattern_e pattern, bool always)