From 68d2a1d8f8d661585b785140b5fec71306a3ac25 Mon Sep 17 00:00:00 2001 From: AXYChen Date: Wed, 9 Apr 2025 11:00:56 +0800 Subject: [PATCH] send error message back when report failed Signed-off-by: AXYChen Change-Id: I1313c446da305681bdc777a3eeb2a275d23698e4 --- .../src/sec_comp_enhance_adapter.cpp | 2 +- .../src/sec_comp_client.cpp | 69 +++++++++++-------- .../sa/sa_main/sec_comp_service.cpp | 5 +- 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp index 9c9c4f4..83a8641 100644 --- a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp +++ b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp @@ -185,7 +185,7 @@ static bool WriteMessageParcel(MessageParcel& tmpData, SecCompRawdata& data) static bool ReadMessageParcel(SecCompRawdata& tmpData, MessageParcel& data) { - int32_t size = tmpData.size; + uint32_t size = tmpData.size; const void *iter = tmpData.data; if (iter == nullptr) { diff --git a/frameworks/inner_api/security_component/src/sec_comp_client.cpp b/frameworks/inner_api/security_component/src/sec_comp_client.cpp index c6c4959..ed6d3d0 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_client.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_client.cpp @@ -102,15 +102,20 @@ int32_t SecCompClient::RegisterSecurityComponent(SecCompType type, return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!deserializedReply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Register read res failed."); + if (res != SC_OK) { + SC_LOG_ERROR(LABEL, "Register request failed, result: %{public}d.", res); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (res != SC_OK) { + int32_t serviceRes; + if (!deserializedReply.ReadInt32(serviceRes)) { + SC_LOG_ERROR(LABEL, "Register read serviceRes failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + if (serviceRes != SC_OK) { scId = INVALID_SC_ID; - SC_LOG_ERROR(LABEL, "Register request failed, result: %{public}d.", res); - return res; + return serviceRes; } if (!deserializedReply.ReadInt32(scId)) { @@ -163,17 +168,18 @@ int32_t SecCompClient::UpdateSecurityComponent(int32_t scId, const std::string& return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!deserializedReply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Update read res failed."); + if (res != SC_OK) { + SC_LOG_ERROR(LABEL, "Update request failed, result: %{public}d.", res); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (res != SC_OK) { - SC_LOG_ERROR(LABEL, "Update request failed, result: %{public}d.", res); - return res; + int32_t serviceRes; + if (!deserializedReply.ReadInt32(serviceRes)) { + SC_LOG_ERROR(LABEL, "Update read res failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - return res; + return serviceRes; } int32_t SecCompClient::UnregisterWriteToRawdata(int32_t scId, SecCompRawdata& rawData) @@ -216,16 +222,18 @@ int32_t SecCompClient::UnregisterSecurityComponent(int32_t scId) return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!deserializedReply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Unregister read res failed."); + if (res != SC_OK) { + SC_LOG_ERROR(LABEL, "Unregister request failed, result: %{public}d.", res); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (res != SC_OK) { - SC_LOG_ERROR(LABEL, "Unregister request failed, result: %{public}d.", res); - return res; + int32_t serviceRes; + if (!deserializedReply.ReadInt32(serviceRes)) { + SC_LOG_ERROR(LABEL, "Unregister read res failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - return res; + + return serviceRes; } int32_t SecCompClient::ReportWriteToRawdata(SecCompInfo& secCompInfo, SecCompRawdata& rawData) @@ -284,21 +292,22 @@ int32_t SecCompClient::ReportSecurityComponentClickEvent(SecCompInfo& secCompInf return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!deserializedReply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Report read res failed."); + if (res != SC_OK) { + SC_LOG_ERROR(LABEL, "Report request failed, result: %{public}d.", res); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (res != SC_OK) { - SC_LOG_ERROR(LABEL, "Report request failed, result: %{public}d.", res); - return res; + int32_t serviceRes; + if (!deserializedReply.ReadInt32(serviceRes)) { + SC_LOG_ERROR(LABEL, "Report read res failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!deserializedReply.ReadString(message)) { SC_LOG_ERROR(LABEL, "Report read error message failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - return res; + return serviceRes; } bool SecCompClient::VerifySavePermission(AccessToken::AccessTokenID tokenId) @@ -357,16 +366,18 @@ int32_t SecCompClient::PreRegisterSecCompProcess() return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!deserializedReply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "PreRegister read res failed."); - return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; - } - if (res != SC_OK) { SC_LOG_ERROR(LABEL, "PreRegister request failed, result: %{public}d.", res); return res; } - return res; + + int32_t serviceRes; + if (!deserializedReply.ReadInt32(serviceRes)) { + SC_LOG_ERROR(LABEL, "PreRegister read serviceRes failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + return serviceRes; } bool SecCompClient::IsServiceExist() diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.cpp b/services/security_component_service/sa/sa_main/sec_comp_service.cpp index 56b2223..9793c58 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_service.cpp @@ -191,7 +191,7 @@ int32_t SecCompService::ParseParams(const std::string& componentInfo, int32_t SecCompService::WriteError(int32_t res, SecCompRawdata& rawReply) { MessageParcel replyParcel; - if (!replyParcel.WriteUint32(res)) { + if (!replyParcel.WriteInt32(res)) { SC_LOG_ERROR(LABEL, "Write error res failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -541,9 +541,6 @@ int32_t SecCompService::ReportSecurityComponentClickEvent(const sptrclickInfoParams_ }; std::string message; res = ReportSecurityComponentClickEventBody(secCompInfo, callerToken, dialogCallback, message); - if (res != SC_OK) { - break; - } res = ReportWriteToRawdata(res, message, rawReply); } while (0); if (res != SC_OK) { -- Gitee