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", ¤t_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");
}
}
- 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;
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");
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) {
{
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);
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;
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;
}