Add exceptional case of IME package update and revise socket_update_ise_list() 58/48558/1
authorSungmin Kwak <sungmin.kwak@samsung.com>
Tue, 22 Sep 2015 10:18:57 +0000 (19:18 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 23 Sep 2015 02:26:54 +0000 (11:26 +0900)
Change-Id: I5614f740cd519bfd761414d719205eebf1c4f3de

ism/extras/efl_panel/isf_panel_efl.cpp
ism/modules/frontend/scim_socket_frontend.cpp
ism/src/isf_pkg.cpp
ism/src/isf_query_utility.cpp
ism/src/isf_query_utility.h

index 135948fcdec1f757884ca7708d98b17b5762b496..188e8a8b680e15f906a7437dc83e59ad93829bc0 100644 (file)
@@ -1148,13 +1148,13 @@ static void _initialize_ime_info (void)
  *
  * @param pkgid pkgid to insert/update ime_info table.
  *
- * @return 1 on success, -1 if pkgid is not IME package, otherwise return 0.
+ * @return 1 on successfull insert, 2 on successful update, -1 if pkgid is not IME package, otherwise return 0.
  */
-int _isf_insert_ime_info_by_pkgid(const char *pkgid)
+static int _isf_insert_ime_info_by_pkgid(const char *pkgid)
 {
     int ret = -1;
     pkgmgrinfo_pkginfo_h handle = NULL;
-    bool isImePkg = false;
+    int result = 0;  // 0: not IME, 1: Inserted, 2: Updated (because of the same appid)
 
     if (!pkgid) {
         LOGW("pkgid is null.");
@@ -1167,13 +1167,13 @@ int _isf_insert_ime_info_by_pkgid(const char *pkgid)
         return 0;
     }
 
-    ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, isf_pkg_ime_app_list_cb, (void *)&isImePkg);
+    ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, isf_pkg_ime_app_list_cb, (void *)&result);
     if (ret != PMINFO_R_OK) {
         LOGW("pkgmgrinfo_appinfo_get_list failed(%d)", ret);
         ret = 0;
     }
-    else if (isImePkg)
-        ret = 1;
+    else if (result)
+        ret = result;
 
     pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
 
@@ -1249,8 +1249,9 @@ INFO: Package install/update/uninstall scenario
 Install and Uninstall are obviously simple.
    Install: just INSTALL
    Uninstall: just UNINSTALL
-Update package (change the source codes in IME project and Run As again), there are three scenarios:
+Update package (change the source codes in IME project and Run As again), there are four scenarios:
 1. UPDATE
+   Source code change
 2. UNINSTALL -> INSTALL
    This happens when Tizen IDE Property > Tizen SDK > Rapid Development Support > Check "Enable Project specific settings"
    and change Application ID in tizen-manifest.xml file and Run As.
@@ -1258,6 +1259,9 @@ Update package (change the source codes in IME project and Run As again), there
    This happens when Tizen IDE Property > Tizen SDK > Rapid Development Support > Uncheck "Enable Project specific settings"
    and change Application ID in tizen-manifest.xml file and Run As.
    At UPDATE event, pkgid (package parameter) is invalid...
+4. UPDATE
+   Exceptionally, only UPDATE can be called when Application ID in tizen-manifest.xml file is changed.
+   At UPDATE event, pkgid (package parameter) is valid, and only appid is changed; the previous appid is invalid.
 
 If multiple packages (including non-IME pkgs) are uninstalled and installed; Z300H UPS (ultra power saving) mode scenario.
 For example, A and B packages are uninstalled and installed, the package manager works in this order: A UNINSTALL ¡æB UNINSTALL ¡æA INSTALL ¡æB INSTALL
@@ -1282,9 +1286,39 @@ static void _package_manager_event_cb (const char *type, const char *package, pa
         if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) {
             LOGD ("type=%s package=%s event_type=UPDATE event_state=COMPLETED progress=%d error=%d", type, package, progress, error);
 
-            ret = _isf_insert_ime_info_by_pkgid(package);   // If package is not IME, -1 would be returned.
-            if (ret == 1) { // In case IME package is updated...
-                _update_ime_info();
+            ret = _isf_insert_ime_info_by_pkgid (package);   // If package is not IME, -1 would be returned.
+            if (ret == 1) { // In case the package is updated with the changed appid. In this case, there will be two IMEs
+                ret = isf_db_select_appids_by_pkgid (package, appids);
+                if (ret > 1) {
+                    if (_ime_info.size () > 0 && _ime_info [get_ise_index (appids.front ())].is_enabled)
+                        isf_db_update_is_enabled_by_appid(appids.back ().c_str (), true);
+                    isf_db_delete_ime_info_by_appid (appids.front ().c_str ());
+                }
+
+                _update_ime_info ();
+
+                /* Let panel know that ise list is changed... */
+                for (it = _ime_info.begin(); it != _ime_info.end(); it++) {
+                    total_appids.push_back(it->appid);
+                }
+                if (total_appids.size() > 0)
+                    _panel_agent->update_ise_list (total_appids);
+
+                if (ret > 1 && _soft_keyboard_launched) { // If the previous appid of pkgid is the current IME, restart it with new appid.
+                    current_ime_appid = scim_global_config_read(String(SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), _initial_ise_uuid);
+                    if (current_ime_appid.compare (appids.front ()) == 0) {
+                        LOGD("Stop IME(%s)", current_ime_appid.c_str ());
+                        _panel_agent->hide_helper (current_ime_appid);
+                        _panel_agent->stop_helper (current_ime_appid);
+                        LOGD("Start IME(%s)", appids.back ().c_str ());
+                        scim_global_config_write (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), appids.back ());
+                        set_keyboard_engine (String (SCIM_COMPOSE_KEY_FACTORY_UUID));
+                        _panel_agent->start_helper (appids.back ());
+                    }
+                }
+            }
+            else if (ret == 2) {  // In case IME package is just updated...
+                _update_ime_info ();
 
                 if (_soft_keyboard_launched) { // If package is the current IME, restart it.
                     current_ime_appid = scim_global_config_read(String(SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), _initial_ise_uuid);
@@ -1359,7 +1393,7 @@ static void _package_manager_event_cb (const char *type, const char *package, pa
                 g_stopped_helper_pkgid = "";
 
                 ret = _isf_insert_ime_info_by_pkgid(package);
-                if (ret) {
+                if (ret > 0) {
                     /* Find appid by pkgid. There might be multiple appid, but assume Helper always has one appid.
                        And appid can be changed, but pkgid won't be changed. */
                     ret = isf_db_select_appids_by_pkgid(package, appids);
@@ -1408,7 +1442,7 @@ static void _package_manager_event_cb (const char *type, const char *package, pa
             }
             else {  // If new package is installed...
                 ret = _isf_insert_ime_info_by_pkgid(package);   // If package is not IME, -1 would be returned.
-                if (ret == 1) { // In case package is IME...
+                if (ret > 0) { // In case package is IME...
                     ///////////////// INSTALL /////////////////
                     _update_ime_info();
 
index cfcb7eb8392181459dd3fb4f99075321f717f6e6..86b15f6ffa1b04a682abf090500ace7192cd421b 100644 (file)
@@ -2057,56 +2057,36 @@ void
 SocketFrontEnd::socket_update_ise_list (int /*client_id*/)
 {
     String strName;
-    std::vector<String> install_modules;
-    std::vector<String> imengine_list;
-    std::vector<String> helper_list;
-    size_t i = 0, j = 0;
+    size_t i = 0;
 
     if (m_receive_trans.get_data (strName) && strName.length () > 0) {
         //std::cout << "ISE name list:" << strName << "\n";
         //scim_split_string_list (name_list, strName);
 
-        scim_get_imengine_module_list (imengine_list);
-        scim_get_helper_module_list (helper_list);
-
-        for (i = 0; i < imengine_list.size (); ++i) {
-            install_modules.push_back (imengine_list [i]);
-            if (std::find (__load_engine_list.begin (), __load_engine_list.end (), imengine_list [i]) == __load_engine_list.end ()) {
-                SCIM_DEBUG_FRONTEND (3) << "add_module " << imengine_list [i]  << " in " << __FUNCTION__ << "\n";
-                //add_module (m_config, imengine_list [i], true);
-                add_module_info (m_config, imengine_list [i]);
-                __load_engine_list.push_back (imengine_list [i]);
-            }
-        }
-
-        ImeInfoDB imeInfo;
+        /* The strName has all appids but here module name is necessary. */
         HelperInfo   info;
-        for (i = 0; i < helper_list.size (); ++i) {
-            install_modules.push_back (helper_list [i]);
-            if (std::find (__load_engine_list.begin (), __load_engine_list.end (), helper_list [i]) == __load_engine_list.end ()) {
-                if (isf_db_select_ime_info_by_module_name (helper_list [i].c_str (), &imeInfo)) {
-                    info.uuid = imeInfo.appid;
-                    info.name = imeInfo.label;
-                    info.icon = imeInfo.iconpath;
-                    info.description = "";
-                    info.option = imeInfo.options;
-                    __helpers.push_back (std::make_pair (info, helper_list [i]));
-                    __load_engine_list.push_back (helper_list [i]);
+        std::vector<ImeInfoDB> ime_info;
+        isf_db_select_all_ime_info(ime_info);
+        if (ime_info.size () > 0) {
+            __load_engine_list.clear ();
+            __helpers.clear ();
+
+            for (i = 0; i < ime_info.size (); ++i) {
+                if (ime_info [i].mode == TOOLBAR_KEYBOARD_MODE) {
+                    /* add_module_info (m_config, ime_info [i].module_name); This seems unnecessary because IMEngine will not be added or deleted. */
+                    __load_engine_list.push_back (ime_info [i].module_name);
                 }
             }
-        }
-
-        /* Try to find uninstall ISEs */
-        for (i = 0; i < __load_engine_list.size (); ++i) {
-            if (std::find (install_modules.begin (), install_modules.end (), __load_engine_list [i]) == install_modules.end ()) {
-                HelperRepository tmp_helpers = __helpers;
-                __helpers.clear ();
-                for (j = 0; j < tmp_helpers.size (); ++j) {
-                    if (std::find (install_modules.begin (), install_modules.end (), tmp_helpers [j].second) != install_modules.end ())
-                        __helpers.push_back (tmp_helpers [j]);
+            for (i = 0; i < ime_info.size (); ++i) {
+                if (ime_info [i].mode == TOOLBAR_HELPER_MODE) {
+                    info.uuid = ime_info [i].appid;
+                    info.name = ime_info [i].label;
+                    info.icon = ime_info [i].iconpath;
+                    info.description = "";
+                    info.option = ime_info [i].options;
+                    __helpers.push_back (std::make_pair (info, ime_info [i].module_name));
+                    __load_engine_list.push_back (ime_info [i].module_name);
                 }
-                __load_engine_list = install_modules;
-                break;
             }
         }
     }
index d7ddaa1b6fecd0b4a5c601a7ac6c18f127d11f18..44aee290c54405c009b1c475ef6e3019f4ca3c76 100644 (file)
@@ -52,7 +52,7 @@ int isf_pkg_ime_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data)
     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);
+    int *result = static_cast<int*>(user_data); // 0: not IME, 1: Inserted, 2: Updated
 
     if (result) /* in this case, need to check category */ {
         bool exist = true;
@@ -195,10 +195,18 @@ int isf_pkg_ime_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data)
 
     ret = isf_db_insert_ime_info (&ime_db);
     if (ret < 1) {
-        if (result)
+        if (result) {
             ret = isf_db_update_ime_info (&ime_db);
-        if (ret < 1)
+            if (ret) {
+                *result = 2;    // Updated
+            }
+        }
+        if (ret < 1) {
             ISF_SAVE_LOG("isf_db_%s_ime_info failed(%d). appid=%s pkgid=%s\n", (result? "update" : "insert"), ret, ime_db.appid.c_str(), ime_db.pkgid.c_str());
+        }
+    }
+    else if (result && ret) {
+        *result = 1;    // Inserted
     }
 
     if (pkginfo_handle) {
@@ -206,9 +214,6 @@ int isf_pkg_ime_app_list_cb (const pkgmgrinfo_appinfo_h handle, void *user_data)
         pkginfo_handle = NULL;
     }
 
-    if (result && ret)
-        *result = true;
-
     return 0;
 }
 
index e07e26d31b27f43f36b8b9b4a769041765b9db49..ac568613210d5d0e6f7dad39c402654d60e88a2a 100644 (file)
@@ -438,7 +438,7 @@ out:
 }
 
 /**
- * @brief Select ime_info table with mname.
+ * @brief Select ime_info table with module name.
  *
  * @remarks There can be multiple ime_info tables for one module naume. For now, assuming the module name is unique.
  *
@@ -1260,6 +1260,48 @@ out:
     return i;
 }
 
+/**
+ * @brief Delete ime_info data with appid.
+ *
+ * @param appid appid to delete ime_info table.
+ *
+ * @return 1 if it is successful, otherwise return 0.
+ */
+static int _db_delete_ime_info_by_appid(const char *appid)
+{
+    int i = 0, ret = 0;
+    sqlite3_stmt* pStmt = NULL;
+    static const char* pQuery = "DELETE FROM ime_info WHERE appid = ?;";
+
+    ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+        return i;
+    }
+
+    ret = sqlite3_bind_text(pStmt, 1, appid, -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) {
+        LOGE("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
+    }
+    else {
+        // If there is no appid to delete, ret is still SQLITE_DONE.
+        SECURE_LOGD("DELETE FROM ime_info WHERE appid = %s;", appid);
+        i = 1;
+    }
+
+out:
+    sqlite3_reset(pStmt);
+    sqlite3_clear_bindings(pStmt);
+    sqlite3_finalize(pStmt);
+    return i;
+}
+
 /**
  * @brief Delete all ime_info data.
  *
@@ -1344,7 +1386,7 @@ EXAPI int isf_db_select_ime_info_by_appid(const char *appid, ImeInfoDB *pImeInfo
 }
 
 /**
- * @brief Select ime_info table with mname.
+ * @brief Select ime_info table with module name.
  *
  * @remarks There can be multiple ime_info tables for one module naume. For now, assuming the module name is unique.
  *
@@ -1687,6 +1729,37 @@ EXAPI int isf_db_delete_ime_info_by_pkgid(const char *pkgid)
     return ret;
 }
 
+/**
+ * @brief Delete ime_info data with appid.
+ *
+ * @param appid appid to delete ime_info table.
+ *
+ * @return 1 if it is successful, otherwise return 0.
+ */
+EXAPI int isf_db_delete_ime_info_by_appid(const char *appid)
+{
+    int ret = 0;
+
+    if (!appid) {
+        LOGW("Input parameter is null.");
+        return ret;
+    }
+
+    if (_db_connect() == 0) {
+        ret = _db_delete_ime_info_by_appid(appid);
+        _db_disconnect();
+    }
+    else
+        LOGW("failed");
+
+    return ret;
+}
+
+/**
+ * @brief Delete all ime_info data.
+ *
+ * @return 1 if it is successful, otherwise return 0.
+ */
 EXAPI int isf_db_delete_ime_info(void)
 {
     int ret = 0;
index eb4cd616b604492e87fd3e5e4179ac88156b6141..127c9cb656dfe568617164e0672789894ba3f9e6 100644 (file)
@@ -79,6 +79,7 @@ EXAPI int isf_db_update_has_option_by_appid(const char *appid, bool has_option);
 EXAPI int isf_db_update_ime_info(ImeInfoDB *ime_db);
 EXAPI int isf_db_insert_ime_info(ImeInfoDB *ime_db);
 EXAPI int isf_db_delete_ime_info_by_pkgid(const char *pkgid);
+EXAPI int isf_db_delete_ime_info_by_appid(const char *appid);
 EXAPI int isf_db_delete_ime_info(void);
 
 #endif /* __ISF_QUERY_UTILITY_H__ */