From 316bd6d66a862d3a3d2da50071c7db09b2ac0ef0 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 21 Sep 2017 20:23:40 +0900 Subject: [PATCH] Restart ISE if it crashes before connecting to the panel Change-Id: I8939c4c06127993c1e44537f96f88972937faa85 --- ism/extras/efl_panel/isf_panel_efl.cpp | 76 +++++++++++++++++++++++++++++++--- ism/src/isf_info_manager.cpp | 32 ++++++++++++++ 2 files changed, 102 insertions(+), 6 deletions(-) diff --git a/ism/extras/efl_panel/isf_panel_efl.cpp b/ism/extras/efl_panel/isf_panel_efl.cpp index feb9428..90ebd28 100644 --- a/ism/extras/efl_panel/isf_panel_efl.cpp +++ b/ism/extras/efl_panel/isf_panel_efl.cpp @@ -248,6 +248,7 @@ static void slot_accept_connection (int fd); static void slot_close_connection (int fd); static void slot_exit (void); +static void slot_register_helper (int id, const HelperInfo& info); static void slot_register_helper_properties (int id, const PropertyList &props); static void slot_show_ise (void); static void slot_hide_ise (void); @@ -285,7 +286,7 @@ static void create_notification (NotificationData *noti_d static void show_ime_selector_notification (void); #endif static void set_language_and_locale (const char *lang_str); -static void app_control_launch (const char *app_id); +static bool app_control_launch (const char *app_id); ///////////////////////////////////////////////////////////////////////////// // Declaration of internal variables. @@ -512,6 +513,10 @@ static Ecore_Event_Handler *_candidate_show_handler = NULL; static String ime_selector_app = ""; static String ime_list_app = ""; +static Ecore_Timer *_ise_check_pid_alive_timer = NULL; +static const double _ise_check_pid_alive_time = 1.0f; +static String _ise_check_pid_alive_uuid; + enum { EMOJI_IMAGE_WIDTH = 0, EMOJI_IMAGE_HEIGHT, @@ -4264,6 +4269,7 @@ static bool initialize_panel_agent (const ConfigPointer& config, const String &d _info_manager->signal_connect_close_connection (slot (slot_close_connection)); _info_manager->signal_connect_exit (slot (slot_exit)); + _info_manager->signal_connect_register_helper (slot(slot_register_helper)); _info_manager->signal_connect_register_helper_properties (slot (slot_register_helper_properties)); _info_manager->signal_connect_show_ise (slot (slot_show_ise)); _info_manager->signal_connect_hide_ise (slot (slot_hide_ise)); @@ -6100,6 +6106,49 @@ static void slot_exit (void) #endif /* CANDIDATE */ } +static void delete_ise_check_pid_alive_timer(void) +{ + LOGD("deleting ise_check_alive_timer\n"); + if (_ise_check_pid_alive_timer) { + ecore_timer_del(_ise_check_pid_alive_timer); + _ise_check_pid_alive_timer = NULL; + } +} + +static Eina_Bool ise_check_pid_alive_timer(void *data) +{ + Eina_Bool ret = ECORE_CALLBACK_RENEW; + int ime_pid = (int)data; + + int status = aul_app_get_status_bypid(ime_pid); + LOGD("STATUS : %d %d", status, ime_pid); + + /* If the status is not one of STATUS_LAUNCHING, STATUS_VISIBLE, STATUS_BG */ + if (status >= STATUS_DYING || status == -1) { + _soft_keyboard_launched = false; + + String uuid = _config->read(SCIM_CONFIG_DEFAULT_HELPER_ISE, String("")); + /* The start_helper() function below will going to call slot_run_helper, + which will going to assign a new timer handle to the _ise_check_pid_alive_timer variable. + */ + if (_info_manager->start_helper(uuid)) + _soft_keyboard_launched = true; + + ret = ECORE_CALLBACK_CANCEL; + } + + return ret; +} + +static void slot_register_helper(int id, const HelperInfo& info) +{ + LOGD (""); + /* Do we need to check whether the pid of this helper is the one we are watching? */ + if (info.uuid.compare(_ise_check_pid_alive_uuid) == 0) { + delete_ise_check_pid_alive_timer(); + } +} + static void slot_register_helper_properties (int id, const PropertyList &props) { SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n"; @@ -6392,7 +6441,7 @@ static void launch_helper (const char* exec, const char *name, const char *appid } } -static void app_control_launch (const char *app_id) +static bool app_control_launch (const char *app_id) { app_control_h app_control; int ret; @@ -6400,21 +6449,21 @@ static void app_control_launch (const char *app_id) ret = app_control_create (&app_control); if (ret != APP_CONTROL_ERROR_NONE) { LOGW ("app_control_create returned %08x\n", ret); - return; + return false; } ret = app_control_set_operation (app_control, APP_CONTROL_OPERATION_DEFAULT); if (ret != APP_CONTROL_ERROR_NONE) { LOGW ("app_control_set_operation returned %08x\n", ret); app_control_destroy (app_control); - return; + return false; } ret = app_control_set_app_id (app_control, app_id); if (ret != APP_CONTROL_ERROR_NONE) { LOGW ("app_control_set_app_id returned %08x\n", ret); app_control_destroy (app_control); - return; + return false; } int tries = 0; @@ -6431,6 +6480,8 @@ static void app_control_launch (const char *app_id) } else { LOGD ("Succeeded to launch IME (%s)\n", app_id); } + + return (ret == APP_CONTROL_ERROR_NONE); } static void slot_run_helper (const String &uuid, const String &config, const String &display) @@ -6442,6 +6493,8 @@ static void slot_run_helper (const String &uuid, const String &config, const Str String strDisplay = display; String scim_helper_path; + delete_ise_check_pid_alive_timer(); + #ifdef HAVE_PKGMGR_INFO char *execpath = NULL; int ret; @@ -6492,7 +6545,17 @@ static void slot_run_helper (const String &uuid, const String &config, const Str } /* execute type IME */ LOGD ("Try to launch IME (%s)\n", uuid.c_str ()); - app_control_launch (uuid.c_str ()); + bool launched = app_control_launch (uuid.c_str ()); + + if (launched) { + int ime_pid = aul_app_get_pid(uuid.c_str()); + if (ime_pid > 0) { + LOGD ("Register check_alive timer for pid : %d", ime_pid); + _ise_check_pid_alive_uuid = uuid; + _ise_check_pid_alive_timer = ecore_timer_add (_ise_check_pid_alive_time, + ise_check_pid_alive_timer, (void*)ime_pid); + } + } } else { /* shared object (so) type IME */ @@ -7802,6 +7865,7 @@ cleanup: pkgmgr = NULL; } #endif + delete_ise_check_pid_alive_timer(); #ifdef HAVE_TTS ui_close_tts (); diff --git a/ism/src/isf_info_manager.cpp b/ism/src/isf_info_manager.cpp index 01475f6..d7baf37 100644 --- a/ism/src/isf_info_manager.cpp +++ b/ism/src/isf_info_manager.cpp @@ -1005,6 +1005,18 @@ public: lock (); /*if (m_current_toolbar_mode != TOOLBAR_HELPER_MODE || m_current_helper_uuid.compare (uuid) != 0)*/ { SCIM_DEBUG_MAIN (1) << "Run_helper\n"; + + uint32 ic = get_helper_ic (m_panel_client_map[client], context); + String ic_uuid; + /* Get the context uuid from the client context registration table. */ + { + ClientContextUUIDRepository::iterator it = + m_client_context_uuids.find (get_helper_ic (m_panel_client_map[client], context)); + + if (it != m_client_context_uuids.end ()) + ic_uuid = it->second; + } + m_start_helper_ic_index [uuid].push_back (std::make_pair (ic, ic_uuid)); m_signal_run_helper (uuid, m_config_name, m_display_name); } m_current_helper_uuid = uuid; @@ -1034,6 +1046,9 @@ public: ISF_SAVE_LOG ("send SCIM_TRANS_CMD_EXIT message to %s\n", uuid.c_str ()); } + /* Since we are stopping this helper, erase information from start_helper_ic_index too */ + m_start_helper_ic_index.erase (uuid); + unlock (); return true; } @@ -2820,6 +2835,23 @@ public: if (restart_uuid != uuid || secs > MIN_REPEAT_TIME) { scim_usleep (100000); + + int client; + uint32 context; + get_focused_context(client, context); + + uint32 ic = get_helper_ic (client, context); + String ic_uuid; + /* Get the context uuid from the client context registration table. */ + { + ClientContextUUIDRepository::iterator it = + m_client_context_uuids.find (get_helper_ic (m_panel_client_map[client], context)); + + if (it != m_client_context_uuids.end ()) + ic_uuid = it->second; + } + + m_start_helper_ic_index[uuid].push_back(std::make_pair(ic, ic_uuid)); m_signal_run_helper (uuid, m_config_name, m_display_name); restart_uuid = uuid; LOGE ("Auto restart soft ISE:%s", uuid.c_str ()); -- 2.7.4