sound: Fix multi-theme start index with 0 94/297594/1
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 17 Aug 2023 05:55:16 +0000 (14:55 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 21 Aug 2023 07:45:23 +0000 (16:45 +0900)
In the previous multi-theme support implementation,
default index was different according to multi-theme or single theme.
However default sound theme index should start with 0 to maintain consistency.
User should use index "1~N", and that index will be converted to 0~N-1 in intenral implementation.
Start index will be 0 in terms of implementation.

Change-Id: I8549d2039c399e875ace7c06303bb4d1fd10febb
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
common/data/sound.conf
include/feedback-internal.h
src/sound.c

index 5e896b3..4f4c93c 100644 (file)
 #     The N number range=1~N
 # [SoundThemeN]
 # - This section determines that the file is defined as the Nth theme.
+#   The N number range=1~N
 #  file_path_of_theme=string
 #   - Defines the path of the corresponding number file.
 #     In this file, [Sound] section and new patterns, new files should be defined.
 #
+# When you use SoundMultiTheme, You should follow the accurate range of number according to above description.
+# If you do not follow above description, the conf file parsing will be fail.
+#
 # Example
 # [SoundMultiTheme]
 # number_of_theme=2
index 559196e..c7b03da 100755 (executable)
@@ -192,6 +192,8 @@ int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigned in
 /**
  * @brief Sets the current index of theme.
  * @details This function sets the index of theme.
+ *          The range of theme index will be 1~N according to conf file.
+ *          Please put the accurate index_of_theme value.
  * @since_tizen 8.0
  * @param[in] type The feedback type
  * @param[in] index_of_theme The index of theme will be selected
index 450b727..d5e2a8d 100644 (file)
@@ -133,6 +133,7 @@ static int feedback_parse_sound_multi_theme_section(const struct parse_result *r
                        sscanf(extracted_section_prop->value, "%d", &number_of_theme);
                } else if (MATCH("name_of_default_theme", extracted_section_prop->key)) {
                        sscanf(extracted_section_prop->value, "SoundTheme%d", &current_theme_index);
+                       current_theme_index--;
                } else {
                        _E("Failed to parse SoundMultiTheme section. Please check your config file, \
                                check the value or typo of key value");
@@ -140,7 +141,7 @@ static int feedback_parse_sound_multi_theme_section(const struct parse_result *r
                }
        }
 
-       if (number_of_theme < current_theme_index) {
+       if (number_of_theme <= current_theme_index) {
                _E("Failed to parse SoundMultiTheme section. Please check your config file, \
                        default theme number cannot be greater then the number of theme");
                return -EINVAL;
@@ -183,12 +184,19 @@ static int feedback_parse_multi_theme_conf_path_section(const struct parse_resul
        if (ret == EOF)
                return 0;
 
-       if (multi_theme_index < 0 || multi_theme_index > number_of_theme)
-               return 0;
+       if (multi_theme_index <= 0) {
+               _E("Failed to parse SoundThemeN section, you should check range of SoundThemeN(1~N)");
+               return -EINVAL;
+       }
+
+       if (multi_theme_index > number_of_theme) {
+               _E("Failed to parse SoundThemeN section, you cannot put N value over number_of_theme value");
+               return -EINVAL;
+       }
 
        SYS_G_LIST_FOREACH(result->props, temp_glist, extracted_section_prop) {
                if (MATCH("file_path_of_theme", extracted_section_prop->key)) {
-                       feedback_load_config(extracted_section_prop->value, &sound_info[multi_theme_index]);
+                       feedback_load_config(extracted_section_prop->value, &sound_info[multi_theme_index-1]);
                } else {
                        _E("Failed to parse SoundThemeN section, Please check your config file, \
                                check the value or typo of key value");
@@ -216,14 +224,16 @@ static int sound_get_config(void)
        bool is_support_multi_theme = false;
 
        is_support_multi_theme = feedback_is_multi_theme_support(SOUND_CONF_FILE);
+       if (!is_support_multi_theme)
+               number_of_theme++;
 
-       sound_info = (struct feedback_config_info*)calloc(number_of_theme+1, sizeof(struct feedback_config_info));
+       sound_info = (struct feedback_config_info*)calloc(number_of_theme, sizeof(struct feedback_config_info));
        if (!sound_info) {
                _E("Failed to allocate memory for sound_info.");
                return -ENOMEM;
        }
 
-       for (int i = 0; i <= number_of_theme; i++)
+       for (int i = 0; i < number_of_theme; i++)
                sound_info[i].name = SOUND_NAME;
 
        if (is_support_multi_theme) {
@@ -240,6 +250,9 @@ static void sound_init(void)
 {
        int ret = 0;
 
+       number_of_theme = 0;
+       current_theme_index = 0;
+
        ret = sound_get_config();
        if (ret < 0)
                _W("Failed to load configuration file(%s): %d", SOUND_CONF_FILE, ret);
@@ -274,7 +287,7 @@ static void sound_put_config(void)
                return;
 
        /* free sound data */
-       for (int i = 0; i <= number_of_theme; i++) {
+       for (int i = 0; i < number_of_theme; i++) {
                feedback_free_config(&sound_info[i]);
        }
        sound_info = NULL;
@@ -595,20 +608,17 @@ static int sound_get_theme_index(unsigned int *index_of_theme)
        if (!index_of_theme)
                return -EINVAL;
 
-       *index_of_theme = current_theme_index;
+       *index_of_theme = current_theme_index + 1;
 
        return 0;
 }
 
 static int sound_set_theme_index(unsigned int index_of_theme)
 {
-       if (index_of_theme > number_of_theme)
-               return -EINVAL;
-
-       if (number_of_theme > 0 && index_of_theme == 0)
+       if (index_of_theme > number_of_theme || index_of_theme <= 0)
                return -EINVAL;
 
-       current_theme_index = index_of_theme;
+       current_theme_index = index_of_theme - 1;
 
        return 0;
 }