diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 99af3ca..59de7ba 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -75,7 +75,7 @@ namespace MiscServices { int32_t GetInputPattern(); void HideCurrentInput(); void SetCallingWindow(uint32_t windowId); - int32_t SwitchInputMethod(InputMethodProperty *target); + int32_t SwitchInputMethod(const InputMethodProperty &target); private: InputMethodController(); diff --git a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h index e1fd29c..4575ab4 100644 --- a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -56,7 +56,7 @@ namespace MiscServices { int32_t listInputMethodEnabled(std::vector *properties) override; int32_t listInputMethod(std::vector *properties) override; int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) override; - int32_t SwitchInputMethod(InputMethodProperty* target); + int32_t SwitchInputMethod(const InputMethodProperty &target); private: static inline BrokerDelegator delegator_; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 02f525a..f0ec0b8 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -444,7 +444,7 @@ using namespace MessageID; agent->SetCallingWindow(windowId); } - int32_t InputMethodController::SwitchInputMethod(InputMethodProperty *target) + int32_t InputMethodController::SwitchInputMethod(const InputMethodProperty &target) { IMSA_HILOGI("InputMethodController::SwitchInputMethod"); if (!mImms) { diff --git a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp index d111a8a..0d2ef50 100644 --- a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -438,7 +438,7 @@ namespace MiscServices { return NO_ERROR; } - int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(InputMethodProperty* target) + int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(const InputMethodProperty &target) { IMSA_HILOGI("InputMethodSystemAbilityProxy::SwitchInputMethod"); MessageParcel data, reply; @@ -448,14 +448,12 @@ namespace MiscServices { return ERROR_EX_PARCELABLE; } - if (!target->Marshalling(data)) { + if (!target.Marshalling(data)) { IMSA_HILOGE("InputMethodSystemAbilityProxy::switchInputMethod Failed to marshall target to data!"); - delete target; return ERROR_IME_PROPERTY_MARSHALL; } - delete target; auto ret = Remote()->SendRequest(SWITCH_INPUT_METHOD, data, reply, option); - if (ret != NO_ERROR) { + if (ret != 0) { return ERROR_STATUS_FAILED_TRANSACTION; } ret = reply.ReadInt32(); diff --git a/interfaces/kits/js/napi/inputmethod/src/js_input_method_registry.cpp b/interfaces/kits/js/napi/inputmethod/src/js_input_method_registry.cpp index a885001..f7aeb2e 100644 --- a/interfaces/kits/js/napi/inputmethod/src/js_input_method_registry.cpp +++ b/interfaces/kits/js/napi/inputmethod/src/js_input_method_registry.cpp @@ -96,14 +96,14 @@ namespace MiscServices { return engine.CreateUndefined(); } - InputMethodProperty *target = new InputMethodProperty(); + InputMethodProperty target; NativeObject *object = ConvertNativeValueTo(info.argv[0]); if (object == nullptr) { IMSA_HILOGE("JsInputMethodRegistry::OnSwitchInputMethod Failed to get object"); return engine.CreateUndefined(); } - if (!GetInputMethodPropertyFromJs(engine, object, *target)) { + if (!GetInputMethodPropertyFromJs(engine, object, target)) { return engine.CreateUndefined(); } 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 62c1af5..b134ad1 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 @@ -37,19 +37,18 @@ namespace MiscServices { std::lock_guard lock(mMutex); std::shared_ptr callbackRef(engine_->CreateReference(jsListenerObject, 1)); if (callbackRef == nullptr) { - IMSA_HILOGI("JsInputMethodEngineListener::AddCallback fail, callbackRef is nullptr."); + IMSA_HILOGI("JsInputMethodEngineListener::AddCallback fail, callbackRef is nullptr"); return; } std::lock_guard lk(mapMutex); jsCbMap_[type].push_back(callbackRef); - IMSA_HILOGI("JsInputMethodEngineListener::AddCallback success"); - IMSA_HILOGI("jsCbMap_ size: %{public}d, and type[%{public}s] size: %{public}d!", + IMSA_HILOGI("AddCallback success! jsCbMap_ size: %{public}d, and type[%{public}s] size: %{public}d", static_cast(jsCbMap_.size()), type.c_str(), static_cast(jsCbMap_[type].size())); } void JsInputMethodEngineListener::UnregisterAllListenerWithType(std::string type) { - IMSA_HILOGI("JsInputMethodEngineListener::UnregisterAllListenerWithType : %{public}s.", type.c_str()); + IMSA_HILOGI("JsInputMethodEngineListener::UnregisterAllListenerWithType : %{public}s", type.c_str()); // should do type check std::lock_guard lk(mapMutex); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { @@ -102,8 +101,8 @@ namespace MiscServices { } for (auto iter : jsCbMap_[methodName]) { if (iter == nullptr) { - IMSA_HILOGE("JsInputMethodEngineListener::CallJsMethod iter is null!"); - return; + IMSA_HILOGE("JsInputMethodEngineListener::CallJsMethod iter is null"); + continue; } engine_->CallFunction(engine_->CreateUndefined(), iter->Get(), argv, argc); } diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 2175e97..fd85779 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -290,7 +290,7 @@ namespace MiscServices { want.SetElementName(imeId.substr(0, pos), imeId.substr(pos + 1)); int32_t result = abms->StartAbility(want); if (result) { - IMSA_HILOGE("InputMethodSystemAbility::StartInputService fail."); + IMSA_HILOGE("InputMethodSystemAbility::StartInputService failed, result = %{public}d", result); isStartSuccess = false; } else { IMSA_HILOGE("InputMethodSystemAbility::StartInputService success."); @@ -990,9 +990,7 @@ namespace MiscServices { } std::string defaultIme = ParaHandle::GetDefaultIme(userId_); - std::string targetIme; - std::string imeId = Str16ToStr8(target->mPackageName) + "/" + Str16ToStr8(target->mAbilityName); - targetIme += imeId; + std::string targetIme = Str16ToStr8(target->mPackageName) + "/" + Str16ToStr8(target->mAbilityName); IMSA_HILOGI("InputMethodSystemAbility::OnSwitchInputMethod DefaultIme : %{public}s, TargetIme : %{public}s", defaultIme.c_str(), targetIme.c_str()); if (defaultIme != targetIme) { @@ -1004,9 +1002,11 @@ namespace MiscServices { } bool setResult = ParaHandle::SetDefaultIme(userId_, targetIme); if (setResult) { - IMSA_HILOGI("SetDefaultIme Successfully."); + IMSA_HILOGI("InputMethodSystemAbility::OnSwitchInputMethod SetDefaultIme Successfully."); } else { - IMSA_HILOGI("SetDefaultIme Failed."); + IMSA_HILOGI("InputMethodSystemAbility::OnSwitchInputMethod SetDefaultIme Failed. setResult = " + "%{public}d", + setResult); return ErrorCode::ERROR_STATUS_PERMISSION_DENIED; } } else {