sound: Fix checking default theme duplication
[platform/core/system/libsvi.git] / src / sound-parser.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