Handle the exceptional case that /opt is not yet mounted 89/173589/3
authorInHong Han <inhong1.han@samsung.com>
Thu, 22 Mar 2018 10:25:19 +0000 (19:25 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 28 Mar 2018 23:30:13 +0000 (23:30 +0000)
This reverts commit ae7bb274e716bafbaaecf0dcde07ceecc58c3cc2.

Change-Id: I0556266f329576f9bb20a7f2d82a30a74359a33a

ism/extras/efl_panel/Makefile.am
ism/extras/efl_panel/isf_panel_efl.cpp
ism/src/isf_query_utility.cpp
ism/src/isf_query_utility.h
ism/src/scim_global_config.cpp
ism/src/scim_global_config.h
packaging/isf.spec

index b1186da..52f664c 100644 (file)
@@ -41,6 +41,7 @@ endif
 isf_panel_efl_CXXFLAGS = @ECOREX_CFLAGS@ \
                          @ECORE_WL_CFLAGS@ \
                          @ECORE_CFLAGS@ \
+                         @ECORE_FILE_CFLAGS@ \
                          @ECORE_IMF_CFLAGS@ \
                          @EINA_CFLAGS@ \
                          @VCONF_CFLAGS@ \
@@ -61,6 +62,7 @@ isf_panel_efl_LDFLAGS  = @LTLIBINTL@ -rpath $(libdir) \
                          @ECOREX_LIBS@ \
                          @ECORE_WL_LIBS@ \
                          @ECORE_LIBS@ \
+                         @ECORE_FILE_LIBS@ \
                          @ECORE_IMF_LIBS@ \
                          @EINA_LIBS@ \
                          @VCONF_LIBS@ \
index 8370a33..01798dd 100644 (file)
@@ -39,6 +39,7 @@
 #include <string.h>
 #include <Eina.h>
 #include <Ecore.h>
+#include <Ecore_File.h>
 #include <malloc.h>
 #include "scim_private.h"
 #include "scim.h"
@@ -522,6 +523,8 @@ static Ecore_Timer       *_ise_check_pid_alive_timer            = NULL;
 static const double      _ise_check_pid_alive_time              = 3.0f;
 static String            _ise_check_pid_alive_uuid;
 
+static Ecore_Timer       *g_monitor_user_data_path_timer = NULL;
+
 enum {
     EMOJI_IMAGE_WIDTH = 0,
     EMOJI_IMAGE_HEIGHT,
@@ -2124,7 +2127,89 @@ static bool set_active_ise (const String &uuid, bool launch_ise)
         }
     }
 
-    LOGW ("Failed to launch IME (%s)", uuid.c_str ());
+    LOGW ("Failed to launch IME (%s), %d", uuid.c_str (), _ime_info.size());
+
+    return false;
+}
+
+/**
+ * @brief Set temporary ISE.
+ *
+ * @param uuid The ISE's uuid.
+ *
+ * @return false if ISE change is failed, otherwise return true.
+ */
+static bool set_temporary_ise (const String &uuid)
+{
+    SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n";
+    LOGD ("set temporary ISE (%s)", uuid.c_str ());
+
+    if (uuid.length () <= 0)
+        return false;
+
+    bool ise_changed = false;
+
+    if (_ime_info.size () == 0) {
+#ifdef HAVE_PKGMGR_INFO
+        pkgmgrinfo_appinfo_filter_h handle;
+        int ret = pkgmgrinfo_appinfo_filter_create (&handle);
+        if (ret == PMINFO_R_OK) {
+            /* Add the package info for the IME that matches with our uuid only */
+            ret = pkgmgrinfo_appinfo_filter_add_string (handle, PMINFO_APPINFO_PROP_APP_ID, uuid.c_str ());
+            if (ret == PMINFO_R_OK)
+                ret = pkgmgrinfo_appinfo_filter_foreach_appinfo (handle, get_ime_app_list_cb, NULL);
+            else {
+                LOGE ("pkgmgrinfo_appinfo_filter_add_string failed(%d)", ret);
+            }
+            pkgmgrinfo_appinfo_filter_destroy (handle);
+        } else {
+            LOGE ("pkgmgrinfo_appinfo_filter_create failed(%d)", ret);
+        }
+#endif
+    }
+
+#ifdef HAVE_PKGMGR_INFO
+    pkgmgrinfo_appinfo_h handle = NULL;
+    int ret = pkgmgr_get_appinfo (uuid.c_str (), &handle);
+    if (ret != PMINFO_R_OK) {
+        LOGW ("appid \"%s\" is invalid.", uuid.c_str ());
+        return false;
+    }
+
+    if (handle) {
+        char *label = NULL;
+        ret = pkgmgrinfo_appinfo_get_label (handle, &label);
+        if (ret != PMINFO_R_OK) {
+            LOGW ("Could not get label for appid '%s'", uuid.c_str ());
+            pkgmgrinfo_appinfo_destroy_appinfo (handle);
+            return false;
+        }
+
+        ise_changed = set_helper_ise (uuid, true);
+
+        if (ise_changed) {
+            _info_manager->set_current_toolbar_mode (TOOLBAR_HELPER_MODE);
+            if (_TV)
+                _info_manager->set_current_helper_option (SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO |
+                    SCIM_HELPER_AUTO_RESTART | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT);
+            else
+                _info_manager->set_current_helper_option (SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO |
+                    SCIM_HELPER_AUTO_RESTART);
+            String label_string = label;
+            _info_manager->set_current_ise_name (label_string);
+
+#ifdef HAVE_VCONF
+            vconf_set_str (VCONFKEY_ISF_ACTIVE_KEYBOARD_UUID, uuid.c_str ());
+#endif
+        } else {
+            LOGW ("Failed to launch IME (%s)", uuid.c_str ());
+        }
+
+        pkgmgrinfo_appinfo_destroy_appinfo (handle);
+
+        return ise_changed;
+    }
+#endif
 
     return false;
 }
@@ -6552,7 +6637,7 @@ static void slot_run_helper (const String &uuid, const String &config, const Str
         return;
     }
 
-    LOGD ("exec path : %s", execpath);
+    LOGD ("exec path : %s %d", execpath, _ime_info.size ());
     scim_helper_path = String (execpath);
 
     if (appinfo_handle) {
@@ -7446,8 +7531,13 @@ static void launch_default_soft_keyboard (keynode_t *key, void* data)
 {
     SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n";
 
-    /* Start default ISE */
-    change_keyboard_mode (TOOLBAR_HELPER_MODE);
+    String helper_uuid = _config->read (SCIM_CONFIG_DEFAULT_HELPER_ISE, String(""));
+    if (helper_uuid.length () > 0) {
+        /* Start default ISE */
+        change_keyboard_mode (TOOLBAR_HELPER_MODE);
+    } else {
+        set_temporary_ise (_initial_ise_uuid);
+    }
 }
 
 static String sanitize_string (const char *str, int maxlen = 32)
@@ -7478,6 +7568,42 @@ static String sanitize_string (const char *str, int maxlen = 32)
     return ret;
 }
 
+static Eina_Bool monitor_user_data_path_timer(void *data)
+{
+    const char *path = static_cast<const char*>(data);
+    bool user_data_path_exists = ecore_file_exists (path);
+    bool user_data_path_is_dir = ecore_file_is_dir (path);
+    if (user_data_path_exists && user_data_path_is_dir) {
+        LOGW ("'%s' exists : %d, is_dir : %d", path,
+             (user_data_path_exists ? 1 : 0), (user_data_path_is_dir ? 1 : 0));
+
+        /* Flush config before reloading */
+        scim_global_config_flush ();
+        scim_global_config_reload ();
+
+        load_config ();
+
+        /* Read all ime info from db */
+        _ime_info.clear ();
+        isf_pkg_select_all_ime_info_db (_ime_info);
+
+        bool launch = true;
+        if (_info_manager->get_current_toolbar_mode () != TOOLBAR_HELPER_MODE) {
+            launch = false;
+        }
+        if (_launch_ise_on_request) {
+            launch = false;
+        }
+        String default_ise_uuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), _initial_ise_uuid);
+        set_active_ise (default_ise_uuid, launch);
+
+        g_monitor_user_data_path_timer = NULL;
+        return ECORE_CALLBACK_CANCEL;
+    }
+
+    return ECORE_CALLBACK_RENEW;
+}
+
 int main (int argc, char *argv [])
 {
     struct tms    tiks_buf;
@@ -7497,6 +7623,10 @@ int main (int argc, char *argv [])
     String        display_name    = String ();
     char          buf[256]        = {0};
 
+    String        user_data_path  = String ();
+    bool          user_data_path_exists = false;
+    bool          user_data_path_is_dir = false;
+
 #ifdef HAVE_ECOREX
     Ecore_Event_Handler *xclient_message_handler  = NULL;
     Ecore_Event_Handler *xwindow_property_handler = NULL;
@@ -7729,8 +7859,17 @@ int main (int argc, char *argv [])
 #endif /* CANDIDATE */
 
     /* Load ISF configuration */
-    load_config ();
-    check_time ("load_config");
+    user_data_path = scim_get_user_data_dir ();
+    user_data_path_exists = ecore_file_exists (user_data_path.c_str ());
+    user_data_path_is_dir = ecore_file_is_dir (user_data_path.c_str ());
+    if (user_data_path_exists && user_data_path_is_dir) {
+        load_config ();
+    } else {
+        LOGW ("'%s' exists : %d, is_dir : %d", user_data_path.c_str (),
+            (user_data_path_exists ? 1 : 0), (user_data_path_is_dir ? 1 : 0));
+        g_monitor_user_data_path_timer = ecore_timer_add (1.0, monitor_user_data_path_timer, user_data_path.c_str ());
+    }
+    check_time("load_config");
 
 #ifdef HAVE_VCONF
     char *lang_str;
@@ -7849,6 +7988,11 @@ int main (int argc, char *argv [])
     _config->flush ();
     ret = 0;
 
+    if (g_monitor_user_data_path_timer) {
+        ecore_timer_del (g_monitor_user_data_path_timer);
+        g_monitor_user_data_path_timer = NULL;
+    }
+
 #ifdef HAVE_BLUETOOTH
     /* deinitialize the callback function of Bluetooth connection */
     ret = bt_hid_host_deinitialize ();
index 7dcf859..21780d9 100644 (file)
@@ -227,6 +227,11 @@ static inline int _db_create_table(void)
 
 static inline int _db_init(void)
 {
+    if (!isf_db_check_path_available()) {
+        LOGE ("The db path is not available, returning");
+        return -EIO;
+    }
+
     struct stat stat;
     int ret = db_util_open(databaseInfo.pPath, &databaseInfo.pHandle, DB_UTIL_REGISTER_HOOK_METHOD);
     if (ret != SQLITE_OK) {
@@ -1795,6 +1800,21 @@ EXAPI int isf_db_rollback_transaction(void)
     return (ret == EXIT_SUCCESS);
 }
 
+/**
+ * @brief Check availability of the path that isf db file will be stored
+ *
+ * @return 1 if it is available, otherwise return 0.
+ */
+EXAPI int isf_db_check_path_available(void)
+{
+    const char *user_db_path = tzplatform_getenv(TZ_USER_DB);
+    if (access(user_db_path, F_OK) != 0) {
+        LOGW("access failed : %s, errno(%d) - %s", user_db_path, errno, strerror(errno));
+        return 0;
+    }
+    return 1;
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab
 */
index 04f1ffb..0fd94ee 100644 (file)
@@ -84,6 +84,7 @@ EXAPI int isf_db_is_in_transaction(void);
 EXAPI int isf_db_begin_transaction(void);
 EXAPI int isf_db_commit_transaction(void);
 EXAPI int isf_db_rollback_transaction(void);
+EXAPI int isf_db_check_path_available(void);
 
 #endif /* __ISF_QUERY_UTILITY_H__ */
 
index 55580ab..df46017 100644 (file)
@@ -407,6 +407,18 @@ scim_global_config_reset (const String &key)
 }
 
 EXAPI bool
+scim_global_config_reload ()
+{
+    if (__config_repository.updated.size ())
+        return false;
+
+    // Reload all configuration.
+    __initialize_config ();
+
+    return true;
+}
+
+EXAPI bool
 scim_global_config_flush ()
 {
     if (!__config_repository.initialized)
index 698e51b..657c356 100644 (file)
@@ -162,6 +162,12 @@ EXAPI void scim_global_config_write (const String &key, const std::vector <int>
 EXAPI void scim_global_config_reset (const String &key);
 
 /**
+ * @brief Reload global config.
+ * @return true if success.
+ */
+EXAPI bool scim_global_config_reload ();
+
+/**
  * @brief Flush the updated global config into user global config file.
  * @return true if success.
  */
index 7b5ba2f..157786c 100644 (file)
@@ -25,6 +25,7 @@ BuildRequires:  pkgconfig(tts)
 %endif
 BuildRequires:  pkgconfig(eina)
 BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(ecore-file)
 BuildRequires:  pkgconfig(evas)
 BuildRequires:  pkgconfig(edje)
 BuildRequires:  pkgconfig(dlog)