无障碍修改carsh

Signed-off-by: jinqi6 <jinqi6@huawei.com>
This commit is contained in:
jinqi6 2024-01-11 15:28:13 +08:00
parent 8e9a6f57cb
commit 19532f8b78
2 changed files with 52 additions and 9 deletions

View File

@ -17,11 +17,25 @@
#define ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_STUB_H
#include <map>
#include <mutex>
#include "i_accessibility_element_operator_callback.h"
#include "iremote_stub.h"
namespace OHOS {
namespace Accessibility {
class StoreElementData {
public:
StoreElementData() = default;
~StoreElementData() = default;
void WriteData(std::vector<AccessibilityElementInfo> &infos);
std::vector<AccessibilityElementInfo> ReadData();
size_t Size();
void Clear();
std::vector<AccessibilityElementInfo> storeData_ = {};
std::mutex mutex_;
};
/*
* The class define the interface for UI to implement.
* It triggered by ABMS when AA to request the accessibility information.
@ -49,7 +63,7 @@ public:
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
static std::vector<AccessibilityElementInfo> storeData;
static StoreElementData storeElementData;
private:
/**
* @brief Handle the IPC request for the function:SetSearchElementInfoByAccessibilityIdResult.

View File

@ -25,6 +25,34 @@ namespace Accessibility {
constexpr int32_t SINGLE_TRANSMIT = -2;
constexpr int32_t MULTI_TRANSMIT_FINISH = -1;
void StoreElementData::WriteData(std::vector<AccessibilityElementInfo> &infos)
{
HILOG_DEBUG();
std::lock_guard<std::mutex> lock(mutex_);
storeData_.insert(storeData_.end(), infos.begin(), infos.end());
}
void StoreElementData::Clear()
{
HILOG_DEBUG();
std::lock_guard<std::mutex> lock(mutex_);
storeData_.clear();
}
std::vector<AccessibilityElementInfo> StoreElementData::ReadData()
{
HILOG_DEBUG();
std::lock_guard<std::mutex> lock(mutex_);
return storeData_;
}
size_t StoreElementData::Size()
{
HILOG_DEBUG();
std::lock_guard<std::mutex> lock(mutex_);
return storeData_.size();
}
AccessibilityElementOperatorCallbackStub::AccessibilityElementOperatorCallbackStub()
{
memberFuncMap_[static_cast<uint32_t>(
@ -42,7 +70,7 @@ AccessibilityElementOperatorCallbackStub::AccessibilityElementOperatorCallbackSt
&AccessibilityElementOperatorCallbackStub::HandleSetExecuteActionResult;
}
std::vector<AccessibilityElementInfo> AccessibilityElementOperatorCallbackStub::storeData = {};
StoreElementData AccessibilityElementOperatorCallbackStub::storeElementData;
AccessibilityElementOperatorCallbackStub::~AccessibilityElementOperatorCallbackStub()
{
@ -79,29 +107,30 @@ ErrCode AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByAc
HILOG_DEBUG();
int32_t flag = data.ReadInt32();
if (flag == SINGLE_TRANSMIT || flag == 0) {
storeData.clear();
storeElementData.Clear();
}
int32_t accessibilityInfosize = data.ReadInt32();
ContainerSecurityVerify(data, accessibilityInfosize, storeData.max_size());
std::vector<AccessibilityElementInfo> tmpData;
ContainerSecurityVerify(data, accessibilityInfosize, tmpData.max_size());
for (int32_t i = 0; i < accessibilityInfosize; i++) {
sptr<AccessibilityElementInfoParcel> accessibilityInfo =
data.ReadStrongParcelable<AccessibilityElementInfoParcel>();
if (!accessibilityInfo) {
HILOG_ERROR("ReadStrongParcelable<accessibilityInfo> failed");
storeData.clear();
storeElementData.Clear();
reply.WriteInt32(RET_ERR_FAILED);
return TRANSACTION_ERR;
}
storeData.push_back(*accessibilityInfo);
tmpData.push_back(*accessibilityInfo);
}
storeElementData.WriteData(tmpData); // get all data and push once
int32_t requestId = data.ReadInt32();
if (flag == SINGLE_TRANSMIT || flag == MULTI_TRANSMIT_FINISH) {
reply.WriteInt32(0);
HILOG_DEBUG("size %{public}zu requestId %{public}d", storeData.size(), requestId);
SetSearchElementInfoByAccessibilityIdResult(storeData, requestId);
// clear storeData will crash here
HILOG_DEBUG("infos size %{public}zu, requestId %{public}d", storeElementData.Size(), requestId);
SetSearchElementInfoByAccessibilityIdResult(storeElementData.ReadData(), requestId);
return NO_ERROR;
}