diff --git a/common/include/itypes_util.h b/common/include/itypes_util.h index 9c9d57eaf5c0abb5a6ce6e41e512bca944c0e59f..003070d5ed7e8654e7e6e02e44e70c20f2af2250 100644 --- a/common/include/itypes_util.h +++ b/common/include/itypes_util.h @@ -20,13 +20,8 @@ #include #include -#include "element_name.h" #include "global.h" -#include "input_client_info.h" -#include "input_window_info.h" #include "message_parcel.h" -#include "panel_info.h" -#include "sys_panel_status.h" namespace OHOS { namespace MiscServices { @@ -41,10 +36,16 @@ public: static bool Marshalling(const std::string &input, MessageParcel &data); static bool Unmarshalling(std::string &output, MessageParcel &data); + static bool Marshal(const sptr &input, Parcel &data); + static bool Unmarshal(sptr &output, Parcel &data); + template static bool Marshal(MessageParcel &parcel, const T &first, const Types &...others); template static bool Unmarshal(MessageParcel &parcel, T &first, Types &...others); + + template static bool MarshalVector(const std::vector &in, Parcel &out); + template static bool UnmarshalVector(Parcel &in, std::vector &out); }; template @@ -64,6 +65,47 @@ bool ITypesUtil::Unmarshal(MessageParcel &parcel, T &first, Types &...others) } return Unmarshal(parcel, others...); } + +template bool ITypesUtil::MarshalVector(const std::vector &in, Parcel &out) +{ + auto size = in.size(); + if (size > INT32_MAX) { + return false; + } + if (!out.WriteInt32(static_cast(size))) { + return false; + } + for (const auto &it : in) { + if (!it.Marshalling(out)) { + return false; + } + } + return true; +} + +template bool ITypesUtil::UnmarshalVector(Parcel &in, std::vector &out) +{ + int32_t len = 0; + if (!in.ReadInt32(len)) { + return false; + } + if (len < 0) { + return false; + } + auto size = static_cast(len); + if (size > out.max_size()) { + return false; + } + out.clear(); + for (size_t i = 0; i < size; ++i) { + T value; + if (!value.ReadFromParcel(in)) { + return false; + } + out.emplace_back(std::move(value)); + } + return true; +} } // namespace MiscServices } // namespace OHOS #endif diff --git a/common/src/itypes_util.cpp b/common/src/itypes_util.cpp index 4dbfd4ae498373931a3d9be1d9801b79d7263475..d4a03b15d7a077296064f423d2b63512ff3179e7 100644 --- a/common/src/itypes_util.cpp +++ b/common/src/itypes_util.cpp @@ -49,5 +49,16 @@ bool ITypesUtil::Unmarshalling(std::string &output, MessageParcel &data) { return data.ReadString(output); } + +bool ITypesUtil::Marshal(const sptr &input, Parcel &data) +{ + return (static_cast(&data))->WriteRemoteObject(input); +} + +bool ITypesUtil::Unmarshal(sptr &output, Parcel &data) +{ + output = (static_cast(&data))->ReadRemoteObject(); + return true; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/common/include/response_data_util.h b/frameworks/native/common/include/response_data_util.h deleted file mode 100644 index f25ab7cbd6f9aed573425270bab69f75afbdbba1..0000000000000000000000000000000000000000 --- a/frameworks/native/common/include/response_data_util.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IMF_FRAMEWORKS_RESPONSE_DATA_UTIL_H -#define IMF_FRAMEWORKS_RESPONSE_DATA_UTIL_H - -#include -#include - -#include "input_method_property.h" -#include "input_method_utils.h" - -namespace OHOS { -namespace MiscServices { -inline constexpr size_t MAX_SIZE = 102400; -class ResponseDataUtil { -public: - template static bool Unmarshall(Parcel &in, std::vector &out) - { - int32_t len = 0; - if (!in.ReadInt32(len)) { - return false; - } - if (len < 0) { - return false; - } - auto size = static_cast(len); - if (size > MAX_SIZE) { - return false; - } - out.clear(); - for (size_t i = 0; i < size; ++i) { - T value; - if (!value.ReadFromParcel(in)) { - return false; - } - out.push_back(value); - } - return true; - } - - template static bool Marshall(const std::vector &in, Parcel &out) - { - auto size = in.size(); - if (size > INT32_MAX) { - return false; - } - if (!out.WriteInt32(static_cast(size))) { - return false; - } - for (const auto &it : in) { - if (!it.Marshalling(out)) { - return false; - } - } - return true; - } -}; -} // namespace MiscServices -} // namespace OHOS - -#endif // IMF_FRAMEWORKS_RESPONSE_DATA_UTIL_H diff --git a/frameworks/native/common/include/service_response_data.h b/frameworks/native/common/include/service_response_data.h index 31c564f1202f9a79c46669845eccd74b288fb295..7710fbd0dc4ee48876270d2634f3aa5809d55425 100644 --- a/frameworks/native/common/include/service_response_data.h +++ b/frameworks/native/common/include/service_response_data.h @@ -23,18 +23,25 @@ #include "input_method_property.h" #include "input_method_utils.h" -#include "response_data_util.h" +#include "itypes_util.h" namespace OHOS { namespace MiscServices { -using RequestId = uint32_t; -using RequestFunc = std::function; +using RequestFunc = std::function; struct StartInputResponse : public Parcelable { sptr agent{ nullptr }; int64_t pid{ 0 }; std::string bundleName; - void Set(sptr imeAgent, int64_t imePid, const std::string &imeBundleName); + StartInputResponse() = default; + StartInputResponse(sptr agent, int64_t pid, const std::string &bundleName) + : agent(agent), pid(pid), bundleName(bundleName) + { + } + bool operator==(const StartInputResponse &response) const + { + return (agent == response.agent && pid == response.pid && bundleName == response.bundleName); + } bool ReadFromParcel(Parcel &in); bool Marshalling(Parcel &out) const override; static StartInputResponse *Unmarshalling(Parcel &in); @@ -44,7 +51,16 @@ struct InputStartInfo : public Parcelable { bool isInputStart{ false }; uint32_t callingWindowId{ 0 }; int32_t requestKeyboardReason{ 0 }; - void Set(bool inputStart, uint32_t id, int32_t reason); + InputStartInfo() = default; + InputStartInfo(bool isInputStart, uint32_t callingWindowId, int32_t requestKeyboardReason) + : isInputStart(isInputStart), callingWindowId(callingWindowId), requestKeyboardReason(requestKeyboardReason) + { + } + bool operator==(const InputStartInfo &info) const + { + return isInputStart == info.isInputStart && callingWindowId == info.callingWindowId && + requestKeyboardReason == info.requestKeyboardReason; + } bool ReadFromParcel(Parcel &in); bool Marshalling(Parcel &out) const override; static InputStartInfo *Unmarshalling(Parcel &in); @@ -130,9 +146,9 @@ struct ServiceResponseWriter { { result = out.WriteUint64(val); } - void operator()(sptr val) + void operator()(const sptr &val) { - result = static_cast(&out)->WriteRemoteObject(val); + result = ITypesUtil::Marshal(val, out); } void operator()(const Property &val) { @@ -140,7 +156,7 @@ struct ServiceResponseWriter { } void operator()(const std::vector &val) { - result = ResponseDataUtil::Marshall(val, out); + result = ITypesUtil::MarshalVector(val, out); } void operator()(const SubProperty &val) { @@ -148,7 +164,7 @@ struct ServiceResponseWriter { } void operator()(const std::vector &val) { - result = ResponseDataUtil::Marshall(val, out); + result = ITypesUtil::MarshalVector(val, out); } void operator()(const StartInputResponse &val) { diff --git a/frameworks/native/common/src/service_response_data.cpp b/frameworks/native/common/src/service_response_data.cpp index fd2f737183aa316e3b5a34447a3551f21eb50bd5..b087d27e76e038acdafbd8007844965a94e324f9 100644 --- a/frameworks/native/common/src/service_response_data.cpp +++ b/frameworks/native/common/src/service_response_data.cpp @@ -25,7 +25,11 @@ const std::unordered_map ServiceResponseDataInner::UNMAR { static_cast(TYPE_INT64), [](Parcel &in, ServiceResponseData &out) { out = in.ReadInt64(); } }, { static_cast(TYPE_UINT64), [](Parcel &in, ServiceResponseData &out) { out = in.ReadUint64(); } }, { static_cast(TYPE_REMOTE_OBJECT), - [](Parcel &in, ServiceResponseData &out) { out = static_cast(&in)->ReadRemoteObject(); } }, + [](Parcel &in, ServiceResponseData &out) { + sptr value; + ITypesUtil::Unmarshal(value, in); + out = value; + } }, { static_cast(TYPE_PROPERTY), [](Parcel &in, ServiceResponseData &out) { Property value; @@ -35,7 +39,7 @@ const std::unordered_map ServiceResponseDataInner::UNMAR { static_cast(TYPE_PROPERTIES), [](Parcel &in, ServiceResponseData &out) { std::vector value; - ResponseDataUtil::Unmarshall(in, value); + ITypesUtil::UnmarshalVector(in, value); out = value; } }, { static_cast(TYPE_SUB_PROPERTY), @@ -47,7 +51,7 @@ const std::unordered_map ServiceResponseDataInner::UNMAR { static_cast(TYPE_SUB_PROPERTIES), [](Parcel &in, ServiceResponseData &out) { std::vector value; - ResponseDataUtil::Unmarshall(in, value); + ITypesUtil::UnmarshalVector(in, value); out = value; } }, { static_cast(TYPE_START_INPUT_RESPONSE), @@ -78,11 +82,7 @@ bool ServiceResponseDataInner::ReadFromParcel(Parcel &in) if (iter == UNMARSHAL_FUNCTION_MAP.end()) { return false; } - auto handler = iter->second; - if (handler == nullptr) { - return false; - } - handler(in, data); + iter->second(in, data); return true; } @@ -123,17 +123,9 @@ ServiceResponseDataInner *ServiceResponseDataInner::Unmarshalling(Parcel &in) return data; } -void StartInputResponse::Set(sptr imeAgent, int64_t imePid, const std::string &imeBundleName) -{ - agent = imeAgent; - pid = imePid; - bundleName = imeBundleName; -} - bool StartInputResponse::ReadFromParcel(Parcel &in) { - agent = (static_cast(&in))->ReadRemoteObject(); - if (agent == nullptr) { + if (!ITypesUtil::Unmarshal(agent, in)) { return false; } if (!in.ReadInt64(pid)) { @@ -147,7 +139,7 @@ bool StartInputResponse::ReadFromParcel(Parcel &in) bool StartInputResponse::Marshalling(Parcel &out) const { - if (!(static_cast(&out))->WriteRemoteObject(agent)) { + if (!ITypesUtil::Marshal(agent, out)) { return false; } if (!out.WriteInt64(pid)) { @@ -172,13 +164,6 @@ StartInputResponse *StartInputResponse::Unmarshalling(Parcel &in) return data; } -void InputStartInfo::Set(bool inputStart, uint32_t id, int32_t reason) -{ - isInputStart = inputStart; - callingWindowId = id; - requestKeyboardReason = reason; -} - bool InputStartInfo::ReadFromParcel(Parcel &in) { if (!in.ReadBool(isInputStart)) { diff --git a/frameworks/native/inputmethod_ability/include/ima_service_proxy.h b/frameworks/native/inputmethod_ability/include/ima_service_proxy.h index f0bd018bbd61909615880856f726659bcb4bf332..95a6b54bb698012d59f79fe1317d6864a5ef7af6 100644 --- a/frameworks/native/inputmethod_ability/include/ima_service_proxy.h +++ b/frameworks/native/inputmethod_ability/include/ima_service_proxy.h @@ -45,7 +45,7 @@ public: template int32_t SendRequest(const RequestFunc &request, ResultType &resultValue, int64_t timeout); - void OnResponse(RequestId id, const ServiceResponse &responseData); + void OnResponse(uint32_t id, const ServiceResponse &responseData); void RemoveDeathRecipient(); @@ -59,19 +59,19 @@ private: private: void Init(); - RequestId GetNextRequestId(); - int32_t SendRequestInner(const RequestFunc &request, ServiceResponseData &responseData, int64_t timeout); + uint32_t GetNextRequestId(); + int32_t SendRequestInner(const RequestFunc &request, ServiceResponse &response, int64_t timeout); - void AddRequest(RequestId id, PendingRequest pendingRequest); - void RemoveRequest(RequestId requestId); - void RemoveUnresponsiveRequest(RequestId requestId); + void AddRequest(uint32_t id, PendingRequest pendingRequest); + void RemoveRequest(uint32_t requestId); + void RemoveUnresponsiveRequest(uint32_t requestId); void ClearRequest(); - std::atomic currentRequestId_{ 0 }; + std::atomic currentRequestId_{ 0 }; std::atomic isInterrupted_{ false }; std::mutex requestsMutex_{}; - std::unordered_map pendingRequests_; + std::unordered_map pendingRequests_; sptr responseChannelStub_{ nullptr }; }; diff --git a/frameworks/native/inputmethod_ability/src/ima_service_proxy.cpp b/frameworks/native/inputmethod_ability/src/ima_service_proxy.cpp index 1e9e35f241d8db5cf6eb5cf83432776cc7404d64..1e6b00ef8b761db84343e8c053659b11b7f5ed51 100644 --- a/frameworks/native/inputmethod_ability/src/ima_service_proxy.cpp +++ b/frameworks/native/inputmethod_ability/src/ima_service_proxy.cpp @@ -15,6 +15,8 @@ #include "ima_service_proxy.h" +#include + #include "ima_response_channel_impl.h" #include "input_method_ability.h" #include "on_demand_start_stop_sa.h" @@ -44,13 +46,13 @@ void ImaServiceProxy::Init() responseChannelStub_ = channel; } -RequestId ImaServiceProxy::GetNextRequestId() +uint32_t ImaServiceProxy::GetNextRequestId() { static std::atomic seqId{ 1 }; return seqId.fetch_add(1, std::memory_order_seq_cst); } -void ImaServiceProxy::OnResponse(RequestId id, const ServiceResponse &responseData) +void ImaServiceProxy::OnResponse(uint32_t id, const ServiceResponse &responseData) { std::lock_guard lock(requestsMutex_); auto iter = pendingRequests_.find(id); @@ -101,53 +103,29 @@ void ImaServiceProxy::RemoveDeathRecipient() abilityManager_ = nullptr; } -int32_t ImaServiceProxy::SendRequest(const RequestFunc &request, int64_t timeout) +template +int32_t ImaServiceProxy::SendRequest(const RequestFunc &request, ResultType &resultValue, int64_t timeout) { - if (request == nullptr) { - IMSA_HILOGE("request is nullptr"); - return ErrorCode::ERROR_IMC_NULLPTR; - } - if (isInterrupted_.load()) { - IMSA_HILOGW("request is interrupted"); - return ErrorCode::ERROR_REQUEST_INTERRUPTED; - } - PendingRequest pendingRequest; - RequestId id = GetNextRequestId(); - auto future = pendingRequest.promise.get_future(); - AddRequest(id, std::move(pendingRequest)); - - // send request - int32_t ret = request(id); + ServiceResponse response; + int32_t ret = SendRequestInner(request, response, timeout); if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("request failed, ret: %{public}d", ret); - RemoveUnresponsiveRequest(id); return ret; } - - if (isInterrupted_.load()) { - IMSA_HILOGW("request is interrupted"); - RemoveUnresponsiveRequest(id); - return ErrorCode::ERROR_REQUEST_INTERRUPTED; - } - // wait till timeout - if (future.wait_for(std::chrono::milliseconds(timeout)) != std::future_status::ready) { - IMSA_HILOGE("service handle timeout"); - RemoveUnresponsiveRequest(id); - return ErrorCode::ERROR_IMC_SERVICE_RESPONSE_TIMEOUT; + ServiceResponseData responseData = response.responseData; + if (!VariantUtil::GetValue(responseData, resultValue)) { + IMSA_HILOGE("failed to get result value"); + return ErrorCode::ERROR_INVALID_VARIANT_TYPE; } + return ErrorCode::NO_ERROR; +} - // handle response - ServiceResponse response = future.get(); - ret = response.result; - RemoveRequest(id); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("task failed"); - } - return ret; +int32_t ImaServiceProxy::SendRequest(const RequestFunc &request, int64_t timeout) +{ + ServiceResponse response; + return SendRequestInner(request, response, timeout); } -int32_t ImaServiceProxy::SendRequestInner( - const RequestFunc &request, ServiceResponseData &responseData, int64_t timeout) +int32_t ImaServiceProxy::SendRequestInner(const RequestFunc &request, ServiceResponse &response, int64_t timeout) { if (request == nullptr) { IMSA_HILOGE("request is nullptr"); @@ -159,7 +137,7 @@ int32_t ImaServiceProxy::SendRequestInner( } PendingRequest pendingRequest; - RequestId id = GetNextRequestId(); + uint32_t id = GetNextRequestId(); auto future = pendingRequest.promise.get_future(); AddRequest(id, std::move(pendingRequest)); @@ -184,29 +162,13 @@ int32_t ImaServiceProxy::SendRequestInner( } // handle response - ServiceResponse response = future.get(); + response = future.get(); ret = response.result; RemoveRequest(id); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("task failed"); return ret; } - responseData = response.responseData; - return ErrorCode::NO_ERROR; -} - -template -int32_t ImaServiceProxy::SendRequest(const RequestFunc &request, ResultType &resultValue, int64_t timeout) -{ - ServiceResponseData responseData; - int32_t ret = SendRequestInner(request, responseData, timeout); - if (ret != ErrorCode::NO_ERROR) { - return ret; - } - if (!VariantUtil::GetValue(responseData, resultValue)) { - IMSA_HILOGE("failed to get result value"); - return ErrorCode::ERROR_INVALID_VARIANT_TYPE; - } return ErrorCode::NO_ERROR; } @@ -220,34 +182,34 @@ void ImaServiceProxy::OnRemoteSaDied(const wptr &remote) } } -void ImaServiceProxy::AddRequest(RequestId id, PendingRequest pendingRequest) +void ImaServiceProxy::AddRequest(uint32_t id, PendingRequest pendingRequest) { std::lock_guard lock(requestsMutex_); pendingRequests_[id] = std::move(pendingRequest); currentRequestId_.store(id); - IMSA_HILOGD("ima request[%{public}u] added", static_cast(id)); + IMSA_HILOGD("ima request[%{public}u] added", id); } -void ImaServiceProxy::RemoveRequest(RequestId requestId) +void ImaServiceProxy::RemoveRequest(uint32_t requestId) { std::lock_guard lock(requestsMutex_); pendingRequests_.erase(requestId); currentRequestId_.store(0); - IMSA_HILOGD("ima request[%{public}u] removed", static_cast(requestId)); + IMSA_HILOGD("ima request[%{public}u] removed", requestId); } -void ImaServiceProxy::RemoveUnresponsiveRequest(RequestId requestId) +void ImaServiceProxy::RemoveUnresponsiveRequest(uint32_t requestId) { std::lock_guard lock(requestsMutex_); auto iter = pendingRequests_.find(requestId); if (iter == pendingRequests_.end()) { - IMSA_HILOGD("ima request[%{public}u] already removed", static_cast(requestId)); + IMSA_HILOGD("ima request[%{public}u] already removed", requestId); return; } ServiceResponse response = { .result = ErrorCode::ERROR_IMC_SERVICE_RESPONSE_TIMEOUT }; iter->second.promise.set_value(response); pendingRequests_.erase(iter); - IMSA_HILOGD("ima request[%{public}u] removed", static_cast(requestId)); + IMSA_HILOGD("ima request[%{public}u] removed", requestId); } void ImaServiceProxy::ClearRequest() diff --git a/frameworks/native/inputmethod_controller/include/imc_service_proxy.h b/frameworks/native/inputmethod_controller/include/imc_service_proxy.h index 5a4634dfed54806af1a3a5cc927de4f5ec755815..2a8edb94f1e2dc1b12fc2fe6b5e55970aa24d651 100644 --- a/frameworks/native/inputmethod_controller/include/imc_service_proxy.h +++ b/frameworks/native/inputmethod_controller/include/imc_service_proxy.h @@ -47,7 +47,7 @@ public: template int32_t SendRequest(const RequestFunc &request, ResultType &resultValue, int64_t timeout); - void OnResponse(RequestId id, const ServiceResponse &responseData); + void OnResponse(uint32_t id, const ServiceResponse &responseData); void RemoveDeathRecipient(); @@ -65,19 +65,19 @@ private: private: void Init(); - RequestId GetNextRequestId(); - int32_t SendRequestInner(const RequestFunc &request, ServiceResponseData &responseData, int64_t timeout); + uint32_t GetNextRequestId(); + int32_t SendRequestInner(const RequestFunc &request, ServiceResponse &response, int64_t timeout); - void AddRequest(RequestId id, PendingRequest pendingRequest); - void RemoveRequest(RequestId requestId); - void RemoveUnresponsiveRequest(RequestId requestId); + void AddRequest(uint32_t id, PendingRequest pendingRequest); + void RemoveRequest(uint32_t requestId); + void RemoveUnresponsiveRequest(uint32_t requestId); void ClearRequest(); - std::atomic currentRequestId_{ 0 }; + std::atomic currentRequestId_{ 0 }; std::atomic isInterrupted_{ false }; std::mutex requestsMutex_{}; - std::unordered_map pendingRequests_; + std::unordered_map pendingRequests_; sptr responseChannelStub_{ nullptr }; }; diff --git a/frameworks/native/inputmethod_controller/include/input_method_property.h b/frameworks/native/inputmethod_controller/include/input_method_property.h index b19d18a69b3a4dc28d313f8b377420ccc0f4cd2d..f3212c3ae6733212cb6cf5ea90e5dd59e029391b 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_property.h +++ b/frameworks/native/inputmethod_controller/include/input_method_property.h @@ -24,6 +24,10 @@ namespace OHOS { namespace MiscServices { struct Property : public Parcelable { + Property() = default; + Property(const std::string &name, const std::string &id) : name(name), id(id) + { + } std::string name; // the bundleName of inputMethod std::string id; // the extensionName of inputMethod std::string label; // the label of inputMethod @@ -82,6 +86,10 @@ struct Property : public Parcelable { }; struct SubProperty : public Parcelable { + SubProperty() = default; + SubProperty(const std::string name, const std::string &id) : name(name), id(id) + { + } std::string label; // the label of subtype uint32_t labelId = 0; // the labelId of subtype std::string name; // the bundleName of inputMethod diff --git a/frameworks/native/inputmethod_controller/src/imc_service_proxy.cpp b/frameworks/native/inputmethod_controller/src/imc_service_proxy.cpp index 035f00bb1e4fdf650525a457f78956b2ff7b330c..e2d4d066f30d22ca7b322aa01e0e62add155aac7 100644 --- a/frameworks/native/inputmethod_controller/src/imc_service_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/imc_service_proxy.cpp @@ -48,13 +48,13 @@ void ImcServiceProxy::Init() responseChannelStub_ = channel; } -RequestId ImcServiceProxy::GetNextRequestId() +uint32_t ImcServiceProxy::GetNextRequestId() { static std::atomic seqId{ 1 }; return seqId.fetch_add(1, std::memory_order_seq_cst); } -void ImcServiceProxy::OnResponse(RequestId id, const ServiceResponse &responseData) +void ImcServiceProxy::OnResponse(uint32_t id, const ServiceResponse &responseData) { std::lock_guard lock(requestsMutex_); auto iter = pendingRequests_.find(id); @@ -66,53 +66,29 @@ void ImcServiceProxy::OnResponse(RequestId id, const ServiceResponse &responseDa iter->second.promise.set_value(responseData); } -int32_t ImcServiceProxy::SendRequest(const RequestFunc &request, int64_t timeout) +template +int32_t ImcServiceProxy::SendRequest(const RequestFunc &request, ResultType &resultValue, int64_t timeout) { - if (request == nullptr) { - IMSA_HILOGE("request is nullptr"); - return ErrorCode::ERROR_IMC_NULLPTR; - } - if (isInterrupted_.load()) { - IMSA_HILOGW("request is interrupted"); - return ErrorCode::ERROR_REQUEST_INTERRUPTED; - } - PendingRequest pendingRequest; - RequestId id = GetNextRequestId(); - auto future = pendingRequest.promise.get_future(); - AddRequest(id, std::move(pendingRequest)); - - // send request - int32_t ret = request(id); + ServiceResponse response; + int32_t ret = SendRequestInner(request, response, timeout); if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("request failed, ret: %{public}d", ret); - RemoveUnresponsiveRequest(id); return ret; } - - if (isInterrupted_.load()) { - IMSA_HILOGW("request is interrupted"); - RemoveUnresponsiveRequest(id); - return ErrorCode::ERROR_REQUEST_INTERRUPTED; - } - // wait till timeout - if (future.wait_for(std::chrono::milliseconds(timeout)) != std::future_status::ready) { - IMSA_HILOGE("service handle timeout"); - RemoveUnresponsiveRequest(id); - return ErrorCode::ERROR_IMC_SERVICE_RESPONSE_TIMEOUT; + ServiceResponseData responseData = response.responseData; + if (!VariantUtil::GetValue(responseData, resultValue)) { + IMSA_HILOGE("failed to get result value"); + return ErrorCode::ERROR_INVALID_VARIANT_TYPE; } + return ErrorCode::NO_ERROR; +} - // handle response - ServiceResponse response = future.get(); - ret = response.result; - RemoveRequest(id); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("task failed"); - } - return ret; +int32_t ImcServiceProxy::SendRequest(const RequestFunc &request, int64_t timeout) +{ + ServiceResponse response; + return SendRequestInner(request, response, timeout); } -int32_t ImcServiceProxy::SendRequestInner( - const RequestFunc &request, ServiceResponseData &responseData, int64_t timeout) +int32_t ImcServiceProxy::SendRequestInner(const RequestFunc &request, ServiceResponse &response, int64_t timeout) { if (request == nullptr) { IMSA_HILOGE("request is nullptr"); @@ -124,7 +100,7 @@ int32_t ImcServiceProxy::SendRequestInner( } PendingRequest pendingRequest; - RequestId id = GetNextRequestId(); + uint32_t id = GetNextRequestId(); auto future = pendingRequest.promise.get_future(); AddRequest(id, std::move(pendingRequest)); @@ -149,33 +125,16 @@ int32_t ImcServiceProxy::SendRequestInner( } // handle response - ServiceResponse response = future.get(); + response = future.get(); ret = response.result; RemoveRequest(id); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("task failed"); return ret; } - responseData = response.responseData; return ErrorCode::NO_ERROR; } -template -int32_t ImcServiceProxy::SendRequest(const RequestFunc &request, ResultType &resultValue, int64_t timeout) -{ - ServiceResponseData responseData; - int32_t ret = SendRequestInner(request, responseData, timeout); - if (ret != ErrorCode::NO_ERROR) { - return ret; - } - if (!VariantUtil::GetValue(responseData, resultValue)) { - IMSA_HILOGE("failed to get result value"); - return ErrorCode::ERROR_INVALID_VARIANT_TYPE; - } - return ErrorCode::NO_ERROR; -} - - void ImcServiceProxy::OnRemoteSaDied(const wptr &remote) { hasRegistered_.store(false); @@ -247,7 +206,7 @@ void ImcServiceProxy::RemoveDeathRecipient() abilityManager_ = nullptr; } -void ImcServiceProxy::AddRequest(RequestId id, PendingRequest pendingRequest) +void ImcServiceProxy::AddRequest(uint32_t id, PendingRequest pendingRequest) { std::lock_guard lock(requestsMutex_); pendingRequests_[id] = std::move(pendingRequest); @@ -255,7 +214,7 @@ void ImcServiceProxy::AddRequest(RequestId id, PendingRequest pendingRequest) IMSA_HILOGD("imc request[%{public}u] added", static_cast(id)); } -void ImcServiceProxy::RemoveRequest(RequestId requestId) +void ImcServiceProxy::RemoveRequest(uint32_t requestId) { std::lock_guard lock(requestsMutex_); pendingRequests_.erase(requestId); @@ -263,7 +222,7 @@ void ImcServiceProxy::RemoveRequest(RequestId requestId) IMSA_HILOGD("imc request[%{public}u] removed", static_cast(requestId)); } -void ImcServiceProxy::RemoveUnresponsiveRequest(RequestId requestId) +void ImcServiceProxy::RemoveUnresponsiveRequest(uint32_t requestId) { std::lock_guard lock(requestsMutex_); auto iter = pendingRequests_.find(requestId); diff --git a/frameworks/native/inputmethod_controller/src/input_client_info.cpp b/frameworks/native/inputmethod_controller/src/input_client_info.cpp index 29db07f5f68030ff4d5b7166877788d33395e285..3353e27221df22af2840e055fe4e26125cc369e4 100644 --- a/frameworks/native/inputmethod_controller/src/input_client_info.cpp +++ b/frameworks/native/inputmethod_controller/src/input_client_info.cpp @@ -15,6 +15,8 @@ #include "input_client_info.h" +#include "itypes_util.h" + namespace OHOS { namespace MiscServices { @@ -44,12 +46,13 @@ bool InputClientInfoInner::ReadFromParcel(Parcel &in) if (in.ReadBool()) { sptr clientObj; - clientObj = (static_cast(&in))->ReadRemoteObject(); - client = iface_cast(clientObj); + if (ITypesUtil::Unmarshal(clientObj, in)) { + client = iface_cast(clientObj); + } } if (in.ReadBool()) { - channel = (static_cast(&in))->ReadRemoteObject(); + ITypesUtil::Unmarshal(channel, in); } uint32_t stateData = in.ReadUint32(); state = static_cast(stateData); diff --git a/frameworks/native/inputmethod_controller/src/input_method_utils.cpp b/frameworks/native/inputmethod_controller/src/input_method_utils.cpp index 080a217fc7665491f8be91bc5da7b97a7bbe8e7b..8a4f45343f899795a27bd05630dd642f19270ec3 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_utils.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_utils.cpp @@ -12,10 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include + #include "input_method_utils.h" + +#include + #include "input_method_tools.h" +#include "itypes_util.h" namespace OHOS { namespace MiscServices { @@ -103,13 +106,13 @@ bool TextTotalConfigInner::ReadFromParcel(Parcel &in) height = in.ReadDouble(); std::unique_ptr commandValueInfo(in.ReadParcelable()); - if (commandValueInfo == nullptr) { - return false; - } + if (commandValueInfo == nullptr) { + return false; + } commandValue = *commandValueInfo; int32_t requestKeyboardReasonData = in.ReadInt32(); requestKeyboardReason = static_cast(requestKeyboardReasonData); - abilityToken = (static_cast(&in))->ReadRemoteObject(); + ITypesUtil::Unmarshal(abilityToken, in); isSimpleKeyboardEnabled = in.ReadBool(); return true; } diff --git a/services/task_manager/include/actions/sa_action.h b/services/task_manager/include/actions/sa_action.h index ecd88af2dc8eb08f2c0a17ec85844a49f61fb7fc..72486864d6cf73e33d31f57e9ec808a2912914c7 100644 --- a/services/task_manager/include/actions/sa_action.h +++ b/services/task_manager/include/actions/sa_action.h @@ -26,10 +26,10 @@ namespace OHOS { namespace MiscServices { static constexpr int32_t INVALID_RET_CODE = -1; -enum class PauseType : int32_t { - PAUSED_TYPE_INVALID = -1, - PAUSE_TYPE_START_IME = 0, - PAUSE_TYPE_STOP_IME = 1, +enum class PauseType : uint32_t { + PAUSED_TYPE_INVALID = 0, + PAUSE_TYPE_START_IME = 1, + PAUSE_TYPE_STOP_IME = 2, }; struct PauseInfo { diff --git a/services/task_manager/include/caller_info.h b/services/task_manager/include/caller_info.h index f281ea8f9c44f36d6c39b76aaa8f9361574423dc..5b8320e109b61a7ec65e1187865841457e957fdc 100644 --- a/services/task_manager/include/caller_info.h +++ b/services/task_manager/include/caller_info.h @@ -26,7 +26,7 @@ struct CallerInfo { uint32_t requestId = 0; int32_t pid = 0; int32_t uid = 0; - int32_t userId{ MAIN_USER_ID }; + int32_t userId = MAIN_USER_ID; uint32_t tokenId = 0; uint64_t fullTokenId = 0; std::string bundleName; diff --git a/services/task_manager/src/actions/sa_action_wait.cpp b/services/task_manager/src/actions/sa_action_wait.cpp index fc0015930f6fcfc8b232d7a430d00be06d16e635..868c9cf9b4b4d325eb633af78fce718b46f26fcf 100644 --- a/services/task_manager/src/actions/sa_action_wait.cpp +++ b/services/task_manager/src/actions/sa_action_wait.cpp @@ -49,7 +49,7 @@ RunningState SaActionWait::Resume( if (resumedId == completeId_) { if (onComplete_ != nullptr) { state_ = RUNNING_STATE_RUNNING; - onComplete_(data, innerData); + ret = onComplete_(data, innerData); } state_ = RUNNING_STATE_COMPLETED; return state_; @@ -57,7 +57,7 @@ RunningState SaActionWait::Resume( if (resumedId == timeoutId_) { if (onTimeout_ != nullptr) { state_ = RUNNING_STATE_RUNNING; - onTimeout_(data, innerData); + ret = onTimeout_(data, innerData); } state_ = RUNNING_STATE_COMPLETED; return state_; diff --git a/services/task_manager/src/tasks/sa_task.cpp b/services/task_manager/src/tasks/sa_task.cpp index dbb03904f1f61c45daa376c41191b8236088e7a9..c80c826d1698f64e38652b7562de43b9b35cf760 100644 --- a/services/task_manager/src/tasks/sa_task.cpp +++ b/services/task_manager/src/tasks/sa_task.cpp @@ -193,7 +193,10 @@ RunningState SaTask::ExecuteInner() return state_; } - state_ = RUNNING_STATE_PAUSED; + if (state == RUNNING_STATE_PAUSED) { + IMSA_HILOGI("task paused"); + } + state_ = state; return state_; } diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index 10bd24d5456e98c76131d00180e5c8723402daaa..0e406835022febc2137552c5726a0ad620b2a416 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -1474,6 +1474,67 @@ ohos_unittest("WindowAdapterTest") { } } +ohos_unittest("SaTaskManagerTest") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path + include_dirs = [ + "${inputmethod_path}/common/include", + "${inputmethod_path}/frameworks/native/inputmethod_ability/include/actions", + "${inputmethod_path}/services/task_manager/include", + "${inputmethod_path}/services/task_manager/include/actions", + "${inputmethod_path}/services/task_manager/include/tasks", + ] + sources = [ + "src/ime_response_data_test.cpp", + "src/sa_task_manager_test.cpp", + "${inputmethod_path}/frameworks/native/common/src/service_response_data.cpp", + "${inputmethod_path}/services/task_manager/src/requester_manager.cpp", + "${inputmethod_path}/services/task_manager/src/sa_task_manager.cpp", + "${inputmethod_path}/services/task_manager/src/actions/sa_action.cpp", + "${inputmethod_path}/services/task_manager/src/actions/sa_action_wait.cpp", + "${inputmethod_path}/services/task_manager/src/tasks/sa_task.cpp", + ] + + configs = [ ":module_private_config" ] + deps = [ + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:ima_response_channel_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:ima_response_channel_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:imc_response_channel_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:imc_response_channel_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", + "${inputmethod_path}/services:inputmethod_service_static", + "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", + "${inputmethod_path}/services/file:imf_file_static", + "${inputmethod_path}/services/json:imf_json_static", + "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:ima_response_channel_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:imc_response_channel_proxy", + + ] + + external_deps = [ + "ability_base:want", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "googletest:gtest_main", + "hicollie:libhicollie", + "hilog:libhilog", + "init:libbeget_proxy", + "init:libbegetutil", + "input:libmmi-client", + "resource_management:global_resmgr", + ] +} + ohos_unittest("ImaTextEditTest") { branch_protector_ret = "pac_ret" sanitize = { diff --git a/test/unittest/cpp_test/src/ime_response_data_test.cpp b/test/unittest/cpp_test/src/ime_response_data_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..62f14fa65ad23d744c6c41b92b2c0ac8e684580c --- /dev/null +++ b/test/unittest/cpp_test/src/ime_response_data_test.cpp @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#define protected public +#undef private + +#include +#include +#include + +#include +#include + +#include "iinput_method_agent.h" +#include "iinput_method_core.h" +#include "input_attribute.h" +#include "input_method_agent_service_impl.h" +#include "input_method_core_service_impl.h" +#include "input_method_tools.h" +#include "itypes_util.h" +#include "service_response_data.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS { +namespace MiscServices { +class ImeResponseDataTest : public testing::Test { +public: + static void SetUpTestCase() + { + IMSA_HILOGI("ImeResponseDataTest::SetUpTestCase"); + } + static void TearDownTestCase() + { + IMSA_HILOGI("ImeResponseDataTest::TearDownTestCase"); + } + void SetUp() + { + IMSA_HILOGI("ImeResponseDataTest::SetUp"); + } + void TearDown() + { + IMSA_HILOGI("ImeResponseDataTest::TearDown"); + } + + template static bool TestParcelable(const T &value); + template static bool TestServiceResponseData(const T &value); +}; + +template bool ImeResponseDataTest::TestParcelable(const T &value) +{ + Parcel parcel; + if (!value.Marshalling(parcel)) { + IMSA_HILOGE("failed to marshal"); + return false; + } + T *output = T::Unmarshalling(parcel); + if (output == nullptr) { + IMSA_HILOGE("output is nullptr"); + return false; + } + bool result = *output == value; + delete output; + return result; +} + +template bool ImeResponseDataTest::TestServiceResponseData(const T &value) +{ + ServiceResponseDataInner original; + original.data = value; + // marshal response data to parcel + Parcel parcel; + if (!original.Marshalling(parcel)) { + IMSA_HILOGE("failed to marshal"); + return false; + } + // unmarshal response data from parcel + ServiceResponseDataInner *output = ServiceResponseDataInner::Unmarshalling(parcel); + if (output == nullptr) { + IMSA_HILOGE("unmarshal failed"); + return false; + } + bool result = *output == value; + if (!std::holds_alternative(output->data)) { + IMSA_HILOGE("holds_alternative false"); + delete output; + return false; + } + if (!(std::get(output->data) == value)) { + delete output; + IMSA_HILOGE("value not equal"); + return false; + } + delete output; + return true; +} + +/** + * @tc.name: TestServiceResponseDataType + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestServiceResponseDataType, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestServiceResponseDataType START"); + EXPECT_EQ(std::variant(std::monostate{}).index(), ServiceDataType::TYPE_MONOSTATE); + EXPECT_EQ(std::variant(bool{}).index(), ServiceDataType::TYPE_BOOL); + EXPECT_EQ(std::variant(int32_t{}).index(), ServiceDataType::TYPE_INT32); + EXPECT_EQ(std::variant(uint32_t{}).index(), ServiceDataType::TYPE_UINT32); + EXPECT_EQ(std::variant(int64_t{}).index(), ServiceDataType::TYPE_INT64); + EXPECT_EQ(std::variant(uint64_t{}).index(), ServiceDataType::TYPE_UINT64); + EXPECT_EQ(std::variant(sptr{}).index(), ServiceDataType::TYPE_REMOTE_OBJECT); + EXPECT_EQ(std::variant(Property{}).index(), ServiceDataType::TYPE_PROPERTY); + EXPECT_EQ(std::variant(std::vector{}).index(), ServiceDataType::TYPE_PROPERTIES); + EXPECT_EQ(std::variant(SubProperty{}).index(), ServiceDataType::TYPE_SUB_PROPERTY); + EXPECT_EQ( + std::variant(std::vector{}).index(), ServiceDataType::TYPE_SUB_PROPERTIES); + EXPECT_EQ( + std::variant(StartInputResponse{}).index(), ServiceDataType::TYPE_START_INPUT_RESPONSE); + EXPECT_EQ(std::variant(InputStartInfo{}).index(), ServiceDataType::TYPE_INPUT_START_INFO); + + EXPECT_EQ(std::variant_size_v, ServiceDataType::TYPE_END); +} + +/** + * @tc.name: TestITypesUtils001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestITypesUtils001, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestITypesUtils001 START"); + sptr inputCoreObject = new (std::nothrow) InputMethodCoreServiceImpl(); + ASSERT_NE(inputCoreObject, nullptr); + MessageParcel parcel; + ASSERT_TRUE(ITypesUtil::Marshal(inputCoreObject->AsObject(), parcel)); + sptr outputCoreObject; + ASSERT_TRUE(ITypesUtil::Unmarshal(outputCoreObject, parcel)); + ASSERT_TRUE(outputCoreObject, inputCoreObject->AsObject()); +} + +/** + * @tc.name: TestITypesUtils001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestITypesUtils001, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestITypesUtils001 START"); + sptr inputCoreObject = new (std::nothrow) InputMethodCoreServiceImpl(); + ASSERT_NE(inputCoreObject, nullptr); + MessageParcel parcel; + ASSERT_TRUE(ITypesUtil::Marshal(inputCoreObject->AsObject(), parcel)); + sptr outputCoreObject; + ASSERT_TRUE(ITypesUtil::Unmarshal(outputCoreObject, parcel)); + ASSERT_TRUE(outputCoreObject, inputCoreObject->AsObject()); +} + +/** + * @tc.name: TestITypesUtils002 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestITypesUtils002, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestITypesUtils002 START"); + InputAttribute attributeInput1 = { + .inputPattern = 1, .enterKeyType = 1, .inputOption = 1, .isTextPreviewSupported = true + }; + InputAttribute attributeInput2 = { + .inputPattern = 2, .enterKeyType = 2, .inputOption = 2, .isTextPreviewSupported = false + }; + InputAttribute attributeInput3 = { + .inputPattern = 3, .enterKeyType = 3, .inputOption = 3, .isTextPreviewSupported = true + }; + InputAttributeInner attributeInner1 = InputMethodTools::GetInstance().AttributeToInner(attributeInput1); + InputAttributeInner attributeInner2 = InputMethodTools::GetInstance().AttributeToInner(attributeInput2); + InputAttributeInner attributeInner3 = InputMethodTools::GetInstance().AttributeToInner(attributeInput3); + std::vector inputs = { attributeInner1, attributeInner2, attributeInner3 }; + Parcel parcel; + ASSERT_TRUE(ITypesUtil::MarshalVector(inputs, parcel)); + std::vector outputs; + ASSERT_TRUE(ITypesUtil::UnmarshalVector(parcel, outputs)); + ASSERT_EQ(inputs.size(), outputs.size()); + auto attributeOutput1 = InputMethodTools::GetInstance().InnerToAttribute(outputs[0]); + auto attributeOutput2 = InputMethodTools::GetInstance().InnerToAttribute(outputs[1]); + auto attributeOutput3 = InputMethodTools::GetInstance().InnerToAttribute(outputs[2]); + EXPECT_EQ(attributeInput1, attributeOutput1); + EXPECT_EQ(attributeInput2, attributeOutput2); + EXPECT_EQ(attributeInput3, attributeOutput3); +} + +/** + * @tc.name: TestServiceResponseData001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestServiceResponseData001, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestServiceResponseData001 START"); + sptr agentStub = new (std::nothrow) InputMethodAgentServiceImpl(); + ASSERT_NE(agentStub, nullptr); + StartInputResponse input = { .agent = agentStub, .pid = 1, .bundleName = "TestServiceResponseData001" }; + EXPECT_TRUE(ImeResponseDataTest::TestParcelable(input)); +} + +/** + * @tc.name: TestStartInputResponse001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestStartInputResponse001, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestStartInputResponse001 START"); + sptr agentStub = new (std::nothrow) InputMethodAgentServiceImpl(); + ASSERT_NE(agentStub, nullptr); + StartInputResponse input(agentStub, 1, "TestServiceResponseData001"); + EXPECT_TRUE(ImeResponseDataTest::TestParcelable(input)); +} + +/** + * @tc.name: TestStartInputResponse002 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestStartInputResponse002, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestStartInputResponse002 START"); + StartInputResponse input(nullptr, 0, ""); + EXPECT_TRUE(ImeResponseDataTest::TestParcelable(input)); +} + +/** + * @tc.name: TestInputStartInput001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestInputStartInput001, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestInputStartInput001 START"); + InputStartInfo input(true, 10, 1); + EXPECT_TRUE(ImeResponseDataTest::TestParcelable(input)); +} + +/** + * @tc.name: TestInputStartInput002 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestInputStartInput002, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestInputStartInput002 START"); + InputStartInfo input(nullptr, 0, ""); + EXPECT_TRUE(ImeResponseDataTest::TestParcelable(input)); +} + +/** + * @tc.name: TestServiceResponseData001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestServiceResponseData001, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestServiceResponseData001 START"); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(std::monostate{})); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(true)); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(false)); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(int32_t(123))); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(int32_t(-456))); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(uint32_t(0x7FFFFFFF))); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(int64_t(9876543210))); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(uint64_t(0xFFFFFFFFFFFFFFFF))); + + sptr coreObject = new (std::nothrow) InputMethodCoreServiceImpl(); + ASSERT_NE(coreObject, nullptr); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(coreObject->AsObject())); +} + +/** + * @tc.name: TestServiceResponseData002 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestServiceResponseData002, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestServiceResponseData002 START"); + Property property1("name1", "id1"); + Property property2("name2", "id2"); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(property1)); + + std::vector properties = { property1, property2 }; + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(properties)); + + SubProperty subProperty1("name1", "subId1"); + SubProperty subProperty2("name2", "subId2"); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(subProperty1)); + + std::vector subProperties = { subProperty1, subProperty2 }; + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(subProperties)); +} + +/** + * @tc.name: TestServiceResponseData003 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(ImeResponseDataTest, TestServiceResponseData003, TestSize.Level0) +{ + IMSA_HILOGI("ImeResponseDataTest TestServiceResponseData003 START"); + int64_t pid = 123; + sptr agentStub = new (std::nothrow) InputMethodAgentServiceImpl(); + ASSERT_NE(agentStub, nullptr); + StartInputResponse response(agentStub, pid, "TestServiceResponseData003"); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(response)); + + uint32_t callingWindowId = 456; + int32_t requestKeyboardReason = 2; + InputStartInfo inputStartInfo(true, callingWindowId, requestKeyboardReason); + EXPECT_TRUE(ImeResponseDataTest::TestServiceResponseData(inputStartInfo)); +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cpp_test/src/sa_task_manager_test.cpp b/test/unittest/cpp_test/src/sa_task_manager_test.cpp index 8fed514b8cfae6484a60e7cd8c051eac3846b26f..bf1c391fc62dacac301437af2dfc058c7025c547 100644 --- a/test/unittest/cpp_test/src/sa_task_manager_test.cpp +++ b/test/unittest/cpp_test/src/sa_task_manager_test.cpp @@ -17,7 +17,6 @@ #define protected public #include "sa_task_manager.h" -#include "response_data_util.h" #include "service_response_data.h" #undef private