divide data

Signed-off-by: lzr <liuzengrui1@huawei.com>
This commit is contained in:
lzr 2024-07-04 20:19:39 +08:00
parent b737372db2
commit fbbdc5e5dd
10 changed files with 57 additions and 25 deletions

View File

@ -21,7 +21,7 @@
namespace OHOS::Ace { namespace OHOS::Ace {
int32_t UIContentServiceProxy::GetInspectorTree(const EventCallback& eventCallback) int32_t UIContentServiceProxy::GetInspectorTree(const std::function<void(std::string, int32_t, bool)>& eventCallback)
{ {
MessageParcel data; MessageParcel data;
MessageParcel reply; MessageParcel reply;
@ -30,6 +30,10 @@ int32_t UIContentServiceProxy::GetInspectorTree(const EventCallback& eventCallba
LOGW("GetInspectorTree write interface token failed"); LOGW("GetInspectorTree write interface token failed");
return FAILED; return FAILED;
} }
if (report_ == nullptr) {
LOGW("reportStub is nullptr");
return FAILED;
}
report_->RegisterGetInspectorTreeCallback(eventCallback); report_->RegisterGetInspectorTreeCallback(eventCallback);
if (Remote()->SendRequest(UI_CONTENT_SERVICE_GET_TREE, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(UI_CONTENT_SERVICE_GET_TREE, data, reply, option) != ERR_NONE) {
LOGW("GetInspectorTree send request failed"); LOGW("GetInspectorTree send request failed");
@ -78,7 +82,8 @@ int32_t UIContentServiceProxy::RegisterClickEventCallback(const EventCallback& e
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->RegisterClickEventCallback(eventCallback); report_->RegisterClickEventCallback(eventCallback);
if (Remote()->SendRequest(REGISTER_CLICK_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(REGISTER_CLICK_EVENT, data, reply, option) != ERR_NONE) {
@ -98,7 +103,8 @@ int32_t UIContentServiceProxy::RegisterSearchEventCallback(const EventCallback&
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->RegisterSearchEventCallback(eventCallback); report_->RegisterSearchEventCallback(eventCallback);
if (Remote()->SendRequest(REGISTER_SEARCH_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(REGISTER_SEARCH_EVENT, data, reply, option) != ERR_NONE) {
@ -118,7 +124,8 @@ int32_t UIContentServiceProxy::RegisterRouterChangeEventCallback(const EventCall
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->RegisterRouterChangeEventCallback(eventCallback); report_->RegisterRouterChangeEventCallback(eventCallback);
if (Remote()->SendRequest(REGISTER_ROUTER_CHANGE_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(REGISTER_ROUTER_CHANGE_EVENT, data, reply, option) != ERR_NONE) {
@ -138,7 +145,8 @@ int32_t UIContentServiceProxy::RegisterComponentChangeEventCallback(const EventC
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->RegisterComponentChangeEventCallback(eventCallback); report_->RegisterComponentChangeEventCallback(eventCallback);
if (Remote()->SendRequest(REGISTER_COMPONENT_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(REGISTER_COMPONENT_EVENT, data, reply, option) != ERR_NONE) {
@ -158,7 +166,8 @@ int32_t UIContentServiceProxy::UnregisterClickEventCallback()
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->UnregisterClickEventCallback(); report_->UnregisterClickEventCallback();
if (Remote()->SendRequest(UNREGISTER_CLICK_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(UNREGISTER_CLICK_EVENT, data, reply, option) != ERR_NONE) {
@ -178,7 +187,8 @@ int32_t UIContentServiceProxy::UnregisterSearchEventCallback()
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->UnregisterSearchEventCallback(); report_->UnregisterSearchEventCallback();
if (Remote()->SendRequest(UNREGISTER_SEARCH_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(UNREGISTER_SEARCH_EVENT, data, reply, option) != ERR_NONE) {
@ -198,7 +208,8 @@ int32_t UIContentServiceProxy::UnregisterRouterChangeEventCallback()
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->UnregisterRouterChangeEventCallback(); report_->UnregisterRouterChangeEventCallback();
if (Remote()->SendRequest(UNREGISTER_ROUTER_CHANGE_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(UNREGISTER_ROUTER_CHANGE_EVENT, data, reply, option) != ERR_NONE) {
@ -218,7 +229,8 @@ int32_t UIContentServiceProxy::UnregisterComponentChangeEventCallback()
return FAILED; return FAILED;
} }
if (report_ == nullptr) { if (report_ == nullptr) {
LOGW("reportStub is nullptr,connect is not execute"); LOGW("reportStub is nullptr");
return FAILED;
} }
report_->UnregisterComponentChangeEventCallback(); report_->UnregisterComponentChangeEventCallback();
if (Remote()->SendRequest(UNREGISTER_COMPONENT_EVENT, data, reply, option) != ERR_NONE) { if (Remote()->SendRequest(UNREGISTER_COMPONENT_EVENT, data, reply, option) != ERR_NONE) {

View File

@ -20,7 +20,7 @@
#include "adapter/ohos/entrance/ui_session/include/ui_service_hilog.h" #include "adapter/ohos/entrance/ui_session/include/ui_service_hilog.h"
namespace OHOS::Ace { namespace OHOS::Ace {
int32_t UIContentServiceStubImpl::GetInspectorTree(const EventCallback& eventCallback) int32_t UIContentServiceStubImpl::GetInspectorTree(const std::function<void(std::string, int32_t, bool)>& eventCallback)
{ {
UiSessionManager::GetInstance().GetInspectorTree(); UiSessionManager::GetInstance().GetInspectorTree();
return NO_ERROR; return NO_ERROR;

View File

@ -93,7 +93,7 @@ void UiReportProxy::ReportSearchEvent(const std::string& data)
} }
} }
void UiReportProxy::ReportInspectorTreeValue(const std::string& data) void UiReportProxy::ReportInspectorTreeValue(const std::string& data, int32_t partNum, bool isLastPart)
{ {
MessageParcel messageData; MessageParcel messageData;
MessageParcel reply; MessageParcel reply;
@ -106,6 +106,14 @@ void UiReportProxy::ReportInspectorTreeValue(const std::string& data)
LOGW("ReportInspectorTreeValue write data failed"); LOGW("ReportInspectorTreeValue write data failed");
return; return;
} }
if (!messageData.WriteInt32(partNum)) {
LOGW("ReportInspectorTreeValue write data failed");
return;
}
if (!messageData.WriteBool(isLastPart)) {
LOGW("ReportInspectorTreeValue write data failed");
return;
}
if (Remote()->SendRequest(REPORT_INSPECTOR_VALUE, messageData, reply, option) != ERR_NONE) { if (Remote()->SendRequest(REPORT_INSPECTOR_VALUE, messageData, reply, option) != ERR_NONE) {
LOGW("ReportInspectorTreeValue send request failed"); LOGW("ReportInspectorTreeValue send request failed");
} }

View File

@ -43,7 +43,9 @@ int32_t UiReportStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messag
break; break;
} }
case REPORT_INSPECTOR_VALUE: { case REPORT_INSPECTOR_VALUE: {
ReportInspectorTreeValue(result); int32_t partNum = data.ReadInt32();
bool isLastPart = data.ReadBool();
ReportInspectorTreeValue(result, partNum, isLastPart);
break; break;
} }
default: { default: {
@ -82,10 +84,10 @@ void UiReportStub::ReportSearchEvent(const std::string& data)
} }
} }
void UiReportStub::ReportInspectorTreeValue(const std::string& data) void UiReportStub::ReportInspectorTreeValue(const std::string& data, int32_t partNum, bool isLastPart)
{ {
if (inspectorTreeCallback_ != nullptr) { if (inspectorTreeCallback_ != nullptr) {
inspectorTreeCallback_(data); inspectorTreeCallback_(data, partNum, isLastPart);
} }
} }
@ -94,7 +96,8 @@ void UiReportStub::RegisterClickEventCallback(const EventCallback& eventCallback
clickEventCallback_ = std::move(eventCallback); clickEventCallback_ = std::move(eventCallback);
} }
void UiReportStub::RegisterGetInspectorTreeCallback(const EventCallback& eventCallback) void UiReportStub::RegisterGetInspectorTreeCallback(
const std::function<void(std::string, int32_t, bool)>& eventCallback)
{ {
inspectorTreeCallback_ = std::move(eventCallback); inspectorTreeCallback_ = std::move(eventCallback);
} }

View File

@ -18,7 +18,7 @@
#include "adapter/ohos/entrance/ui_session/include/ui_service_hilog.h" #include "adapter/ohos/entrance/ui_session/include/ui_service_hilog.h"
namespace OHOS::Ace { namespace OHOS::Ace {
std::mutex UiSessionManager::mutex_; std::mutex UiSessionManager::mutex_;
constexpr int32_t ONCE_IPC_SEND_DATA_MAX_SIZE = 4096;
UiSessionManager& UiSessionManager::GetInstance() UiSessionManager& UiSessionManager::GetInstance()
{ {
static UiSessionManager instance_; static UiSessionManager instance_;
@ -175,7 +175,15 @@ void UiSessionManager::ReportInspectorTreeValue(const std::string& data)
for (auto pair : reportObjectMap_) { for (auto pair : reportObjectMap_) {
auto reportService = iface_cast<ReportService>(pair.second); auto reportService = iface_cast<ReportService>(pair.second);
if (reportService != nullptr) { if (reportService != nullptr) {
reportService->ReportInspectorTreeValue(data); int partSize = data.size() / ONCE_IPC_SEND_DATA_MAX_SIZE;
for (int i = 0; i <= partSize; i++) {
if (i != partSize) {
reportService->ReportInspectorTreeValue(
data.substr(i * ONCE_IPC_SEND_DATA_MAX_SIZE, ONCE_IPC_SEND_DATA_MAX_SIZE), i + 1, false);
} else {
reportService->ReportInspectorTreeValue(data.substr(i * ONCE_IPC_SEND_DATA_MAX_SIZE), i + 1, true);
}
}
} else { } else {
LOGW("report component event failed,process id:%{public}d", pair.first); LOGW("report component event failed,process id:%{public}d", pair.first);
} }

View File

@ -25,7 +25,7 @@ namespace OHOS::Ace {
class ACE_FORCE_EXPORT UIContentServiceProxy : public IRemoteProxy<IUiContentService> { class ACE_FORCE_EXPORT UIContentServiceProxy : public IRemoteProxy<IUiContentService> {
public: public:
explicit UIContentServiceProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IUiContentService>(impl) {}; explicit UIContentServiceProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IUiContentService>(impl) {};
virtual int32_t GetInspectorTree(const EventCallback& eventCallback) override; virtual int32_t GetInspectorTree(const std::function<void(std::string, int32_t, bool)>& eventCallback) override;
virtual int32_t Connect() override; virtual int32_t Connect() override;
virtual int32_t RegisterClickEventCallback(const EventCallback& eventCallback) override; virtual int32_t RegisterClickEventCallback(const EventCallback& eventCallback) override;
virtual int32_t RegisterRouterChangeEventCallback(const EventCallback& eventCallback) override; virtual int32_t RegisterRouterChangeEventCallback(const EventCallback& eventCallback) override;

View File

@ -44,7 +44,7 @@ public:
* @description: define get the current page inspector tree info interface * @description: define get the current page inspector tree info interface
* @return: result number * @return: result number
*/ */
virtual int32_t GetInspectorTree(const EventCallback& eventCallback) = 0; virtual int32_t GetInspectorTree(const std::function<void(std::string, int32_t, bool)>& eventCallback) = 0;
/** /**
* @description: define SA process and current process connect interface * @description: define SA process and current process connect interface
@ -137,7 +137,8 @@ public:
/** /**
* @description: define reports inspector value to the proxy interface * @description: define reports inspector value to the proxy interface
*/ */
virtual void ReportInspectorTreeValue(const std::string& data) = 0; virtual void ReportInspectorTreeValue(const std::string& data, int32_t partNum, bool isLastPart) = 0;
virtual void ReportWebUnfocusEvent(int64_t accessibilityId, const std::string& data) = 0;
}; };
} // namespace OHOS::Ace } // namespace OHOS::Ace
#endif // FOUNDATION_ACE_INTERFACE_UI_CONTENT_SERVICE_INTERFACE_H #endif // FOUNDATION_ACE_INTERFACE_UI_CONTENT_SERVICE_INTERFACE_H

View File

@ -31,7 +31,7 @@ public:
{ {
return 0; return 0;
} }
int32_t GetInspectorTree(const EventCallback& eventCallback) override; int32_t GetInspectorTree(const std::function<void(std::string, int32_t, bool)>& eventCallback) override;
int32_t RegisterClickEventCallback(const EventCallback& eventCallback) override; int32_t RegisterClickEventCallback(const EventCallback& eventCallback) override;
int32_t RegisterRouterChangeEventCallback(const EventCallback& eventCallback) override; int32_t RegisterRouterChangeEventCallback(const EventCallback& eventCallback) override;
int32_t RegisterSearchEventCallback(const EventCallback& eventCallback) override; int32_t RegisterSearchEventCallback(const EventCallback& eventCallback) override;

View File

@ -50,7 +50,7 @@ public:
/** /**
* @description: notify stub side to report inspector value * @description: notify stub side to report inspector value
*/ */
void ReportInspectorTreeValue(const std::string& data) override; void ReportInspectorTreeValue(const std::string& data, int32_t partNum, bool isLastPart) override;
void OnComponentChange(const std::string& key, const std::string& value); void OnComponentChange(const std::string& key, const std::string& value);

View File

@ -77,7 +77,7 @@ public:
* @description: register a callback when get inspector tree * @description: register a callback when get inspector tree
* @param eventCallback callback to be performed * @param eventCallback callback to be performed
*/ */
void RegisterGetInspectorTreeCallback(const EventCallback& eventCallback); void RegisterGetInspectorTreeCallback(const std::function<void(std::string, int32_t, bool)>& eventCallback);
/** /**
* @description: unregister the click callback last register * @description: unregister the click callback last register
@ -102,14 +102,14 @@ public:
/** /**
* @description: report whole inspectorTree for SA * @description: report whole inspectorTree for SA
*/ */
void ReportInspectorTreeValue(const std::string& data) override; void ReportInspectorTreeValue(const std::string& data, int32_t partNum, bool isLastPart) override;
private: private:
EventCallback clickEventCallback_; EventCallback clickEventCallback_;
EventCallback searchEventCallback_; EventCallback searchEventCallback_;
EventCallback RouterChangeEventCallback_; EventCallback RouterChangeEventCallback_;
EventCallback ComponentChangeEventCallback_; EventCallback ComponentChangeEventCallback_;
EventCallback inspectorTreeCallback_; std::function<void(std::string, int32_t, bool)> inspectorTreeCallback_;
}; };
} // namespace OHOS::Ace } // namespace OHOS::Ace
#endif // FOUNDATION_ACE_INTERFACE_UI_REPORT_STUB_H #endif // FOUNDATION_ACE_INTERFACE_UI_REPORT_STUB_H