Support to get IME setting using metadata 53/280153/1
authorInHong Han <inhong1.han@samsung.com>
Wed, 24 Aug 2022 11:08:57 +0000 (20:08 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 24 Aug 2022 11:08:57 +0000 (20:08 +0900)
Change-Id: Ibd4af2b941b942fec483057b2a5236069ab7832d

ism/src/isf_pkg.cpp

index 0d4cc6f..22664b8 100644 (file)
@@ -50,6 +50,7 @@
 using namespace scim;
 
 static String ime_setting_app;
+static bool setting_app_changed;
 
 #ifdef HAVE_PKGMGR_INFO
 /**
@@ -313,6 +314,29 @@ int isf_pkg_select_all_ime_info_db(std::vector<ImeInfoDB> &ime_info)
 
 #ifdef HAVE_PKGMGR_INFO
 /**
+ * @brief Finds ime_setting with specific metadata
+ *
+ * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative
+ */
+static int _metadata_func (const char *key, const char *value, void *user_data)
+{
+    if (!user_data) {
+        LOGW ("user_data is null!");
+        return -1;
+    }
+
+    String ime_pkgid = String(static_cast<char *>(user_data));
+    LOGD ("key : %s, value : %s, ime pkg id : %s", key, value, ime_pkgid.c_str ());
+
+    if (strncmp (key, "ime-package-id", strlen (key)) == 0 && strncmp (value, ime_pkgid.c_str (), strlen (value)) == 0) {
+        setting_app_changed = true;
+        return -1;
+    }
+
+    return 0;
+}
+
+/**
  * @brief Finds appid with specific category
  *
  * @return 0 if success, negative value(<0) if fail. Callback is not called if return value is negative
@@ -346,6 +370,24 @@ static int _find_ime_setting (const pkgmgrinfo_appinfo_h handle, void *user_data
             ime_setting_app = String (ime_setting_appid);
             return -1;
         }
+        else {
+            pkgmgrinfo_appinfo_h appinfo_handle = NULL;
+            ret = pkgmgrinfo_appinfo_get_appinfo(ime_setting_appid, &appinfo_handle);
+            if (ret != PMINFO_R_OK)
+                return 0;
+            setting_app_changed = false;
+            ret = pkgmgrinfo_appinfo_foreach_metadata (appinfo_handle, _metadata_func, static_cast<char *>(user_data));
+            if (ret != PMINFO_R_OK) {
+                pkgmgrinfo_appinfo_destroy_appinfo(appinfo_handle);
+                return 0;
+            }
+            pkgmgrinfo_appinfo_destroy_appinfo(appinfo_handle);
+
+            if (setting_app_changed) {
+                ime_setting_app = String (ime_setting_appid);
+                return -1;
+            }
+        }
     }
     else {
         LOGW ("pkgmgrinfo_appinfo_get_appid failed!");