From f9adeff852dd5483ebaa04f9109d9e4a865f1f33 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 24 Nov 2023 17:23:08 +0900 Subject: [PATCH] sound: Fix checking default theme duplication 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 --- src/sound-parser.c | 24 +++++++++++++++++------- src/sound-parser.h | 1 + src/sound.c | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/sound-parser.c b/src/sound-parser.c index ca81608..e4eb1e3 100644 --- a/src/sound-parser.c +++ b/src/sound-parser.c @@ -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 diff --git a/src/sound-parser.h b/src/sound-parser.h index b25bc81..f72791d 100644 --- a/src/sound-parser.h +++ b/src/sound-parser.h @@ -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 diff --git a/src/sound.c b/src/sound.c index bf31a9f..612c8a5 100644 --- a/src/sound.c +++ b/src/sound.c @@ -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(¤t_theme_id); @@ -187,6 +188,7 @@ static void sound_exit(void) { int ret; + sound_parser_exit(); sound_thememan_exit(); /* remove watch */ -- 2.7.4