TizenRefApp-6886 [Call UI] Fix issue in misbehavior with turning on and off display... 91/83491/2
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 11 Aug 2016 07:45:17 +0000 (10:45 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 11 Aug 2016 08:54:53 +0000 (11:54 +0300)
Change-Id: Ifeee74ff16c4dae4a6f1ea2eebe59d09ce1ef124

src/callui-common.c
src/callui-proximity-lock-manager.c

index 75deea3..52f16d1 100755 (executable)
@@ -396,7 +396,7 @@ bool _callui_common_is_powerkey_ending_call_mode_on(void)
        int powerkey_mode = 0;
        int ret = vconf_get_bool(VCONFKEY_CISSAPPL_POWER_KEY_ENDS_CALL_BOOL, &powerkey_mode);
        if (!ret) {
-               dbg("Powerkey ending call mode [%d]", powerkey_mode ? "ON":"OFF");
+               dbg("Powerkey ending call mode [%s]", powerkey_mode ? "ON":"OFF");
        } else {
                dbg("vconf_get_bool failed. res[%d]", ret);
        }
index e7138ff..85d4a95 100644 (file)
 #include "callui-common.h"
 
 #define CALLUI_SENSOR_INTERVAL 100
+#define CALLUI_LCD_TURN_ON_DELAY_INTERVAL 0.1
 
 typedef enum {
-       CALLUI_PLM_LCD_NONE,
+       CALLUI_PLM_LCD_UNDEFINED,
        CALLUI_PLM_LCD_ON,
        CALLUI_PLM_LCD_OFF
-} proximity_lock_manager_state;
+} callui_plm_lcd_state_e;
+
+typedef enum {
+       CALLUI_PLM_STATE_UNDEFINED,
+       CALLUI_PLM_STATE_STARTED,
+       CALLUI_PLM_STATE_SUSPENDED,
+       CALLUI_PLM_STATE_STOPPED
+} callui_plm_run_state_e;
 
 typedef struct proximity_lock {
        sensor_h sensor;
        sensor_listener_h sensor_listener;
-       bool is_started;
-       proximity_lock_manager_state state;
+       callui_plm_lcd_state_e lcd_state;
+       callui_plm_run_state_e run_state;
        unlock_cb_t unlock_cb;
        void *cb_data;
-} proximity_lock_t;
+
+       Ecore_Timer *lcd_turn_on_timer;
+
+} _callui_proximity_lock_t;
 
 /**
  * @brief Create proximity lock manager
  *
  * @return The proximity lock handle as void pointer
  *
- * @see proximity_lock_t
+ * @see _callui_proximity_lock_t
  */
 static void *__callui_proximity_lock_manager_create();
 
@@ -52,7 +63,7 @@ static void *__callui_proximity_lock_manager_create();
  *
  * @param[in]   lock_h The proximity lock handle
  *
- * @see proximity_lock_t
+ * @see _callui_proximity_lock_t
  */
 static void __callui_proximity_lock_manager_start(void *lock_h);
 
@@ -62,7 +73,7 @@ static void __callui_proximity_lock_manager_start(void *lock_h);
  * @param[in]   lock_h The proximity lock handle
  * @param[in]   force  force stops when true, otherwise just stops
  *
- * @see proximity_lock_t
+ * @see _callui_proximity_lock_t
  */
 static void __callui_proximity_lock_manager_force_stop(void *lock_h, bool force);
 
@@ -71,7 +82,7 @@ static void __callui_proximity_lock_manager_force_stop(void *lock_h, bool force)
  *
  * @param[in]   lock_h The proximity lock handle
  *
- * @see proximity_lock_t
+ * @see _callui_proximity_lock_t
  */
 static void __callui_proximity_lock_manager_stop(void *lock_h);
 
@@ -82,7 +93,7 @@ static void __callui_proximity_lock_manager_stop(void *lock_h);
  *
  * @return true when proximity lock manager is started, otherwise false
  *
- * @see proximity_lock_t
+ * @see _callui_proximity_lock_t
  */
 static bool __callui_proximity_lock_manager_is_started(void *lock_h);
 
@@ -91,16 +102,19 @@ static bool __callui_proximity_lock_manager_is_started(void *lock_h);
  *
  * @param[in]   proximity_h The proximity lock handle
  *
- * @see proximity_lock_t
+ * @see _callui_proximity_lock_t
  */
 static void __callui_proximity_lock_manager_destroy(void *lock_h);
 static bool __callui_proximity_lock_manager_is_lcd_off(void *lock_h);
 static void __callui_proximity_lock_manager_set_callback_on_unlock(void *lock_h, unlock_cb_t callback, void *data);
 
-static int __callui_proximity_lock_manager_create_listener(proximity_lock_t *proximity_h);
+static int __callui_proximity_lock_manager_create_listener(_callui_proximity_lock_t *proximity_h);
 static void __callui_proximity_lock_manager_cb(sensor_h sensor, sensor_event_s *sensor_data, void *user_data);
 
-static int __callui_proximity_lock_manager_create_listener(proximity_lock_t *proximity_h)
+static void __callui_proximity_lock_manager_turn_lcd_on(_callui_proximity_lock_t *proximity_h);
+static Eina_Bool __callui_proximity_lock_manager_turn_lcd_on_timer_cb(void *data);
+
+static int __callui_proximity_lock_manager_create_listener(_callui_proximity_lock_t *proximity_h)
 {
        dbg("..");
        int ret = SENSOR_ERROR_NONE;
@@ -115,30 +129,64 @@ static int __callui_proximity_lock_manager_create_listener(proximity_lock_t *pro
        return ret;
 }
 
+static void __callui_proximity_lock_manager_turn_lcd_on(_callui_proximity_lock_t *proximity_h)
+{
+       callui_app_data_t *ad = _callui_get_app_data();
+
+       dbg("Turn display [ON]");
+       _callui_display_set_control_state(ad->display, CALLUI_DISPLAY_ON);
+       proximity_h->lcd_state = CALLUI_PLM_LCD_ON;
+
+       if (proximity_h->unlock_cb) {
+               proximity_h->unlock_cb(proximity_h->cb_data);
+               proximity_h->unlock_cb = NULL;
+               proximity_h->cb_data = NULL;
+       }
+}
+
+static Eina_Bool __callui_proximity_lock_manager_turn_lcd_on_timer_cb(void *data)
+{
+       _callui_proximity_lock_t *proximity_h = data;
+
+       __callui_proximity_lock_manager_turn_lcd_on(proximity_h);
+       proximity_h->lcd_turn_on_timer = NULL;
+
+       return ECORE_CALLBACK_DONE;
+}
+
 static void __callui_proximity_lock_manager_cb(sensor_h sensor, sensor_event_s *sensor_data, void *user_data)
 {
        CALLUI_RETURN_IF_FAIL(user_data);
-       proximity_lock_t *proximity_h = user_data;
        CALLUI_RETURN_IF_FAIL(sensor_data);
+
+       _callui_proximity_lock_t *proximity_h = user_data;
+       if (proximity_h->run_state == CALLUI_PLM_STATE_STOPPED) {
+               dbg("Ignored. Proximity Lock Manager is stopped.");
+               return;
+       }
+
        float value = sensor_data->values[0];
-       dbg("changed proximity sensor value = %f", value);
+       dbg("Proximity sensor value [%.1f]. Sensor state [%s]", value, (value > 0) ? "OPENED" : "CLOSED");
        callui_app_data_t *ad = _callui_get_app_data();
 
        if (value > 0) {
-               if (proximity_h->state == CALLUI_PLM_LCD_OFF) {
-                       dbg("proximity state: LCD is off");
-                       _callui_display_set_control_state(ad->display, CALLUI_DISPLAY_ON);
-                       proximity_h->state = CALLUI_PLM_LCD_ON;
-                       if (proximity_h->unlock_cb) {
-                               proximity_h->unlock_cb(proximity_h->cb_data);
-                               proximity_h->unlock_cb = NULL;
-                               proximity_h->cb_data = NULL;
-                       }
+               if (proximity_h->lcd_state == CALLUI_PLM_LCD_OFF) {
+                       dbg("Make request on turn display [ON] with delay");
+                       DELETE_ECORE_TIMER(proximity_h->lcd_turn_on_timer);
+                       proximity_h->lcd_turn_on_timer = ecore_timer_add(CALLUI_LCD_TURN_ON_DELAY_INTERVAL, __callui_proximity_lock_manager_turn_lcd_on_timer_cb, proximity_h);
                }
        } else {
                if (_callui_display_is_turned_on(ad->display)) {
-                       _callui_display_set_control_state(ad->display, CALLUI_DISPLAY_OFF);
-                       proximity_h->state = CALLUI_PLM_LCD_OFF;
+                       if (proximity_h->lcd_turn_on_timer) {
+                               dbg("Cancel request on turn display [ON] with delay");
+                               DELETE_ECORE_TIMER(proximity_h->lcd_turn_on_timer);
+                       } else {
+                               dbg("Turn display [OFF]");
+                               _callui_display_set_control_state(ad->display, CALLUI_DISPLAY_OFF);
+                               proximity_h->lcd_state = CALLUI_PLM_LCD_OFF;
+                       }
+               } else {
+                       dbg("Ignored. Display already turned off");
                }
        }
 }
@@ -146,10 +194,10 @@ static void __callui_proximity_lock_manager_cb(sensor_h sensor, sensor_event_s *
 static void *__callui_proximity_lock_manager_create()
 {
        dbg("..");
-       proximity_lock_t *proximity_h = calloc(1, sizeof(proximity_lock_t));
+       _callui_proximity_lock_t *proximity_h = calloc(1, sizeof(_callui_proximity_lock_t));
        CALLUI_RETURN_NULL_IF_FAIL(proximity_h);
-       proximity_h->is_started = false;
-       proximity_h->state = CALLUI_PLM_LCD_NONE;
+       proximity_h->run_state = CALLUI_PLM_STATE_UNDEFINED;
+       proximity_h->lcd_state = CALLUI_PLM_LCD_UNDEFINED;
        proximity_h->unlock_cb = NULL;
        proximity_h->cb_data = NULL;
 
@@ -173,25 +221,42 @@ static void __callui_proximity_lock_manager_start(void *lock_h)
 {
        dbg("..");
        CALLUI_RETURN_IF_FAIL(lock_h);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
-       int ret = sensor_listener_start(proximity_h->sensor_listener);
-       if (ret != SENSOR_ERROR_NONE) {
-               err("sensor_listener_start() failed(%d)", ret);
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
+
+       switch (proximity_h->run_state) {
+       case CALLUI_PLM_STATE_STARTED:
+               dbg("Already started");
+               return;
+       case CALLUI_PLM_STATE_SUSPENDED:
+               proximity_h->unlock_cb = NULL;
+               proximity_h->cb_data = NULL;
+               break;
+       default:
+       {
+               int ret = sensor_listener_start(proximity_h->sensor_listener);
+               if (ret != SENSOR_ERROR_NONE) {
+                       err("sensor_listener_start() failed. res[%d]", ret);
+               }
+               break;
        }
+       }
+
 #ifdef _DBUS_DISPLAY_DEVICE_TIMEOUT_
        callui_app_data_t *ad = _callui_get_app_data();
        _callui_display_set_timeout(ad->display, CALLUI_DISPLAY_TIMEOUT_SET);
 #endif
 
-       proximity_h->is_started = true;
+       proximity_h->run_state = CALLUI_PLM_STATE_STARTED;
+       proximity_h->lcd_state = _callui_display_is_turned_on(ad->display) ? CALLUI_PLM_LCD_ON : CALLUI_PLM_LCD_OFF;
 }
 
 static void __callui_proximity_lock_manager_force_stop(void *lock_h, bool force)
 {
        dbg("..");
        CALLUI_RETURN_IF_FAIL(lock_h);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
        if (!force && __callui_proximity_lock_manager_is_lcd_off(proximity_h)) {
+               proximity_h->run_state = CALLUI_PLM_STATE_SUSPENDED;
                __callui_proximity_lock_manager_set_callback_on_unlock(proximity_h, __callui_proximity_lock_manager_stop, proximity_h);
        } else {
                __callui_proximity_lock_manager_stop(proximity_h);
@@ -202,28 +267,30 @@ static void __callui_proximity_lock_manager_stop(void *lock_h)
 {
        dbg("..");
        CALLUI_RETURN_IF_FAIL(lock_h);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
        int ret = sensor_listener_stop(proximity_h->sensor_listener);
        if (ret != SENSOR_ERROR_NONE) {
                err("sensor_listener_stop() failed(%d)", ret);
        }
-       proximity_h->is_started = false;
-       proximity_h->state = CALLUI_PLM_LCD_NONE;
+       proximity_h->run_state = CALLUI_PLM_STATE_STOPPED;
+       proximity_h->lcd_state = CALLUI_PLM_LCD_UNDEFINED;
 }
 
 static bool __callui_proximity_lock_manager_is_started(void *lock_h)
 {
        dbg("..");
        CALLUI_RETURN_VALUE_IF_FAIL(lock_h, false);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
-       return proximity_h->is_started;
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
+       return (proximity_h->run_state == CALLUI_PLM_STATE_STARTED);
 }
 
 static void __callui_proximity_lock_manager_destroy(void *lock_h)
 {
        dbg("..");
        CALLUI_RETURN_IF_FAIL(lock_h);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
+
+       DELETE_ECORE_TIMER(proximity_h->lcd_turn_on_timer);
        sensor_listener_unset_event_cb(proximity_h->sensor_listener);
        sensor_destroy_listener(proximity_h->sensor_listener);
        free(proximity_h);
@@ -233,15 +300,15 @@ static bool __callui_proximity_lock_manager_is_lcd_off(void *lock_h)
 {
        dbg("..");
        CALLUI_RETURN_VALUE_IF_FAIL(lock_h, false);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
-       return (proximity_h->state == CALLUI_PLM_LCD_OFF);
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
+       return (proximity_h->lcd_state == CALLUI_PLM_LCD_OFF);
 }
 
 static void __callui_proximity_lock_manager_set_callback_on_unlock(void *lock_h, unlock_cb_t callback, void *data)
 {
        dbg("..");
        CALLUI_RETURN_IF_FAIL(lock_h || callback || data);
-       proximity_lock_t *proximity_h = (proximity_lock_t *)lock_h;
+       _callui_proximity_lock_t *proximity_h = (_callui_proximity_lock_t *)lock_h;
        proximity_h->unlock_cb = callback;
        proximity_h->cb_data = data;
 }