From 3f382750a3d3be7fd47c12040e88836cdd1b5635 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 24 Aug 2022 20:08:57 +0900 Subject: [PATCH] Support to get IME setting using metadata Change-Id: Ibd4af2b941b942fec483057b2a5236069ab7832d --- ism/src/isf_pkg.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/ism/src/isf_pkg.cpp b/ism/src/isf_pkg.cpp index 0d4cc6f..22664b8 100644 --- a/ism/src/isf_pkg.cpp +++ b/ism/src/isf_pkg.cpp @@ -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 &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(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(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!"); -- 2.7.4