sound: Intialize theme id by default value only when it hasn't been initialized 09/305309/4 accepted/tizen/7.0/unified/20240201.013921
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 31 Jan 2024 06:29:11 +0000 (15:29 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 31 Jan 2024 07:24:05 +0000 (16:24 +0900)
It is necessary to keep the previous theme id if it once has been
initialized to the valid value. Otherwise, it will always be reset
to the default theme id, overwriting the previous valid theme id.

Change-Id: Ie5ba57820f31e5718bb4951ba918781ebd6fa263
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/sound.c

index cee9724..13c855e 100644 (file)
 #define VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL "db/setting/sound/button_sounds"
 #endif
 
+#define SOUND_THEME_ID_UNINITIALIZED 0
+
 static int sndstatus;
 static int touch_sndstatus;
 static int keytone_sndstatus;
 static unsigned int current_theme_id = 0;
 
+static int sound_set_theme_id(unsigned int id_of_theme);
+
 static const char *get_data(feedback_pattern_e pattern)
 {
        const char *data;
@@ -146,12 +150,22 @@ static void feedback_sound_theme_changed_cb(keynode_t *key, void* data)
        current_theme_id = vconf_keynode_get_int(key);
 }
 
+static void sound_theme_id_init(void)
+{
+       int ret;
+       unsigned int theme_id = SOUND_THEME_ID_UNINITIALIZED;
+
+       ret = vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME, (int *) &theme_id);
+       if (ret < 0 || theme_id == SOUND_THEME_ID_UNINITIALIZED)
+               sound_thememan_get_default_sound_theme_id(&theme_id);
+
+       sound_set_theme_id(theme_id);
+}
+
 static void sound_init(void)
 {
        int ret = 0;
 
-       current_theme_id = 0;
-
        ret = sound_thememan_init();
        if (ret < 0) {
                _E("Failed to initialize sound theme manager(%d)", ret);
@@ -165,8 +179,7 @@ static void sound_init(void)
                sound_parser_exit();
        }
 
-       sound_thememan_get_default_sound_theme_id(&current_theme_id);
-       ret = vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SOUND_FEEDBACK_THEME, current_theme_id);
+       sound_theme_id_init();
 
        /* check sound status */
        if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &touch_sndstatus) < 0)