Cache has_conformant info for preventing app crash 28/108628/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 5 Jan 2017 07:57:40 +0000 (16:57 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Thu, 5 Jan 2017 07:57:44 +0000 (16:57 +0900)
ecore_wl_window_conformant_get() invokes ecore_wl_sync(),
and when this function gets called inside class destructor,
sometimes causes abort() when no connection is available.
Need to enhance this piece of code, to check if there is a
valid wl connection available before querying conformant info.

Change-Id: Iefec96095eaca1e2faa99b3c7186ce2a98808a10

ism/extras/wayland_immodule/wayland_imcontext.c

index 907f6f4..3493726 100644 (file)
@@ -213,6 +213,8 @@ struct _WaylandIMContext
     Eina_List *keysym_list;
 
     uint32_t reset_serial;
+
+    Eina_Bool has_conformant;
     //
 };
 
@@ -865,20 +867,23 @@ static Eina_Rectangle _conformant_area_backup = { 0, 0, 0, 0 };
 static Eina_Bool reset_conformant_area(Ecore_IMF_Context *ctx)
 {
     Eina_Bool reset = EINA_FALSE;
+    Eina_Bool has_conformant = EINA_FALSE;
     Ecore_Wl_Window *window = NULL;
 
     if (!ctx) return EINA_FALSE;
 
     WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
-    if (imcontext) window = imcontext->window;
+    if (imcontext) {
+        window = imcontext->window;
+        has_conformant = imcontext->has_conformant;
+    }
 
     if (window) {
         int x = 0, y = 0, w = 0, h = 0;
         Eina_Bool result = ecore_wl_window_keyboard_geometry_get(window, &x, &y, &w, &h);
 
         if (result) {
-            if (ecore_imf_context_client_canvas_get(ctx) && ecore_wl_window_conformant_get(window) &&
-                (w != 0 || h != 0)) {
+            if (ecore_imf_context_client_canvas_get(ctx) && has_conformant && (w != 0 || h != 0)) {
                 reset = EINA_TRUE;
                 _conformant_area_backup.x = x;
                 _conformant_area_backup.y = y;
@@ -907,20 +912,23 @@ static Eina_Bool reset_conformant_area(Ecore_IMF_Context *ctx)
 static void restore_conformant_area(Ecore_IMF_Context *ctx)
 {
     Eina_Bool restore = EINA_FALSE;
+    Eina_Bool has_conformant = EINA_FALSE;
     Ecore_Wl_Window *window = NULL;
 
     if (!ctx) return;
 
     WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
-    if (imcontext) window = imcontext->window;
+    if (imcontext) {
+        window = imcontext->window;
+        has_conformant = imcontext->has_conformant;
+    }
 
     if (window) {
         int x = 0, y = 0, w = 0, h = 0;
         Eina_Bool result = ecore_wl_window_keyboard_geometry_get(window, &x, &y, &w, &h);
 
         if (result) {
-            if (ecore_imf_context_client_canvas_get(ctx) && ecore_wl_window_conformant_get(window) &&
-                (w == 0 || h == 0)) {
+            if (ecore_imf_context_client_canvas_get(ctx) && has_conformant && (w == 0 || h == 0)) {
                 restore = EINA_TRUE;
             }
         }
@@ -1306,6 +1314,7 @@ static Eina_Bool _client_window_focus_out_cb(void *data, int ev_type, void *ev)
 static void send_will_hide_ack(Ecore_IMF_Context *ctx)
 {
     Eina_Bool need_temporary_context = EINA_FALSE;
+    Eina_Bool has_conformant = EINA_FALSE;
     WaylandIMContext *imcontext = NULL;
 
     if (!ctx) {
@@ -1316,6 +1325,8 @@ static void send_will_hide_ack(Ecore_IMF_Context *ctx)
         if (!imcontext) {
             LOGD("imcontext is NULL :%p\n", ctx);
             need_temporary_context = EINA_TRUE;
+        } else {
+            has_conformant = imcontext->has_conformant;
         }
     }
 
@@ -1332,7 +1343,7 @@ static void send_will_hide_ack(Ecore_IMF_Context *ctx)
     }
 
     if (ctx && imcontext) {
-        if (ecore_imf_context_client_canvas_get(ctx) && ecore_wl_window_conformant_get(imcontext->window)) {
+        if (ecore_imf_context_client_canvas_get(ctx) && has_conformant) {
             if (_conformant_reset_done && _received_will_hide_event) {
                 LOGD("Send will hide ack, _conformant_reset_done = 1, received_will_hide_event = 1\n");
                 _send_will_hide_ack(imcontext);
@@ -1344,7 +1355,7 @@ static void send_will_hide_ack(Ecore_IMF_Context *ctx)
             }
         } else {
             LOGD("Send will hide ack right away, since there is no conformant available : %p %d\n",
-                ecore_imf_context_client_canvas_get(ctx), ecore_wl_window_conformant_get(imcontext->window));
+                ecore_imf_context_client_canvas_get(ctx), has_conformant);
             _send_will_hide_ack (imcontext);
         }
     }
@@ -1546,8 +1557,12 @@ show_input_panel(Ecore_IMF_Context *ctx)
     _input_panel_ctx = ctx;
     _active_context_canvas = ecore_imf_context_client_canvas_get(ctx);
 
-    if (imcontext->window)
+    if (imcontext->window) {
         _active_context_window_id = ecore_wl_window_id_get(imcontext->window);
+        imcontext->has_conformant = ecore_wl_window_conformant_get(imcontext->window);
+    } else {
+        imcontext->has_conformant = EINA_FALSE;
+    }
     //
 
     // TIZEN_ONLY(20150715): Support input_panel_state_get