sound: Fix checking default theme duplication 37/301837/4
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 24 Nov 2023 08:23:08 +0000 (17:23 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Wed, 29 Nov 2023 10:36:22 +0000 (19:36 +0900)
Previously, the default theme was not checked properly as intended.
It is necessary to check default sound theme duplication.

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

index ca81608..e4eb1e3 100644 (file)
@@ -51,6 +51,13 @@ static bool is_sound_theme_id_duplicated(int sound_theme_id)
        return false;
 }
 
+static bool is_default_theme_id_set(void)
+{
+       if (default_sound_theme_id == INITIAL_DEFAULT_SOUND_THEME_ID)
+               return false;
+       return true;
+}
+
 static int parse_sound_theme_property(gpointer data, gpointer user_data)
 {
        struct section_property *prop = (struct section_property *) data;
@@ -100,17 +107,16 @@ static int parse_sound_theme_section(const struct parse_result *result, void *da
                        goto out_parsing_fail;
        }
 
-       if (sound_theme_elem.is_default && (sound_theme_elem.id == default_sound_theme_id)) {
-               _E("Failed to parse sound conf file, default sound theme is duplicated.");
-               goto out_parsing_fail;
-       }
-
        if (is_sound_theme_id_duplicated(sound_theme_elem.id)) {
                _E("Failed to parse sound conf file, sound theme id is duplicated.");
                goto out_parsing_fail;
        }
 
        if (sound_theme_elem.is_default) {
+               if (is_default_theme_id_set()) {
+                       _E("Failed to parse sound conf file, default sound theme is duplicated.");
+                       goto out_parsing_fail;
+               }
                default_sound_theme_id = sound_theme_elem.id;
                sound_thememan_set_default_sound_theme_id(default_sound_theme_id);
        }
@@ -133,14 +139,13 @@ out_parsing_fail:
 int sound_parser_init(const char* sound_file_path)
 {
        int ret = 0;
-       default_sound_theme_id = INITIAL_DEFAULT_SOUND_THEME_ID;
 
        g_hash_table_to_check_id_duplicated = g_hash_table_new_full(g_int_hash, g_int_equal,
                                                                        g_free, g_free);
 
        ret = libsys_config_parse_by_section(sound_file_path, parse_sound_theme_section, NULL);
 
-       if (default_sound_theme_id == INITIAL_DEFAULT_SOUND_THEME_ID) {
+       if (!is_default_theme_id_set()) {
                _E("Failed to parse sound conf file. There is no default sound theme id");
                ret = -EPERM;
        }
@@ -152,4 +157,9 @@ int sound_parser_init(const char* sound_file_path)
                return ret;
 
        return 0;
+}
+
+void sound_parser_exit(void)
+{
+       default_sound_theme_id = INITIAL_DEFAULT_SOUND_THEME_ID;
 }
\ No newline at end of file
index b25bc81..f72791d 100644 (file)
@@ -19,5 +19,6 @@
 #define __SOUND_PARSER_H__
 
 int sound_parser_init(const char* sound_file_path);
+void sound_parser_exit(void);
 
 #endif
\ No newline at end of file
index bf31a9f..612c8a5 100644 (file)
@@ -151,6 +151,7 @@ static void sound_init(void)
        if (ret < 0) {
                _E("Failed to parsing sound config file(%d)", ret);
                sound_thememan_exit();
+               sound_parser_exit();
        }
 
        sound_thememan_get_default_sound_theme_id(&current_theme_id);
@@ -187,6 +188,7 @@ static void sound_exit(void)
 {
        int ret;
 
+       sound_parser_exit();
        sound_thememan_exit();
 
        /* remove watch */