Fix coverity issue 1149129
[apps/native/volume-app.git] / src / control.c
index e7bb9c2..ec9c102 100755 (executable)
@@ -37,7 +37,7 @@
 
 #define VCONF_KEY_FMRADIO_RECORDING "memory/private/Sound/FMRadioRecording"
 
-struct _control_s_info{
+struct _control_s_info {
        Eina_Bool is_deleting;
        Eina_Bool is_launching;
        Eina_Bool is_new;
@@ -64,7 +64,7 @@ static struct _control_s_info control_info = {
 
        .current_angle = 0,
        .viewport_width = 0,
-       .viewport_height= 0,
+       .viewport_height = 0,
        .time_for_safety_limit = 0,
 
        .sound_type_at_show = SOUND_TYPE_RINGTONE,
@@ -150,7 +150,7 @@ Eina_Bool volume_control_get_time_for_safety_limit(void)
 
 Eina_Bool volume_control_viewport_is_warning_visible(void)
 {
-    return control_info.is_warning_visible;
+       return control_info.is_warning_visible;
 }
 
 volume_error_e volume_control_cache_flush(void)
@@ -205,16 +205,14 @@ volume_error_e volume_control_app_launch_with_bundle(const char *op_type, const
        }
 
        ret = app_control_set_app_id(app_control, pkgname);
-       if (ret != 0)
-       {
+       if (ret != 0) {
                _E("Failed to set appid");
                app_control_destroy(app_control);
                return VOLUME_ERROR_FAIL;
        }
 
        ret = app_control_add_extra_data(app_control, op_type, operation);
-       if (ret != 0)
-       {
+       if (ret != 0) {
                _E("Failed to add extra data");
                app_control_destroy(app_control);
                return VOLUME_ERROR_FAIL;
@@ -234,16 +232,14 @@ int volume_control_get_vconf_idlelock(void)
        int pm_state = VCONFKEY_PM_STATE_NORMAL;
 
        /* Check Idle-Lock */
-       if(vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock) < 0)
-       {
+       if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock) < 0) {
                _E("Failed to get vconfkey : VCONFKEY_IDLE_LOCK_STATE");
                return IDLELOCK_ERROR;
        }
        _D("idlelock vconf : %d", lock);
 
        /* Check PM state */
-       if(vconf_get_int(VCONFKEY_PM_STATE, &pm_state) < 0)
-       {
+       if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) < 0) {
                _E("Failed to get vconfkey : VCONFKEY_PM_STATE");
                return IDLELOCK_ERROR;
        }
@@ -262,16 +258,13 @@ int volume_control_check_status(int *lock, sound_type_e *sound_type)
 
        _D("lock : %d / sound_type : %d", *lock, *sound_type);
 
-       if (*lock == IDLELOCK_ON)
-       {
-               if (*sound_type == SOUND_TYPE_RINGTONE)
-               {
+       if (*lock == IDLELOCK_ON) {
+               if (*sound_type == SOUND_TYPE_RINGTONE) {
                        _D("IDLELOCK is ON / sound type is Ringtone");
                        return LOCK_AND_NOT_MEDIA;
                }
 
-               if (*sound_type != SOUND_TYPE_RINGTONE)
-               {
+               if (*sound_type != SOUND_TYPE_RINGTONE) {
                        _D("IDLELOCK is ON / sound type is not Ringtone(media or alaram)");
                        return LOCK_AND_MEDIA;
                }
@@ -310,13 +303,11 @@ Eina_Bool volume_control_show_view(int status, sound_type_e sound_type, int soun
        if (status == LOCK_AND_NOT_MEDIA) {
                _D("Lock and Not Media");
                if (evas_object_visible_get(win)) {
-                       if (VOLUME_ERROR_OK != volume_control_hide_view()) {
+                       if (VOLUME_ERROR_OK != volume_control_hide_view())
                                _E("Failed to close volume");
-                       }
 
-                       if (VOLUME_ERROR_OK != volume_control_cache_flush()) {
+                       if (VOLUME_ERROR_OK != volume_control_cache_flush())
                                _E("Failed to flush cache");
-                       }
                }
                return EINA_FALSE;
        } else {
@@ -324,32 +315,30 @@ Eina_Bool volume_control_show_view(int status, sound_type_e sound_type, int soun
                        _D("LOCK_AND_MEDIA");
                } else {
                        _D("UNLOCK");
-                       if (VOLUME_ERROR_OK != volume_view_change_slider_by_type(sound_type, bt_opened, earphone_connected)) {
+                       if (VOLUME_ERROR_OK != volume_view_change_slider_by_type(sound_type, bt_opened, earphone_connected))
                                _E("Failed to changed max volume");
-                       }
 
-                       if(VOLUME_ERROR_OK != volume_view_window_show(sound_type)) {
+                       if (VOLUME_ERROR_OK != volume_view_window_show(sound_type))
                                _E("Failed to show volume window");
-                       }
+
                        ecore_timer_add(0.1f, _volume_region_set_timer_cb, win);
 
                        control_info.is_launching = EINA_TRUE;
 
-                       if (bt_opened == 1 && sound_type == SOUND_TYPE_CALL) {
+                       if (bt_opened == 1 && sound_type == SOUND_TYPE_CALL)
                                volume = bt_get_bt_volume();
-                       } else {        
+                       else {
                                volume = volume_sound_sound_manager_volume_get(sound_type);
                                _D("volume value: %d", volume);
                                vibration = volume_sound_vconf_status_get(TYPE_VCONF_VIBRATION_STATUS);
                                _D("vibration : %d", vibration);
 
-                               if(sound == 0 && sound_type == SOUND_TYPE_RINGTONE) {
+                               if ((vibration == 1 && sound == 0) && sound_type == SOUND_TYPE_RINGTONE)
                                        volume = 0;
-                               }
 
-                               if(VOLUME_ERROR_OK != volume_view_slider_value_set(volume)) {
+                               if (VOLUME_ERROR_OK != volume_view_slider_value_set(volume))
                                        _E("Failed to set volume value to slider");
-                               }
+
                                volume_view_volume_icon_set(sound_type, sound, vibration, bt_opened);
                                volume_view_volume_icon_name_set_for_access(sound_type);
                        }
@@ -368,9 +357,8 @@ volume_error_e volume_control_close_bt_display(void)
        control_info.is_deleting = EINA_TRUE;
 
        /* hide window */
-       if (VOLUME_ERROR_OK != volume_view_window_hide()) {
+       if (VOLUME_ERROR_OK != volume_view_window_hide())
                _E("Failed to hide window");
-       }
 
        control_info.is_deleting = EINA_FALSE;
 
@@ -395,9 +383,8 @@ volume_error_e volume_control_hide_view(void)
        volume_timer_del(TYPE_TIMER_WARNING_POPUP);
 
        /* hide window */
-       if (VOLUME_ERROR_OK != volume_view_window_hide()) {
+       if (VOLUME_ERROR_OK != volume_view_window_hide())
                _E("Failed to hide window");
-       }
 
        control_info.is_deleting = EINA_FALSE;
        control_info.is_launching = EINA_FALSE;
@@ -410,31 +397,26 @@ volume_error_e volume_control_hide_view(void)
 void volume_control_register_vconfkey(void)
 {
        /* other app grab volume key => close volume */
-       if (vconf_notify_key_changed(VCONFKEY_STARTER_USE_VOLUME_KEY, _starter_user_volume_key_vconf_changed_cb, NULL) != 0) {
+       if (vconf_notify_key_changed(VCONFKEY_STARTER_USE_VOLUME_KEY, _starter_user_volume_key_vconf_changed_cb, NULL) != 0)
                _E("Failed to register callback function : VCONFKEY_STARTER_USE_VOLUME_KEY");
-       }
 
        /* Lock screen status vconf changed callback */
-       if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, _idle_lock_state_vconf_changed_cb, NULL) != 0) {
+       if (vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, _idle_lock_state_vconf_changed_cb, NULL) != 0)
                _E("Failed to notify vconfkey : VCONFKEY_IDLE_LOCK_STATE");
-       }
 
-       if (vconf_notify_key_changed(VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb, NULL) != 0) {
+       if (vconf_notify_key_changed(VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb, NULL) != 0)
                _E("Failed to notify vconfkey : VCONFKEY_PM_LCDOFF_SOURCE");
-       }
 }
 
 void volume_control_unregister_vconfkey(void)
 {
        /* other app grab volume key => close volume */
-       if (vconf_ignore_key_changed(VCONFKEY_STARTER_USE_VOLUME_KEY, _starter_user_volume_key_vconf_changed_cb) < 0) {
+       if (vconf_ignore_key_changed(VCONFKEY_STARTER_USE_VOLUME_KEY, _starter_user_volume_key_vconf_changed_cb) < 0)
                _E("Failed to ignore vconfkey : VCONFKEY_STARTER_USE_VOLUME_KEY");
-       }
 
        /* Lock screen status vconf changed callback */
-       if (vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, _idle_lock_state_vconf_changed_cb) < 0) {
+       if (vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, _idle_lock_state_vconf_changed_cb) < 0)
                _E("Failed to ignore vconfkey : VCONFKEY_IDLE_LOCK_STATE");
-       }
 
        if (vconf_ignore_key_changed
                (VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb) != 0) {
@@ -448,13 +430,11 @@ volume_error_e volume_control_pause(void)
        retv_if(!win, VOLUME_ERROR_FAIL);
 
        if (evas_object_visible_get(win)) {
-               if(VOLUME_ERROR_OK != volume_control_hide_view()) {
+               if (VOLUME_ERROR_OK != volume_control_hide_view())
                        _E("Failed to close volume");
-               }
 
-               if (VOLUME_ERROR_OK != volume_control_cache_flush()) {
+               if (VOLUME_ERROR_OK != volume_control_cache_flush())
                        _E("Failed to flush cache");
-               }
        }
 
        return VOLUME_ERROR_OK;
@@ -486,9 +466,9 @@ volume_error_e volume_control_reset(bundle *b)
        _D("sound status : %d", sound);
 
        error = bt_ag_is_sco_opened(&bt_opened);
-       if (error != BT_ERROR_NONE) {
+       if (error != BT_ERROR_NONE)
                _E("bt_ag_is_sco_opened return [%d]", error);
-       }
+
        earphone_connected = earphone_get_earphone_is_connected();
        _D("BT state %d, Earphone state: %d", bt_opened, earphone_connected);
 
@@ -516,7 +496,7 @@ volume_error_e volume_control_initialize(void)
        retv_if(!win, VOLUME_ERROR_FAIL);
 
        /* Create volume layout */
-       if(VOLUME_ERROR_OK != volume_view_layout_create(win)) {
+       if (VOLUME_ERROR_OK != volume_view_layout_create(win)) {
                _E("Failed to create volume layout");
                return VOLUME_ERROR_FAIL;
        }
@@ -578,7 +558,7 @@ static void _volume_service_region_set(Evas_Object *win, Evas_Object *warning_po
        tzsh_region_h rect = NULL;
        int ret = 0;
 
-       int x, y, w ,h;
+       int x, y, wh;
        int tmp_x;
        int tmp_y;
        int tmp_w;
@@ -612,8 +592,7 @@ static void _volume_service_region_set(Evas_Object *win, Evas_Object *warning_po
                        y = tmp_x;
                        w = tmp_h;
                        h = tmp_w;
-               }
-               else if (current_angle == 270) {
+               } else if (current_angle == 270) {
                        tmp_x = x;
                        tmp_y = y;
                        tmp_w = w;
@@ -650,16 +629,16 @@ static void _rotate_changed_cb(void *data, Evas_Object *obj, void *event_info)
        ret_if(!ly_outer);
 
        _D("window rotated [%d] => [%d]", current_angle, changed_angle);
-       if(current_angle != changed_angle) {
+       if (current_angle != changed_angle) {
                current_angle = changed_angle;
                control_info.current_angle = current_angle;
-               switch(current_angle){
-               case 90 :
-               case 270 :
+               switch (current_angle) {
+               case 90:
+               case 270:
                        _D("show,landscape");
                        elm_object_signal_emit(ly_outer, "show,landscape", "bg");
                        break;
-               default :
+               default:
                        _D("show,portrait");
                        elm_object_signal_emit(ly_outer, "show,portrait", "bg");
                        break;
@@ -690,31 +669,27 @@ static void _starter_user_volume_key_vconf_changed_cb(keynode_t *key, void *data
 {
        int ret = EINA_FALSE;
 
-       if(vconf_get_int(VCONFKEY_STARTER_USE_VOLUME_KEY, &ret) < 0)
-       {
+       if (vconf_get_int(VCONFKEY_STARTER_USE_VOLUME_KEY, &ret) < 0) {
                _E("Failed to get vconfkey : VCONFKEY_STARTER_USE_VOLUME_KEY");
                return;
        }
        _D("ret : %d", ret);
 
-       if(ret == 1)
-       {
+       if (ret == 1) {
                _D("any other App grab volume hard key");
-               if(VOLUME_ERROR_OK != volume_control_hide_view()) {
+               if (VOLUME_ERROR_OK != volume_control_hide_view()) {
                        _E("Failed to close volume");
                        return;
                }
-               if(VOLUME_ERROR_OK != volume_control_cache_flush()) {
+               if (VOLUME_ERROR_OK != volume_control_cache_flush()) {
                        _E("Failed to flush cache");
                        return;
                }
-               if(vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 0) < 0) {
+               if (vconf_set_int(VCONFKEY_STARTER_USE_VOLUME_KEY, 0) < 0) {
                        _E("Failed to get vconfkey : VCONFKEY_STATER_USE_VOLUME_KEY");
                        return;
                }
-       }
-       else if(ret == 2)
-       {
+       } else if (ret == 2) {
                _D("setting App grab volume hard key");
        }
 }
@@ -723,35 +698,26 @@ static void _idle_lock_state_vconf_changed_cb(keynode_t *key, void *data)
 {
        int lock = VCONFKEY_IDLE_UNLOCK;
 
-       if(vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock) < 0)
-       {
+       if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock) < 0) {
                _E("Failed to get vconfkey : VCONFKEY_IDLE_LOCK_STATE");
                return;
        }
        _D("idle lock state : %d", lock);
 
-       if(lock == VCONFKEY_IDLE_LAUNCHING_LOCK)
-       {
-               if(VOLUME_ERROR_OK != volume_view_window_hide())
-               {
+       if (lock == VCONFKEY_IDLE_LAUNCHING_LOCK) {
+               if (VOLUME_ERROR_OK != volume_view_window_hide())
                        _E("Failed to hide window");
-               }
        }
 }
 
 static void _notify_pm_lcdoff_cb(keynode_t * node, void *data)
 {
-       if (volume_view_warning_popup_get()) {
+       if (volume_view_warning_popup_get())
                volume_view_destroy_warning_popup();
-       }
 
-       if(VOLUME_ERROR_OK != volume_control_hide_view())
-       {
+       if (VOLUME_ERROR_OK != volume_control_hide_view())
                _E("Failed to close volume");
-       }
 
-       if(VOLUME_ERROR_OK != volume_control_cache_flush())
-       {
+       if (VOLUME_ERROR_OK != volume_control_cache_flush())
                _E("Failed to flush cache");
-       }
 }