From c11407911b658099180b358b4cb922b1a4ad76f1 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Sat, 26 Feb 2022 16:26:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BE=93=E5=85=A5=E6=B3=95?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=BC=B9=E6=A1=86=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- etc/para/src/para_handle.cpp | 2 +- .../src/js_input_method_engine_listener.cpp | 8 +--- .../src/js_keyboard_delegate_listener.cpp | 2 +- services/dialog/js/pages/index/index.js | 38 ------------------- services/include/input_method_property.h | 2 + services/src/input_method_property.cpp | 10 ++++- services/src/input_method_system_ability.cpp | 17 ++++++++- 7 files changed, 29 insertions(+), 50 deletions(-) diff --git a/etc/para/src/para_handle.cpp b/etc/para/src/para_handle.cpp index 962db0fc8..617a9b666 100644 --- a/etc/para/src/para_handle.cpp +++ b/etc/para/src/para_handle.cpp @@ -18,7 +18,7 @@ namespace OHOS { namespace MiscServices { const char *ParaHandle::DEFAULT_IME_KEY = "persist.sys.default_ime"; - const char *ParaHandle::DEFAULT_IME_NAME = "com.example.kikakeyboard/com.example.kikakeyboard.ServiceExtAbility"; + const char *ParaHandle::DEFAULT_IME_NAME = "com.example.kikakeyboard/ServiceExtAbility"; bool ParaHandle::SetDefaultIme(int32_t userId, const std::string &imeName) { if (userId != main_userId) { diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp index 429a08a45..641ba20f9 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp @@ -166,13 +166,7 @@ namespace MiscServices { std::lock_guard lock(mMutex); IMSA_HILOGI("JsInputMethodEngineListener::OnInputStop"); - NativeValue* nativeValue = engine_->CreateObject(); - NativeObject* object = ConvertNativeValueTo(nativeValue); - if (object == nullptr) { - IMSA_HILOGI("Failed to convert rect to jsObject"); - return; - } - object->SetProperty("imeId", CreateJsValue(*engine_, imeId)); + NativeValue* nativeValue = CreateJsValue(*engine_, imeId); NativeValue* argv[] = {nativeValue}; std::string methodName = "inputStop"; diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp index b5118fdc5..f8e5b9a2b 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp @@ -103,7 +103,7 @@ namespace MiscServices { } bool JsKeyboardDelegateListener::CallJsMethodReturnBool(std::string methodName, - NativeValue* const* argv, size_t argc) + NativeValue* const* argv, size_t argc) { IMSA_HILOGI("JsKeyboardDelegateListener::CallJsMethodReturnBool"); if (engine_ == nullptr) { diff --git a/services/dialog/js/pages/index/index.js b/services/dialog/js/pages/index/index.js index b2dbfba0a..bce8ed683 100644 --- a/services/dialog/js/pages/index/index.js +++ b/services/dialog/js/pages/index/index.js @@ -1,5 +1,4 @@ import router from '@ohos.router' -import resourceManager from '@ohos.resourceManager'; export default { data: { @@ -8,7 +7,6 @@ export default { onInit() { this.dialogTitle = this.$t('strings.dialogTitle'); this.setIme = this.$t('strings.setIme'); - this.initString() }, changeDefaultIme(ime) { console.info('ImsaKit-dialog changeDefaultIme: ' + ime); @@ -18,40 +16,4 @@ export default { console.info('ImsaKit-dialog startImeSetting'); callNativeHandler("EVENT_START_IME_SETTING", ""); }, - initString() { - for (var i = 0; i < this.imeList.length; i++) { - let bundle = this.imeList[i].ime; - console.info('ImsaKit-dialog initString bundle ' + bundle); - let index = bundle.indexOf("/"); - let pn = bundle.substring(0, index); - let labelId = Number(this.imeList[i].labelId); - let discriptionId = Number(this.imeList[i].discriptionId); - resourceManager.getResourceManager(pn).then(mgr => { - mgr.getString(labelId).then(value => { - this.updateLabelData(bundle, value, ''); - }).catch(error => { - console.info("ImsaKit-dialog initString resource getString error:" + error); - }) - mgr.getString(discriptionId).then(value => { - this.updateLabelData(bundle, '', value); - }).catch(error => { - console.info("ImsaKit-dialog initString resource getString error:" + error); - }) - }).catch(error => { - console.info("ImsaKit-dialog initString getResourceManager error:" + error); - }); - } - }, - updateLabelData(bundle, label, discription) { - for (var i = 0; i < this.imeList.length; i++) { - if (this.imeList[i].ime == bundle) { - if (label != '') { - this.imeList[i].label = label; - } - if (discription != '') { - this.imeList[i].discription = discription; - } - } - } - } } diff --git a/services/include/input_method_property.h b/services/include/input_method_property.h index ab02eb466..c87be3eb4 100644 --- a/services/include/input_method_property.h +++ b/services/include/input_method_property.h @@ -33,6 +33,8 @@ namespace MiscServices { std::vector mTypes; int32_t labelId; int32_t descriptionId; + std::u16string label; + std::u16string description; InputMethodProperty(); ~InputMethodProperty(); diff --git a/services/src/input_method_property.cpp b/services/src/input_method_property.cpp index a5581a193..d15f7094a 100644 --- a/services/src/input_method_property.cpp +++ b/services/src/input_method_property.cpp @@ -47,6 +47,8 @@ namespace MiscServices { mDefaultImeId = property.mDefaultImeId; labelId = property.labelId; descriptionId = property.descriptionId; + label = property.label; + description = property.description; for (int i = 0; i < (int)mTypes.size(); i++) { KeyboardType *type = new KeyboardType(*property.mTypes[i]); @@ -71,6 +73,8 @@ namespace MiscServices { mDefaultImeId = property.mDefaultImeId; labelId = property.labelId; descriptionId = property.descriptionId; + label = property.label; + description = property.description; for (int i = 0; i < (int)mTypes.size(); i++) { KeyboardType *type = new KeyboardType(*property.mTypes[i]); @@ -93,7 +97,9 @@ namespace MiscServices { && parcel.WriteBool(isSystemIme) && parcel.WriteInt32(mDefaultImeId) && parcel.WriteInt32(labelId) - && parcel.WriteInt32(descriptionId))) + && parcel.WriteInt32(descriptionId) + && parcel.WriteString16(label) + && parcel.WriteString16(description))) return false; int32_t size = (int32_t)mTypes.size(); parcel.WriteInt32(size); @@ -122,6 +128,8 @@ namespace MiscServices { info->mDefaultImeId = parcel.ReadInt32(); info->labelId = parcel.ReadInt32(); info->descriptionId = parcel.ReadInt32(); + info->label = parcel.ReadString16(); + info->description = parcel.ReadString16(); int32_t size = parcel.ReadInt32(); if (size == 0) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 6b2cd4e07..c68f2567d 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -30,6 +30,7 @@ #include "application_info.h" #include "common_event_support.h" #include "im_common_event_manager.h" +#include "resource_manager.h" namespace OHOS { namespace MiscServices { @@ -387,12 +388,24 @@ namespace MiscServices { return ErrorCode::ERROR_STATUS_UNKNOWN_ERROR; } for (auto extension : extensionInfos) { + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + if (resourceManager == nullptr) { + IMSA_HILOGI("InputMethodSystemAbility::listInputMethodByUserId resourcemanager is nullptr"); + break; + } AppExecFwk::ApplicationInfo applicationInfo = extension.applicationInfo; InputMethodProperty *property = new InputMethodProperty(); property->mPackageName = Str8ToStr16(extension.bundleName); property->mAbilityName = Str8ToStr16(extension.name); property->labelId = applicationInfo.labelId; property->descriptionId = applicationInfo.descriptionId; + resourceManager->AddResource(extension.resourcePath.c_str()); + std::string labelString; + resourceManager->GetStringById(applicationInfo.labelId, labelString); + property->label = Str8ToStr16(labelString); + std::string descriptionString; + resourceManager->GetStringById(applicationInfo.descriptionId, descriptionString); + property->description = Str8ToStr16(descriptionString); properties->push_back(property); } return ErrorCode::NO_ERROR; @@ -876,8 +889,8 @@ namespace MiscServices { params += "\"discriptionId\": \"" + std::to_string(property->descriptionId) + "\","; std::string isDefaultIme = defaultIme == imeId ? "true" : "false"; params += "\"isDefaultIme\": \"" + isDefaultIme + "\","; - params += "\"label\": \"\","; - params += "\"discription\": \"\""; + params += "\"label\": \"" + Str16ToStr8(property->label) + "\","; + params += "\"discription\": \"" + Str16ToStr8(property->description) + "\""; } params += "}]}"; -- Gitee