Remove pkgmgr-info dependency from libscim-1.0.so library 10/46310/1
authorSungmin Kwak <sungmin.kwak@samsung.com>
Mon, 3 Aug 2015 12:39:28 +0000 (21:39 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 19 Aug 2015 05:18:09 +0000 (14:18 +0900)
Make initial ime_info DB in scim process

Change-Id: I854a8b68cfe048683a750d65f7457f5b763bdc4a

ism/extras/efl_panel/isf_panel_efl.cpp
ism/src/Makefile.am
ism/src/isf_query_utility.cpp
ism/src/isf_query_utility.h
ism/src/scim.cpp

index 8a0587d..b39d075 100644 (file)
@@ -1077,7 +1077,216 @@ static unsigned int get_ise_index (const String uuid)
     return index;
 }
 
+/**
+ * @brief Read data from ime category manifest and insert initial db
+ *
+ * @param handle    pkgmgrinfo_appinfo_h pointer
+ * @param user_data The data to pass to this callback.
+ *
+ * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.
+ *
+ * @see _ime_app_list_cb function in scim.cpp; it's slightly different.
+ */
+static int _filtered_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+    int ret = 0;
+    char *appid = NULL, *pkgid = NULL, *pkgtype = NULL, *exec = NULL, *label = NULL, *path = NULL;
+    pkgmgrinfo_pkginfo_h  pkginfo_handle = NULL;
+    ImeInfoDB ime_db;
+    bool *result = static_cast<bool*>(user_data);
+
+    if (result) /* in this case, need to check category */ {
+        bool exist = true;
+        ret = pkgmgrinfo_appinfo_is_category_exist (handle, "http://tizen.org/category/ime", &exist);
+        if (ret != PMINFO_R_OK || !exist) {
+            return 0;
+        }
+    }
+
+    /* appid */
+    ret = pkgmgrinfo_appinfo_get_appid (handle, &appid);
+    if (ret == PMINFO_R_OK)
+        ime_db.appid = String (appid ? appid : "");
+    else {
+        ISF_SAVE_LOG ("appid is not available!\n");
+        return 0;
+    }
+
+    ime_db.iconpath = "";
+
+    /* pkgid */
+    ret = pkgmgrinfo_appinfo_get_pkgid (handle, &pkgid);
+    if (ret == PMINFO_R_OK)
+        ime_db.pkgid = String (pkgid ? pkgid : "");
+    else {
+        ISF_SAVE_LOG ("pkgid is not available!\n");
+        return 0;
+    }
+
+    /* exec path */
+    ret = pkgmgrinfo_appinfo_get_exec (handle, &exec);
+    if (ret == PMINFO_R_OK)
+        ime_db.exec = String (exec ? exec : "");
+    else {
+        ISF_SAVE_LOG ("exec is not available!\n");
+        return 0;
+    }
+
+    /* label */
+    ret = pkgmgrinfo_appinfo_get_label (handle, &label);
+    if (ret == PMINFO_R_OK)
+        ime_db.label = String (label ? label : "");
+
+    /* get pkgmgrinfo_pkginfo_h */
+    ret = pkgmgrinfo_pkginfo_get_pkginfo (pkgid, &pkginfo_handle);
+    if (ret == PMINFO_R_OK && pkginfo_handle) {
+        /* pkgtype */
+        ret = pkgmgrinfo_pkginfo_get_type(pkginfo_handle, &pkgtype);
+
+        if (ret == PMINFO_R_OK)
+            ime_db.pkgtype = String(pkgtype ? pkgtype : "");
+        else {
+            ISF_SAVE_LOG ("pkgtype is not available!");
+            pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
+            return 0;
+        }
+
+        /* pkgrootpath */
+        ret = pkgmgrinfo_pkginfo_get_root_path (pkginfo_handle, &path);
+    }
+
+    ime_db.languages = "en";
+    ime_db.display_lang = "";
+
+    if (ime_db.pkgtype.compare ("rpm") == 0 &&   //1 Inhouse IMEngine ISE(IME)
+        ime_db.exec.find ("scim-launcher") != String::npos)  // Some IMEngine's pkgid doesn't have "ise-engine" prefix.
+    {
+        ime_db.mode = TOOLBAR_KEYBOARD_MODE;
+        ime_db.options = 0;
+        ime_db.module_path = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION)
+            + String (SCIM_PATH_DELIM_STRING) + String ("IMEngine");
+        ime_db.module_name = ime_db.pkgid;
+        ime_db.is_enabled = 1;
+        ime_db.is_preinstalled = 1;
+        ime_db.has_option = 0; // It doesn't matter. No option for IMEngine...
+    }
+    else {
+        ime_db.mode = TOOLBAR_HELPER_MODE;
+        if (ime_db.pkgtype.compare ("rpm") == 0) //1 Inhouse Helper ISE(IME)
+        {
+#ifdef _TV
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT;
+#else
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART;
+#endif
+            ime_db.module_path = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION)
+                + String (SCIM_PATH_DELIM_STRING) + String ("Helper");
+            ime_db.module_name = ime_db.pkgid;
+            ime_db.is_enabled = 1;
+            ime_db.is_preinstalled = 1;
+            ime_db.has_option = 1;  // Let's assume the inhouse IME always has an option menu.
+        }
+#ifdef _WEARABLE
+        else if (ime_db.pkgtype.compare ("wgt") == 0)    //1 Download Web IME
+        {
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART
+                | SCIM_HELPER_NEED_SPOT_LOCATION_INFO | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT | ISM_HELPER_WITHOUT_IMENGINE;
+            ime_db.module_path = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION)
+                + String (SCIM_PATH_DELIM_STRING) + String ("Helper");
+            ime_db.module_name = String ("ise-web-helper-agent");
+            if (ime_db.exec.compare (0, 5, "/usr/") == 0) {
+                ime_db.is_enabled = 1;
+                ime_db.is_preinstalled = 1;
+            }
+            else {
+               ime_db.is_enabled = 0;
+               ime_db.is_preinstalled = 0;
+            }
+            ime_db.has_option = -1; // At this point, we can't know IME has an option (setting) or not; -1 means unknown.
+        }
+#endif
+        else if (ime_db.pkgtype.compare ("tpk") == 0)    //1 Download Native IME
+        {
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART
+                | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT | ISM_HELPER_WITHOUT_IMENGINE;
+            if (path)
+                ime_db.module_path = String (path) + String ("/lib");
+            else
+                ime_db.module_path = String ("/opt/usr/apps/") + ime_db.pkgid + String ("/lib");
+            ime_db.module_name = String ("lib") + ime_db.exec.substr (ime_db.exec.find_last_of (SCIM_PATH_DELIM) + 1);
+            if (ime_db.exec.compare (0, 5, "/usr/") == 0) {
+                ime_db.is_enabled = 1;
+                ime_db.is_preinstalled = 1;
+            }
+            else {
+                ime_db.is_enabled = 0;
+                ime_db.is_preinstalled = 0;
+            }
+            ime_db.has_option = -1; // At this point, we can't know IME has an option (setting) or not; -1 means unknown.
+        }
+        else {
+            ISF_SAVE_LOG ("Unsupported pkgtype(%s)\n", ime_db.pkgtype.c_str ());
+            if (pkginfo_handle) {
+                pkgmgrinfo_pkginfo_destroy_pkginfo (pkginfo_handle);
+                pkginfo_handle = NULL;
+            }
+            return 0;
+        }
+    }
+
+    ret = isf_db_insert_ime_info (&ime_db);
+    if (ret < 1)
+        ret = isf_db_update_ime_info (&ime_db);
+
+    if (pkginfo_handle) {
+        pkgmgrinfo_pkginfo_destroy_pkginfo (pkginfo_handle);
+        pkginfo_handle = NULL;
+    }
+
+    if (result && ret)
+        *result = true;
+
+    return 0;
+}
+
 #if HAVE_PKGMGR_INFO
+/**
+ * @brief Insert ime_info data with pkgid.
+ *
+ * @param pkgid pkgid to insert/update ime_info table.
+ *
+ * @return 1 if it is successful, otherwise return 0.
+ */
+int _db_insert_ime_info_by_pkgid(const char *pkgid)
+{
+    int ret = 0;
+    pkgmgrinfo_pkginfo_h handle = NULL;
+    bool isImePkg = false;
+
+    if (!pkgid) {
+        LOGW("pkgid is null.");
+        return 0;
+    }
+
+    ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+    if (ret != PMINFO_R_OK) {
+        LOGW("pkgmgrinfo_pkginfo_get_pkginfo(\"%s\",~) returned %d", pkgid, ret);
+        return 0;
+    }
+
+    ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, _filtered_app_list_cb, (void *)&isImePkg);
+    if (ret != PMINFO_R_OK) {
+        LOGW("pkgmgrinfo_appinfo_get_list failed(%d)", ret);
+        ret = 0;
+    }
+    else if (isImePkg)
+        ret = 1;
+
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+    return ret;
+}
+
 static Eina_Bool _start_default_helper_timer(void *data)
 {
     std::vector<String> total_appids;
@@ -1161,7 +1370,7 @@ static void _package_manager_event_cb (const char *type, const char *package, pa
                 }
             }
 
-            if (isf_db_insert_ime_info_by_pkgid(package)) {
+            if (_db_insert_ime_info_by_pkgid(package)) {
                 if (is_enabled >= 0) {
                     isf_db_update_is_enabled_by_appid(g_stopped_helper_appid.c_str(), (bool)is_enabled);
                 }
@@ -3591,9 +3800,12 @@ static bool update_ise_list (std::vector<String> &list)
     std::vector<String> uuids;
     std::vector<TOOLBAR_MODE_T>  modes;
     std::vector<ImeInfoDB>::iterator iter;
+    bool result = true;
 
-    if (_ime_info.size() == 0)
-        isf_db_select_all_ime_info(_ime_info);
+    if (_ime_info.size() == 0) {
+        if (isf_db_select_all_ime_info(_ime_info) == 0)
+            result = false;
+    }
 
     /* Update _groups */
     _groups.clear();
@@ -3637,15 +3849,16 @@ static bool update_ise_list (std::vector<String> &list)
                 }
             }
         }
-    }
 
-    char *lang_str = vconf_get_str (VCONFKEY_LANGSET);
-    if (lang_str) {
-        if (_ime_info.size () > 0 && _ime_info[0].display_lang.compare(lang_str) == 0)
-            _locale_string = String (lang_str);
-        free (lang_str);
+        char *lang_str = vconf_get_str (VCONFKEY_LANGSET);
+        if (lang_str) {
+            if (_ime_info.size () > 0 && _ime_info[0].display_lang.compare(lang_str) == 0)
+                _locale_string = String (lang_str);
+            free (lang_str);
+        }
     }
 
+
 #if HAVE_PKGMGR_INFO
     if (!pkgmgr) {
         int ret = package_manager_create (&pkgmgr);
@@ -3664,7 +3877,7 @@ static bool update_ise_list (std::vector<String> &list)
     }
 #endif
 
-    return true;
+    return result;
 }
 
 /**
@@ -5616,9 +5829,9 @@ static void update_ise_locale ()
             pkgmgrinfo_appinfo_destroy_appinfo(handle);
         }
     }
-    isf_db_update_disp_lang(lang_str);
 
     if (lang_str) {
+        isf_db_update_disp_lang(lang_str);
         _locale_string = String (lang_str);
         free (lang_str);
     }
@@ -6592,7 +6805,19 @@ int main (int argc, char *argv [])
     try {
         /* Update ISE list */
         std::vector<String> list;
-        update_ise_list (list);
+        if (update_ise_list (list) == false) {  // If there is no IME, that is, if ime_info DB is empty... But probably it's already made by scim process.
+            pkgmgrinfo_appinfo_filter_h handle;
+            int result = pkgmgrinfo_appinfo_filter_create (&handle);
+            if (result == PMINFO_R_OK) {
+                result = pkgmgrinfo_appinfo_filter_add_string (handle, PMINFO_APPINFO_PROP_APP_CATEGORY, "http://tizen.org/category/ime");
+                if (result == PMINFO_R_OK) {
+                    result = pkgmgrinfo_appinfo_filter_foreach_appinfo (handle, _filtered_app_list_cb, NULL);
+                }
+                pkgmgrinfo_appinfo_filter_destroy (handle);
+            }
+
+            update_ise_list (list);
+        }
 
         /* Load initial ISE information */
         _initial_ise_uuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_INITIAL_ISE_UUID), String (SCIM_COMPOSE_KEY_FACTORY_UUID));
index e136746..1c024b2 100644 (file)
@@ -144,8 +144,7 @@ libscim@SCIM_EPOCH@_la_SOURCES = \
 
 libscim@SCIM_EPOCH@_la_CXXFLAGS = @EFL_CFLAGS@  @TZPLATFORM_CONFIG_CFLAGS@\
                          @DLOG_CFLAGS@ \
-                         @VCONF_CFLAGS@ \
-                         @PKGMGR_INFO_CFLAGS@
+                         @VCONF_CFLAGS@
 
 libscim@SCIM_EPOCH@_la_LDFLAGS  = -version-info $(SCIM_CURRENT):$(SCIM_REVISION):$(SCIM_AGE) \
                          -export-dynamic \
@@ -157,7 +156,6 @@ libscim@SCIM_EPOCH@_la_LDFLAGS  = -version-info $(SCIM_CURRENT):$(SCIM_REVISION)
                          @LTLIBINTL@ \
                          @EFL_LIBS@ \
                          @VCONF_LIBS@ \
-                         @PKGMGR_INFO_LIBS@ \
                          @TZPLATFORM_CONFIG_LIBS@ \
                          -lstdc++
 
@@ -177,9 +175,9 @@ libscim@SCIM_EPOCH@_la_LIBADD       = libltdlc.la
 bin_PROGRAMS           = scim isf-log
 
 scim_SOURCES           = scim.cpp
-scim_CXXFLAGS          = @EFL_CFLAGS@ @PRIVILEGE_CONTROL_CFLAGS@ @VCONF_CFLAGS@ @ECORE_IPC_CFLAGS@ -fPIE
+scim_CXXFLAGS          = @EFL_CFLAGS@ @PRIVILEGE_CONTROL_CFLAGS@ @VCONF_CFLAGS@ @PKGMGR_INFO_CFLAGS@ @ECORE_IPC_CFLAGS@ -fPIE
 scim_LDADD             = libscim@SCIM_EPOCH@.la
-scim_LDFLAGS           = @LTLIBINTL@ @EFL_LIBS@ @PRIVILEGE_CONTROL_LIBS@ @VCONF_LIBS@ @ECORE_IPC_LIBS@ -pie
+scim_LDFLAGS           = @LTLIBINTL@ @EFL_LIBS@ @PRIVILEGE_CONTROL_LIBS@ @VCONF_LIBS@ @PKGMGR_INFO_LIBS@ @ECORE_IPC_LIBS@ -pie
 
 if HAVE_X
 scim_CXXFLAGS += @ECOREX_CFLAGS@
index 51f0111..b7db600 100644 (file)
@@ -43,7 +43,6 @@
 #include "scim.h"
 #include "isf_query_utility.h"
 #include "scim_helper.h"
-#include <pkgmgr-info.h>
 #include <db-util.h>
 
 
@@ -82,8 +81,6 @@ static struct {
     DB_PATH, NULL
 };
 
-static int _filtered_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data);
-
 static inline int _begin_transaction(void)
 {
     sqlite3_stmt* pStmt = NULL;
@@ -250,7 +247,6 @@ static inline int _db_disconnect(void)
 static int _db_select_all_ime_info(std::vector<ImeInfoDB> &ime_info)
 {
     int ret = 0, i = 0;
-    bool firsttry = true;
     ImeInfoDB info;
     sqlite3_stmt* pStmt = NULL;
     static const char* pQuery = "SELECT * FROM ime_info;";
@@ -319,25 +315,6 @@ static int _db_select_all_ime_info(std::vector<ImeInfoDB> &ime_info)
             ime_info.push_back(info);
             i++;
         }
-        else if (i == 0 && firsttry) {
-            LOGD("sqlite3_step returned %d, empty DB", ret);
-            firsttry = false;
-
-            sqlite3_reset(pStmt);
-            sqlite3_clear_bindings(pStmt);
-            sqlite3_finalize(pStmt);
-
-            pkgmgrinfo_appinfo_filter_h handle;
-            ret = pkgmgrinfo_appinfo_filter_create(&handle);
-            if (ret == PMINFO_R_OK) {
-                ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, "http://tizen.org/category/ime");
-                if (ret == PMINFO_R_OK) {
-                    ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _filtered_app_list_cb, NULL);
-                }
-                pkgmgrinfo_appinfo_filter_destroy(handle);
-            }
-            ret = SQLITE_ROW;
-        }
     } while (ret == SQLITE_ROW);
 
     if (ret != SQLITE_DONE) {
@@ -467,7 +444,6 @@ out:
 static int _db_select_module_name_by_mode(TOOLBAR_MODE_T mode, std::vector<String> &mname)
 {
     int ret = 0, i = 0;
-    bool firsttry = true;
     sqlite3_stmt* pStmt = NULL;
     static const char* pQuery = "SELECT mname FROM ime_info WHERE mode = ?;";
 
@@ -493,25 +469,6 @@ static int _db_select_module_name_by_mode(TOOLBAR_MODE_T mode, std::vector<Strin
             SECURE_LOGD("%s: \"%s\"", (mode? "Helper": "IMEngine"), mname.back().c_str());
             i++;
         }
-        else if (i == 0 && firsttry) {
-            LOGD("sqlite3_step returned %d, mode=%d, empty DB", ret, mode);
-            firsttry = false;
-
-            sqlite3_reset(pStmt);
-            sqlite3_clear_bindings(pStmt);
-            sqlite3_finalize(pStmt);
-
-            pkgmgrinfo_appinfo_filter_h handle;
-            ret = pkgmgrinfo_appinfo_filter_create(&handle);
-            if (ret == PMINFO_R_OK) {
-                ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, "http://tizen.org/category/ime");
-                if (ret == PMINFO_R_OK) {
-                    ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, _filtered_app_list_cb, NULL);
-                }
-                pkgmgrinfo_appinfo_filter_destroy(handle);
-            }
-            ret = SQLITE_ROW;
-        }
     } while (ret == SQLITE_ROW);
 
     if (ret != SQLITE_DONE) {
@@ -927,84 +884,86 @@ out:
 /**
  * @brief Update data to ime_info table except for a few columns.
  *
- * @param ime_info The list to store ImeInfoDB
+ * @param ime_db The pointer of ImeInfoDB
  *
  * @return the number of updated data.
  */
-static int _db_update_ime_info(std::vector<ImeInfoDB> &ime_info)
+static int _db_update_ime_info(ImeInfoDB *ime_db)
 {
     int ret = 0, i = 0, has_option = 0;
     sqlite3_stmt* pStmt = NULL;
-    std::vector<ImeInfoDB>::iterator iter;
     static const char* pQuery = "UPDATE ime_info SET label = ?, exec = ?, mname = ?, mpath = ?, has_option = ? WHERE appid = ?;";
 
+    if (!ime_db) {
+        LOGE("Input parameter is null");
+        return 0;
+    }
+
     ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL);
     if (ret != SQLITE_OK) {
         LOGE("sqlite3_prepare_v2: %s", sqlite3_errmsg(databaseInfo.pHandle));
         return 0;
     }
 
-    for (iter = ime_info.begin (); iter != ime_info.end (); iter++) {
-        ret = sqlite3_bind_text(pStmt, 1, iter->label.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 1, ime_db->label.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 2, iter->exec.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 2, ime_db->exec.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 3, iter->module_name.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 3, ime_db->module_name.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 4, iter->module_path.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 4, ime_db->module_path.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        if (iter->pkgtype.compare("wgt") == 0 || iter->pkgtype.compare("tpk") == 0)
-            has_option = -1;
-        else if (iter->mode == TOOLBAR_HELPER_MODE)
-            has_option = 1;
-        else
-            has_option = 0;
-
-        ret = sqlite3_bind_int(pStmt, 5, has_option);
-        if (ret != SQLITE_OK) {
-            LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    if (ime_db->pkgtype.compare("wgt") == 0 || ime_db->pkgtype.compare("tpk") == 0)
+        has_option = -1;
+    else if (ime_db->mode == TOOLBAR_HELPER_MODE)
+        has_option = 1;
+    else
+        has_option = 0;
 
-        ret = sqlite3_bind_text(pStmt, 6, iter->appid.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_int(pStmt, 5, has_option);
+    if (ret != SQLITE_OK) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_step(pStmt);
-        if (ret != SQLITE_DONE) {
-            ISF_SAVE_LOG("sqlite3_step returned %d, appid=%s, %s\n", ret, iter->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
-            LOGE("sqlite3_step returned %d, appid=%s, %s", ret, iter->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
-            ret = SQLITE_ERROR;
-            goto out;
-        }
-        else {
-            SECURE_LOGD("Update \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
-                iter->appid.c_str(), iter->label.c_str(), iter->exec.c_str(), iter->module_name.c_str(), iter->module_path.c_str());
-            ret = SQLITE_OK;
-            i++;
-        }
-        sqlite3_reset(pStmt);
-        sqlite3_clear_bindings(pStmt);
+    ret = sqlite3_bind_text(pStmt, 6, ime_db->appid.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
     }
 
+    ret = sqlite3_step(pStmt);
+    if (ret != SQLITE_DONE) {
+        ISF_SAVE_LOG("sqlite3_step returned %d, appid=%s, %s\n", ret, ime_db->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
+        LOGE("sqlite3_step returned %d, appid=%s, %s", ret, ime_db->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
+        ret = SQLITE_ERROR;
+        goto out;
+    }
+    else {
+        SECURE_LOGD("Update \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
+            ime_db->appid.c_str(), ime_db->label.c_str(), ime_db->exec.c_str(), ime_db->module_name.c_str(), ime_db->module_path.c_str());
+        ret = SQLITE_OK;
+        i++;
+    }
+    sqlite3_reset(pStmt);
+    sqlite3_clear_bindings(pStmt);
+
 out:
     if (ret != SQLITE_OK) {
         sqlite3_reset(pStmt);
@@ -1018,120 +977,122 @@ out:
 /**
  * @brief Insert data to ime_info table.
  *
- * @param ime_info The list to store ImeInfoDB
+ * @param ime_db The pointer of ImeInfoDB
  *
  * @return the number of inserted data.
  */
-static int _db_insert_ime_info(std::vector<ImeInfoDB> &ime_info)
+static int _db_insert_ime_info(ImeInfoDB *ime_db)
 {
     int ret = 0, i = 0;
     sqlite3_stmt* pStmt = NULL;
-    std::vector<ImeInfoDB>::iterator iter;
     static const char* pQuery = "INSERT INTO ime_info (appid, label, pkgid, pkgtype, exec, mname, mpath, mode, options, is_enabled, is_preinstalled, has_option, disp_lang) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
 
+    if (!ime_db) {
+        LOGE("Input parameter is null");
+        return 0;
+    }
+
     ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL);
     if (ret != SQLITE_OK) {
         LOGE("sqlite3_prepare_v2: %s", sqlite3_errmsg(databaseInfo.pHandle));
         return 0;
     }
 
-    for (iter = ime_info.begin (); iter != ime_info.end (); iter++) {
-        ret = sqlite3_bind_text(pStmt, 1, iter->appid.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 1, ime_db->appid.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 2, iter->label.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 2, ime_db->label.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 3, iter->pkgid.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 3, ime_db->pkgid.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 4, iter->pkgtype.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 4, ime_db->pkgtype.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 5, iter->exec.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 5, ime_db->exec.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 6, iter->module_name.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 6, ime_db->module_name.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 7, iter->module_path.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 7, ime_db->module_path.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_int(pStmt, 8, iter->mode);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_int(pStmt, 8, ime_db->mode);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_int(pStmt, 9, (int)iter->options);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_int(pStmt, 9, (int)ime_db->options);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_int(pStmt, 10, (int)iter->is_enabled);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_int(pStmt, 10, (int)ime_db->is_enabled);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_int(pStmt, 11, (int)iter->is_preinstalled);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_int(pStmt, 11, (int)ime_db->is_preinstalled);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_int(pStmt, 12, iter->has_option);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_int(pStmt, 12, ime_db->has_option);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_int: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_bind_text(pStmt, 13, iter->display_lang.c_str(), -1, SQLITE_TRANSIENT);
-        if (ret != SQLITE_OK) {
-            LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
-            goto out;
-        }
+    ret = sqlite3_bind_text(pStmt, 13, ime_db->display_lang.c_str(), -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("sqlite3_bind_text: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
 
-        ret = sqlite3_step(pStmt);
-        if (ret != SQLITE_DONE) {
-            ISF_SAVE_LOG("sqlite3_step returned %d, appid=%s, %s\n", ret, iter->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
-            LOGE("sqlite3_step returned %d, appid=%s, %s", ret, iter->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
-            ret = SQLITE_ERROR;
-            goto out;
-        }
-        else {
-            SECURE_LOGD("Insert \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" %d %u %u %u %d \"%s\"",
-                iter->appid.c_str(), iter->label.c_str(), iter->pkgid.c_str(), iter->pkgtype.c_str(),
-                iter->module_name.c_str(), iter->exec.c_str(), iter->module_path.c_str(), iter->mode,
-                iter->options, iter->is_enabled, iter->is_preinstalled, iter->has_option, iter->display_lang.c_str());
-            ret = SQLITE_OK;
-            i++;
-        }
-        sqlite3_reset(pStmt);
-        sqlite3_clear_bindings(pStmt);
+    ret = sqlite3_step(pStmt);
+    if (ret != SQLITE_DONE) {
+        ISF_SAVE_LOG("sqlite3_step returned %d, appid=%s, %s\n", ret, ime_db->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
+        LOGE("sqlite3_step returned %d, appid=%s, %s", ret, ime_db->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
+        ret = SQLITE_ERROR;
+        goto out;
     }
+    else {
+        SECURE_LOGD("Insert \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" %d %u %u %u %d \"%s\"",
+            ime_db->appid.c_str(), ime_db->label.c_str(), ime_db->pkgid.c_str(), ime_db->pkgtype.c_str(),
+            ime_db->module_name.c_str(), ime_db->exec.c_str(), ime_db->module_path.c_str(), ime_db->mode,
+            ime_db->options, ime_db->is_enabled, ime_db->is_preinstalled, ime_db->has_option, ime_db->display_lang.c_str());
+        ret = SQLITE_OK;
+        i++;
+    }
+    sqlite3_reset(pStmt);
+    sqlite3_clear_bindings(pStmt);
 
 out:
     if (ret != SQLITE_OK) {
@@ -1186,175 +1147,6 @@ out:
 }
 
 /**
- * @brief Read data from ime category manifest and insert initial db
- *
- * @param handle    pkgmgrinfo_appinfo_h pointer
- * @param user_data The data to pass to this callback.
- *
- * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.
- */
-static int _filtered_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data)
-{
-    int ret = 0;
-    char *appid = NULL, *pkgid = NULL, *pkgtype = NULL, *exec = NULL, *label = NULL, *path = NULL;
-    pkgmgrinfo_pkginfo_h  pkginfo_handle = NULL;
-    ImeInfoDB ime_db;
-    std::vector<ImeInfoDB> ime_info;
-    bool *result = static_cast<bool*>(user_data);
-
-    if (result) /* in this case, need to check category */ {
-        bool exist = true;
-        ret = pkgmgrinfo_appinfo_is_category_exist(handle, "http://tizen.org/category/ime", &exist);
-        if (ret != PMINFO_R_OK || !exist) {
-            LOGD("ime category is not available!");
-            return 0;
-        }
-    }
-
-    /* appid */
-    ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
-    if (ret == PMINFO_R_OK)
-        ime_db.appid = String(appid ? appid : "");
-    else {
-        LOGE("appid is not available!");
-        return 0;
-    }
-
-    ime_db.iconpath = "";
-
-    /* pkgid */
-    ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
-    if (ret == PMINFO_R_OK)
-        ime_db.pkgid = String(pkgid ? pkgid : "");
-    else {
-        LOGE("pkgid is not available!");
-        return 0;
-    }
-
-    /* exec path */
-    ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
-    if (ret == PMINFO_R_OK)
-        ime_db.exec = String(exec ? exec : "");
-    else {
-        LOGE("exec is not available!");
-        return 0;
-    }
-
-    /* label */
-    ret = pkgmgrinfo_appinfo_get_label(handle, &label);
-    if (ret == PMINFO_R_OK)
-        ime_db.label = String(label ? label : "");
-
-    /* get pkgmgrinfo_pkginfo_h */
-    ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo_handle);
-    if (ret == PMINFO_R_OK && pkginfo_handle) {
-        /* pkgrootpath */
-        ret = pkgmgrinfo_pkginfo_get_root_path(pkginfo_handle, &path);
-
-        /* pkgtype */
-        ret = pkgmgrinfo_pkginfo_get_type(pkginfo_handle, &pkgtype);
-
-        if (ret == PMINFO_R_OK)
-            ime_db.pkgtype = String(pkgtype ? pkgtype : "");
-        else {
-            LOGE("pkgtype is not available!");
-            pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
-            return 0;
-        }
-    }
-
-    ime_db.languages = "en";
-    ime_db.display_lang = "";
-
-    if (ime_db.pkgtype.compare("rpm") == 0 &&   //1 Inhouse IMEngine ISE(IME)
-        ime_db.exec.find("scim-launcher") != String::npos)  // Some IMEngine's pkgid doesn't have "ise-engine" prefix.
-    {
-        ime_db.mode = TOOLBAR_KEYBOARD_MODE;
-        ime_db.options = 0;
-        ime_db.module_path = String(SCIM_MODULE_PATH) + String(SCIM_PATH_DELIM_STRING) + String(SCIM_BINARY_VERSION)
-            + String(SCIM_PATH_DELIM_STRING) + String("IMEngine");
-        ime_db.module_name = ime_db.pkgid;
-        ime_db.is_enabled = 1;
-        ime_db.is_preinstalled = 1;
-        ime_db.has_option = 0; // It doesn't matter. No option for IMEngine...
-    }
-    else {
-        ime_db.mode = TOOLBAR_HELPER_MODE;
-        if (ime_db.pkgtype.compare("rpm") == 0) //1 Inhouse Helper ISE(IME)
-        {
-            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART;
-            ime_db.module_path = String(SCIM_MODULE_PATH) + String(SCIM_PATH_DELIM_STRING) + String(SCIM_BINARY_VERSION)
-                + String(SCIM_PATH_DELIM_STRING) + String("Helper");
-            ime_db.module_name = ime_db.pkgid;
-            ime_db.is_enabled = 1;
-            ime_db.is_preinstalled = 1;
-            ime_db.has_option = 1;  // Let's assume the inhouse IME always has an option menu.
-        }
-#ifdef _WEARABLE
-        else if (ime_db.pkgtype.compare("wgt") == 0)    //1 Download Web IME
-        {
-            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART
-                | SCIM_HELPER_NEED_SPOT_LOCATION_INFO | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT | ISM_HELPER_WITHOUT_IMENGINE;
-            ime_db.module_path = String(SCIM_MODULE_PATH) + String(SCIM_PATH_DELIM_STRING) + String(SCIM_BINARY_VERSION)
-                + String(SCIM_PATH_DELIM_STRING) + String("Helper");
-            ime_db.module_name = String("ise-web-helper-agent");
-            if (ime_db.exec.compare(0, 5, "/usr/") == 0) {
-                ime_db.is_enabled = 1;
-                ime_db.is_preinstalled = 1;
-            }
-            else {
-               ime_db.is_enabled = 0;
-               ime_db.is_preinstalled = 0;
-            }
-            ime_db.has_option = -1; // At this point, we can't know IME has an option (setting) or not; -1 means unknown.
-        }
-#endif
-        else if (ime_db.pkgtype.compare("tpk") == 0)    //1 Download Native IME
-        {
-            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART
-                | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT | ISM_HELPER_WITHOUT_IMENGINE;
-            if (path)
-                ime_db.module_path = String(path) + String("/lib");
-            else
-                ime_db.module_path = String("/opt/usr/apps/") + ime_db.pkgid + String("/lib");
-            ime_db.module_name = String("lib") + ime_db.exec.substr(ime_db.exec.find_last_of(SCIM_PATH_DELIM) + 1);
-            if (ime_db.exec.compare(0, 5, "/usr/") == 0) {
-                ime_db.is_enabled = 1;
-                ime_db.is_preinstalled = 1;
-            }
-            else {
-                ime_db.is_enabled = 0;
-                ime_db.is_preinstalled = 0;
-            }
-            ime_db.has_option = -1; // At this point, we can't know IME has an option (setting) or not; -1 means unknown.
-        }
-        else {
-            LOGE("Unsupported pkgtype(%s)", ime_db.pkgtype.c_str());
-            if (pkginfo_handle) {
-                pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
-                pkginfo_handle = NULL;
-            }
-            return 0;
-        }
-    }
-
-    ime_info.push_back(ime_db);
-    ret = _db_insert_ime_info(ime_info);
-    if (ret < 1)
-        ret = _db_update_ime_info(ime_info);
-
-    if (pkginfo_handle) {
-        pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
-        pkginfo_handle = NULL;
-    }
-
-    if (result && ret)
-        *result = true;
-
-    return 0;
-}
-
-/**
  * @brief Select all ime_info table.
  *
  * @param ime_info The list to store ImeInfoDB
@@ -1623,45 +1415,52 @@ EAPI int isf_db_update_has_option_by_appid(const char *appid, bool has_option)
 }
 
 /**
- * @brief Insert ime_info data with pkgid.
+ * @brief Update data to ime_info table except for a few columns.
  *
- * @param pkgid pkgid to insert/update ime_info table.
+ * @param ime_db The pointer of ImeInfoDB
  *
- * @return 1 if it is successful, otherwise return 0.
+ * @return the number of updated data.
  */
-EAPI int isf_db_insert_ime_info_by_pkgid(const char *pkgid)
+EAPI int isf_db_update_ime_info(ImeInfoDB *ime_db)
 {
     int ret = 0;
-    pkgmgrinfo_pkginfo_h handle = NULL;
-    bool isImePkg = false;
 
-    if (!pkgid) {
-        LOGW("pkgid is null.");
-        return 0;
+    if (!ime_db) {
+        return ret;
     }
 
-    ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
-    if (ret != PMINFO_R_OK) {
-        LOGW("pkgmgrinfo_pkginfo_get_pkginfo(\"%s\",~) returned %d", pkgid, ret);
-        return 0;
+    if (_db_connect() == 0) {
+        ret = _db_update_ime_info(ime_db);
+        _db_disconnect();
     }
+    else
+        LOGW("failed");
 
-    if (_db_connect() == 0) {
-        ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, _filtered_app_list_cb, (void *)&isImePkg);
-        if (ret != PMINFO_R_OK) {
-            LOGW("pkgmgrinfo_appinfo_get_list failed(%d)", ret);
-            ret = 0;
-        }
-        else if (isImePkg)
-            ret = 1;
+    return ret;
+}
 
+/**
+ * @brief Insert data to ime_info table.
+ *
+ * @param ime_db The pointer of ImeInfoDB
+ *
+ * @return the number of inserted data.
+ */
+EAPI int isf_db_insert_ime_info(ImeInfoDB *ime_db)
+{
+    int ret = 0;
+
+    if (!ime_db) {
+        return ret;
+    }
+
+    if (_db_connect() == 0) {
+        ret = _db_insert_ime_info(ime_db);
         _db_disconnect();
     }
     else
         LOGW("failed");
 
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
     return ret;
 }
 
index f65e743..9229924 100644 (file)
@@ -76,7 +76,8 @@ EAPI int isf_db_update_label_by_appid(const char *appid, const char *label);
 EAPI int isf_db_update_disp_lang(const char *disp_lang);
 EAPI int isf_db_update_is_enabled_by_appid(const char *appid, bool is_enabled);
 EAPI int isf_db_update_has_option_by_appid(const char *appid, bool has_option);
-EAPI int isf_db_insert_ime_info_by_pkgid(const char *pkgid);
+EAPI int isf_db_update_ime_info(ImeInfoDB *ime_db);
+EAPI int isf_db_insert_ime_info(ImeInfoDB *ime_db);
 EAPI int isf_db_delete_ime_info_by_pkgid(const char *pkgid);
 
 #endif /* __ISF_QUERY_UTILITY_H */
index 22f4c1f..8f4413e 100644 (file)
@@ -45,6 +45,9 @@
 #include <privilege-control.h>
 #include <sys/resource.h>
 #include <sched.h>
+#include <pkgmgr-info.h>
+#include <scim_panel_common.h>
+#include "isf_query_utility.h"
 
 using namespace scim;
 using std::cout;
@@ -97,6 +100,168 @@ static bool check_panel (const String &display)
     return true;
 }
 
+/**
+ * @brief Read data from ime category manifest and insert initial db
+ *
+ * @param handle    pkgmgrinfo_appinfo_h pointer
+ * @param user_data The data to pass to this callback.
+ *
+ * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative.
+ *
+ * @see _filtered_app_list_cb function in isf_panel_efl.cpp; it's slightly different.
+ */
+static int _ime_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+    int ret = 0;
+    char *appid = NULL, *pkgid = NULL, *pkgtype = NULL, *exec = NULL, *label = NULL, *path = NULL;
+    pkgmgrinfo_pkginfo_h  pkginfo_handle = NULL;
+    ImeInfoDB ime_db;
+
+    /* appid */
+    ret = pkgmgrinfo_appinfo_get_appid (handle, &appid);
+    if (ret == PMINFO_R_OK)
+        ime_db.appid = String (appid ? appid : "");
+    else {
+        ISF_SAVE_LOG ("appid is not available!\n");
+        return 0;
+    }
+
+    ime_db.iconpath = "";
+
+    /* pkgid */
+    ret = pkgmgrinfo_appinfo_get_pkgid (handle, &pkgid);
+    if (ret == PMINFO_R_OK)
+        ime_db.pkgid = String (pkgid ? pkgid : "");
+    else {
+        ISF_SAVE_LOG ("pkgid is not available!\n");
+        return 0;
+    }
+
+    /* exec path */
+    ret = pkgmgrinfo_appinfo_get_exec (handle, &exec);
+    if (ret == PMINFO_R_OK)
+        ime_db.exec = String (exec ? exec : "");
+    else {
+        ISF_SAVE_LOG ("exec is not available!\n");
+        return 0;
+    }
+
+    /* label */
+    ret = pkgmgrinfo_appinfo_get_label (handle, &label);
+    if (ret == PMINFO_R_OK)
+        ime_db.label = String (label ? label : "");
+
+    /* get pkgmgrinfo_pkginfo_h */
+    ret = pkgmgrinfo_pkginfo_get_pkginfo (pkgid, &pkginfo_handle);
+    if (ret == PMINFO_R_OK && pkginfo_handle) {
+        /* pkgtype */
+        ret = pkgmgrinfo_pkginfo_get_type(pkginfo_handle, &pkgtype);
+
+        if (ret == PMINFO_R_OK)
+            ime_db.pkgtype = String(pkgtype ? pkgtype : "");
+        else {
+            ISF_SAVE_LOG ("pkgtype is not available!");
+            pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_handle);
+            return 0;
+        }
+
+        /* pkgrootpath */
+        ret = pkgmgrinfo_pkginfo_get_root_path (pkginfo_handle, &path);
+    }
+
+    ime_db.languages = "en";
+    ime_db.display_lang = "";
+
+    if (ime_db.pkgtype.compare ("rpm") == 0 &&   //1 Inhouse IMEngine ISE(IME)
+        ime_db.exec.find ("scim-launcher") != String::npos)  // Some IMEngine's pkgid doesn't have "ise-engine" prefix.
+    {
+        ime_db.mode = TOOLBAR_KEYBOARD_MODE;
+        ime_db.options = 0;
+        ime_db.module_path = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION)
+            + String (SCIM_PATH_DELIM_STRING) + String ("IMEngine");
+        ime_db.module_name = ime_db.pkgid;
+        ime_db.is_enabled = 1;
+        ime_db.is_preinstalled = 1;
+        ime_db.has_option = 0; // It doesn't matter. No option for IMEngine...
+    }
+    else {
+        ime_db.mode = TOOLBAR_HELPER_MODE;
+        if (ime_db.pkgtype.compare ("rpm") == 0) //1 Inhouse Helper ISE(IME)
+        {
+#ifdef _TV
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT;
+#else
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART;
+#endif
+            ime_db.module_path = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION)
+                + String (SCIM_PATH_DELIM_STRING) + String ("Helper");
+            ime_db.module_name = ime_db.pkgid;
+            ime_db.is_enabled = 1;
+            ime_db.is_preinstalled = 1;
+            ime_db.has_option = 1;  // Let's assume the inhouse IME always has an option menu.
+        }
+#ifdef _WEARABLE
+        else if (ime_db.pkgtype.compare ("wgt") == 0)    //1 Download Web IME
+        {
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART
+                | SCIM_HELPER_NEED_SPOT_LOCATION_INFO | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT | ISM_HELPER_WITHOUT_IMENGINE;
+            ime_db.module_path = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION)
+                + String (SCIM_PATH_DELIM_STRING) + String ("Helper");
+            ime_db.module_name = String ("ise-web-helper-agent");
+            if (ime_db.exec.compare (0, 5, "/usr/") == 0) {
+                ime_db.is_enabled = 1;
+                ime_db.is_preinstalled = 1;
+            }
+            else {
+               ime_db.is_enabled = 0;
+               ime_db.is_preinstalled = 0;
+            }
+            ime_db.has_option = -1; // At this point, we can't know IME has an option (setting) or not; -1 means unknown.
+        }
+#endif
+        else if (ime_db.pkgtype.compare ("tpk") == 0)    //1 Download Native IME
+        {
+            ime_db.options = SCIM_HELPER_STAND_ALONE | SCIM_HELPER_NEED_SCREEN_INFO | SCIM_HELPER_AUTO_RESTART
+                | ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT | ISM_HELPER_WITHOUT_IMENGINE;
+            if (path)
+                ime_db.module_path = String (path) + String ("/lib");
+            else
+                ime_db.module_path = String ("/opt/usr/apps/") + ime_db.pkgid + String ("/lib");
+            ime_db.module_name = String ("lib") + ime_db.exec.substr (ime_db.exec.find_last_of (SCIM_PATH_DELIM) + 1);
+            if (ime_db.exec.compare (0, 5, "/usr/") == 0) {
+                ime_db.is_enabled = 1;
+                ime_db.is_preinstalled = 1;
+            }
+            else {
+                ime_db.is_enabled = 0;
+                ime_db.is_preinstalled = 0;
+            }
+            ime_db.has_option = -1; // At this point, we can't know IME has an option (setting) or not; -1 means unknown.
+        }
+        else {
+            ISF_SAVE_LOG ("Unsupported pkgtype(%s)\n", ime_db.pkgtype.c_str ());
+            if (pkginfo_handle) {
+                pkgmgrinfo_pkginfo_destroy_pkginfo (pkginfo_handle);
+                pkginfo_handle = NULL;
+            }
+            return 0;
+        }
+    }
+
+    ret = isf_db_insert_ime_info (&ime_db);
+    if (ret < 1) {
+        ISF_SAVE_LOG("isf_db_insert_ime_info failed(%d). appid=%s pkgid=%s\n", ret, ime_db.appid.c_str(), ime_db.pkgid.c_str());
+    }
+
+    if (pkginfo_handle) {
+        pkgmgrinfo_pkginfo_destroy_pkginfo (pkginfo_handle);
+        pkginfo_handle = NULL;
+    }
+
+    return 0;
+}
+
+
 /* The broker for launching OSP based IMEs */
 // {
 
@@ -313,8 +478,22 @@ int main (int argc, char *argv [])
     config_list.push_back ("simple");
     config_list.push_back ("socket");
 
+    scim_get_helper_module_list (helper_list);
+    if (helper_list.size () < 1) {  // If there is no IME, that is, if ime_info DB is empty...
+        pkgmgrinfo_appinfo_filter_h handle;
+        int ret = pkgmgrinfo_appinfo_filter_create (&handle);
+        if (ret == PMINFO_R_OK) {
+            ret = pkgmgrinfo_appinfo_filter_add_string (handle, PMINFO_APPINFO_PROP_APP_CATEGORY, "http://tizen.org/category/ime");
+            if (ret == PMINFO_R_OK) {
+                ret = pkgmgrinfo_appinfo_filter_foreach_appinfo (handle, _ime_app_list_cb, NULL);
+            }
+            pkgmgrinfo_appinfo_filter_destroy (handle);
+        }
+
+        scim_get_helper_module_list (helper_list);  // Assuming ime_info DB is initialized, try again.
+    }
+
     scim_get_imengine_module_list (engine_list);
-    scim_get_helper_module_list   (helper_list);
 
     for (it = engine_list.begin (); it != engine_list.end (); it++) {
         all_engine_list.push_back (*it);