mirror of
https://gitee.com/openharmony/distributeddatamgr_pasteboard
synced 2025-02-17 07:37:53 +00:00
fix: Code discrepancy modifications 3
Signed-off-by: wangruifeng14 <wangruifeng14@huawei.com>
This commit is contained in:
parent
657b83e152
commit
997166ae03
@ -22,6 +22,7 @@
|
||||
#include "hiview_adapter.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "pasteboard_client.h"
|
||||
#include "pasteboard_deduplicate_memory.h"
|
||||
#include "pasteboard_delay_getter_client.h"
|
||||
#include "pasteboard_entry_getter_client.h"
|
||||
#include "pasteboard_error.h"
|
||||
@ -39,11 +40,23 @@ namespace OHOS {
|
||||
namespace MiscServices {
|
||||
constexpr const int32_t HITRACE_GETPASTEDATA = 0;
|
||||
constexpr int32_t LOADSA_TIMEOUT_MS = 10000;
|
||||
constexpr int64_t REPORT_DUPLICATE_TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
||||
sptr<IPasteboardService> PasteboardClient::pasteboardServiceProxy_;
|
||||
PasteboardClient::StaticDestoryMonitor PasteboardClient::staticDestoryMonitor_;
|
||||
std::mutex PasteboardClient::instanceLock_;
|
||||
std::condition_variable PasteboardClient::proxyConVar_;
|
||||
sptr<IRemoteObject> clientDeathObserverPtr_;
|
||||
|
||||
struct RadarReportIdentity {
|
||||
pid_t pid;
|
||||
int32_t errorCode;
|
||||
};
|
||||
|
||||
bool operator==(const RadarReportIdentity &lhs, const RadarReportIdentity &rhs)
|
||||
{
|
||||
return lhs.pid == rhs.pid && lhs.errorCode == rhs.errorCode;
|
||||
}
|
||||
|
||||
PasteboardClient::PasteboardClient()
|
||||
{
|
||||
Init();
|
||||
@ -188,7 +201,9 @@ void PasteboardClient::Clear()
|
||||
|
||||
int32_t PasteboardClient::GetPasteData(PasteData &pasteData)
|
||||
{
|
||||
std::string currentPid = std::to_string(getpid());
|
||||
static DeduplicateMemory<RadarReportIdentity> reportMemory(REPORT_DUPLICATE_TIMEOUT);
|
||||
pid_t pid = getpid();
|
||||
std::string currentPid = std::to_string(pid);
|
||||
uint32_t tmpSequenceId = getSequenceId_++;
|
||||
std::string currentId = "GetPasteData_" + currentPid + "_" + std::to_string(tmpSequenceId);
|
||||
pasteData.SetPasteId(currentId);
|
||||
@ -222,10 +237,16 @@ int32_t PasteboardClient::GetPasteData(PasteData &pasteData)
|
||||
RadarReporter::CONCURRENT_ID, currentId, RadarReporter::DIS_SYNC_TIME, syncTime,
|
||||
RadarReporter::PACKAGE_NAME, currentPid);
|
||||
}
|
||||
} else {
|
||||
} else if (ret != static_cast<int32_t>(PasteboardError::TASK_PROCESSING) ||
|
||||
!reportMemory.IsDuplicate({.pid = pid, .errorCode = ret})) {
|
||||
RADAR_REPORT(RadarReporter::DFX_GET_PASTEBOARD, bizStage, RadarReporter::DFX_FAILED, RadarReporter::BIZ_STATE,
|
||||
RadarReporter::DFX_END, RadarReporter::CONCURRENT_ID, currentId, RadarReporter::DIS_SYNC_TIME,
|
||||
RadarReporter::PACKAGE_NAME, currentPid, syncTime, RadarReporter::ERROR_CODE, ret);
|
||||
syncTime, RadarReporter::PACKAGE_NAME, currentPid, RadarReporter::ERROR_CODE, ret);
|
||||
} else {
|
||||
RADAR_REPORT(RadarReporter::DFX_GET_PASTEBOARD, bizStage, RadarReporter::DFX_CANCELLED,
|
||||
RadarReporter::BIZ_STATE, RadarReporter::DFX_END, RadarReporter::CONCURRENT_ID, currentId,
|
||||
RadarReporter::DIS_SYNC_TIME, syncTime, RadarReporter::PACKAGE_NAME, currentPid,
|
||||
RadarReporter::ERROR_CODE, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -99,6 +99,16 @@ static inline uint64_t NetToHost(uint64_t value)
|
||||
return le64toh(value);
|
||||
}
|
||||
|
||||
static inline bool HostToNet(bool value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline bool NetToHost(bool value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
inline double HostToNet(double value)
|
||||
{
|
||||
double to;
|
||||
|
@ -476,7 +476,11 @@ bool TLVObject::ReadValue(const std::vector<std::uint8_t> &buffer, AAFwk::Want &
|
||||
if (!ReadValue(buffer, rawMem, head)) {
|
||||
return false;
|
||||
}
|
||||
value = *(ParcelUtil::Raw2Parcelable<AAFwk::Want>(rawMem));
|
||||
auto ret = ParcelUtil::Raw2Parcelable<AAFwk::Want>(rawMem);
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
value = *(ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -395,6 +395,27 @@ private:
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ReadBasicValue(const std::vector<std::uint8_t> &buffer, bool &value, const TLVHead &head)
|
||||
{
|
||||
if (head.len != sizeof(bool) || head.len == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!HasExpectBuffer(buffer, head.len)) {
|
||||
return false;
|
||||
}
|
||||
uint8_t rawValue = 0;
|
||||
auto ret = memcpy_s(&rawValue, sizeof(bool), buffer.data() + cursor_, sizeof(bool));
|
||||
if (ret != EOK) {
|
||||
return false;
|
||||
}
|
||||
if (rawValue > 1) {
|
||||
return false;
|
||||
}
|
||||
value = NetToHost(rawValue);
|
||||
cursor_ += sizeof(bool);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ReadBasicValue(const std::vector<std::uint8_t> &buffer, T &value, const TLVHead &head)
|
||||
{
|
||||
|
@ -222,7 +222,7 @@ RetDataCString FfiOHOSPasteDataGetPrimaryText(int64_t id)
|
||||
LOGE("[PasteData] GetPrimaryText: pasteData not exist");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<std::string> p = pasteData->GetPrimaryText();
|
||||
if (p != nullptr) {
|
||||
ret.data = PasteBoardMallocCString(*p);
|
||||
@ -396,7 +396,7 @@ static char** VectorToCArrString(std::vector<std::string> &vec)
|
||||
break;
|
||||
}
|
||||
if (strcpy_s(result[i], vec[i].length() + 1, vec[i].c_str()) != 0) {
|
||||
delete result[i];
|
||||
delete[] result[i];
|
||||
result[i] = nullptr;
|
||||
break;
|
||||
}
|
||||
@ -404,7 +404,7 @@ static char** VectorToCArrString(std::vector<std::string> &vec)
|
||||
}
|
||||
if (temp != vec.size()) {
|
||||
for (size_t j = temp; j > 0; j--) {
|
||||
delete result[j - 1];
|
||||
delete[] result[j - 1];
|
||||
result[j - 1] = nullptr;
|
||||
}
|
||||
delete[] result;
|
||||
|
@ -203,7 +203,7 @@ OH_UdmfData* OH_Pasteboard_GetData(OH_Pasteboard* pasteboard, int* status)
|
||||
return nullptr;
|
||||
}
|
||||
auto unifiedData = std::make_shared<OHOS::UDMF::UnifiedData>();
|
||||
auto ret = PasteboardClient::GetInstance()->GetUdsdData(*unifiedData);
|
||||
int32_t ret = PasteboardClient::GetInstance()->GetUdsdData(*unifiedData);
|
||||
if (ret != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_CAPI, "client OH_Pasteboard_GetData return invalid, result is %{public}d", ret);
|
||||
@ -221,7 +221,7 @@ int OH_Pasteboard_SetData(OH_Pasteboard* pasteboard, OH_UdmfData* data)
|
||||
if (!IsPasteboardValid(pasteboard) || data == nullptr) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
auto ret = PasteboardClient::GetInstance()->SetUdsdData(*(data->unifiedData_));
|
||||
int32_t ret = PasteboardClient::GetInstance()->SetUdsdData(*(data->unifiedData_));
|
||||
if (ret != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
PASTEBOARD_HILOGE(
|
||||
PASTEBOARD_MODULE_CAPI, "client OH_Pasteboard_SetData return invalid, result is %{public}d", ret);
|
||||
|
16
publicity.xml
Normal file
16
publicity.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Copyright (C) 2024 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.
|
||||
-->
|
||||
<packageInfo package = 'com.ohos.pasteboarddialog' label = 'pasteboarddialog' feature = "提供管理系统剪贴板的能力,为系统复制、粘贴功能提供支持。系统剪切板支持包文本、超文本、URIs等内容操作" author="华为终端有限公司"></packageInfo>
|
@ -623,13 +623,15 @@ int32_t PasteboardService::GetData(uint32_t tokenId, PasteData &data, int32_t &s
|
||||
auto appInfo = GetAppInfo(tokenId);
|
||||
int32_t result = static_cast<int32_t>(PasteboardError::E_OK);
|
||||
std::string peerNetId = "";
|
||||
std::string peerUdid = "";
|
||||
std::string pasteId = data.GetPasteId();
|
||||
auto event = GetValidDistributeEvent(appInfo.userId);
|
||||
if (!event.first || GetCurrentScreenStatus() != ScreenEvent::ScreenUnlocked) {
|
||||
result = GetLocalData(appInfo, data);
|
||||
} else {
|
||||
result = GetRemoteData(appInfo.userId, event.second, data, syncTime);
|
||||
peerNetId = DMAdapter::GetInstance().GetUdidByNetworkId(event.second.deviceId);
|
||||
peerNetId = event.second.deviceId;
|
||||
peerUdid = DMAdapter::GetInstance().GetUdidByNetworkId(peerNetId);
|
||||
}
|
||||
if (observerEventMap_.size() != 0) {
|
||||
std::string targetBundleName = GetAppBundleName(appInfo);
|
||||
@ -637,7 +639,8 @@ int32_t PasteboardService::GetData(uint32_t tokenId, PasteData &data, int32_t &s
|
||||
}
|
||||
RADAR_REPORT(DFX_GET_PASTEBOARD, DFX_GET_DATA_INFO, DFX_SUCCESS, CONCURRENT_ID, pasteId, GET_DATA_APP,
|
||||
appInfo.bundleName, GET_DATA_TYPE, GenerateDataType(data), LOCAL_DEV_TYPE,
|
||||
DMAdapter::GetInstance().GetLocalDeviceType(), PEER_NET_ID, PasteboardDfxUntil::GetAnonymousID(peerNetId));
|
||||
DMAdapter::GetInstance().GetLocalDeviceType(), PEER_NET_ID, PasteboardDfxUntil::GetAnonymousID(peerNetId),
|
||||
PEER_UDID, PasteboardDfxUntil::GetAnonymousID(peerUdid));
|
||||
if (result != static_cast<int32_t>(PasteboardError::E_OK)) {
|
||||
return result;
|
||||
}
|
||||
|
102
services/dfx/src/pasteboard_deduplicate_memory.h
Normal file
102
services/dfx/src/pasteboard_deduplicate_memory.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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 DISTRIBUTEDDATAMGR_PASTEBOARD_DEDUPLICATE_MEMORY_H
|
||||
#define DISTRIBUTEDDATAMGR_PASTEBOARD_DEDUPLICATE_MEMORY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
|
||||
template <typename T>
|
||||
class DeduplicateMemory {
|
||||
public:
|
||||
explicit DeduplicateMemory(int64_t expirationMilliSeconds);
|
||||
~DeduplicateMemory();
|
||||
bool IsDuplicate(const T &data);
|
||||
|
||||
private:
|
||||
int64_t GetTimestamp();
|
||||
void ClearExpiration();
|
||||
bool FindExist(const T &data);
|
||||
|
||||
struct MemoryIdentity {
|
||||
int64_t timestamp;
|
||||
const T data;
|
||||
};
|
||||
|
||||
std::list<MemoryIdentity> memory_;
|
||||
int64_t expirationMS_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
DeduplicateMemory<T>::DeduplicateMemory(int64_t expirationMilliSeconds) : expirationMS_(expirationMilliSeconds)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
DeduplicateMemory<T>::~DeduplicateMemory()
|
||||
{
|
||||
memory_.clear();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DeduplicateMemory<T>::IsDuplicate(const T &data)
|
||||
{
|
||||
ClearExpiration();
|
||||
if (FindExist(data)) {
|
||||
return true;
|
||||
}
|
||||
int64_t timestamp = GetTimestamp();
|
||||
memory_.push_back(MemoryIdentity({.timestamp = timestamp, .data = data}));
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool DeduplicateMemory<T>::FindExist(const T &data)
|
||||
{
|
||||
for (const MemoryIdentity &item : memory_) {
|
||||
if (item.data == data) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int64_t DeduplicateMemory<T>::GetTimestamp()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DeduplicateMemory<T>::ClearExpiration()
|
||||
{
|
||||
int64_t timestamp = GetTimestamp();
|
||||
if (timestamp < expirationMS_) {
|
||||
return;
|
||||
}
|
||||
int64_t expirationTimestamp = timestamp - expirationMS_;
|
||||
memory_.remove_if([expirationTimestamp](const MemoryIdentity &identity) {
|
||||
return expirationTimestamp > identity.timestamp;
|
||||
});
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISTRIBUTEDDATAMGR_PASTEBOARD_DEDUPLICATE_MEMORY_H
|
@ -106,23 +106,24 @@ private:
|
||||
};
|
||||
|
||||
constexpr char DOMAIN[] = "DISTDATAMGR";
|
||||
constexpr const char* EVENT_NAME = "DISTRIBUTED_PASTEBOARD_BEHAVIOR";
|
||||
constexpr const char* ORG_PKG = "distributeddata";
|
||||
constexpr const char* BIZ_STATE = "BIZ_STATE";
|
||||
constexpr const char* ERROR_CODE = "ERROR_CODE";
|
||||
constexpr const char* SET_DATA_APP = "SET_DATA_APP";
|
||||
constexpr const char* SET_DATA_TYPE = "SET_DATA_TYPE";
|
||||
constexpr const char* GET_DATA_APP = "GET_DATA_APP";
|
||||
constexpr const char* GET_DATA_TYPE = "GET_DATA_TYPE";
|
||||
constexpr const char* LOCAL_DEV_TYPE = "LOCAL_DEV_TYPE";
|
||||
constexpr const char* COVER_DELAY_DATA = "COVER_DELAY_DATA";
|
||||
constexpr const char* SEND_BROADCAST_TIME = "SEND_BROADCAST_TIME_64";
|
||||
constexpr const char* RECEIVE_BROADCAST_TIME = "RECEIVE_BROADCAST_TIME_64";
|
||||
constexpr const char* SEQ_ID = "SEQ_ID";
|
||||
constexpr const char* CONCURRENT_ID = "CONCURRENT_ID";
|
||||
constexpr const char* DIS_SYNC_TIME = "DIS_SYNC_TIME";
|
||||
constexpr const char* PACKAGE_NAME = "PACKAGE_NAME";
|
||||
constexpr const char* PEER_NET_ID = "PEER_NET_ID";
|
||||
constexpr const char *EVENT_NAME = "DISTRIBUTED_PASTEBOARD_BEHAVIOR";
|
||||
constexpr const char *ORG_PKG = "distributeddata";
|
||||
constexpr const char *BIZ_STATE = "BIZ_STATE";
|
||||
constexpr const char *ERROR_CODE = "ERROR_CODE";
|
||||
constexpr const char *SET_DATA_APP = "SET_DATA_APP";
|
||||
constexpr const char *SET_DATA_TYPE = "SET_DATA_TYPE";
|
||||
constexpr const char *GET_DATA_APP = "GET_DATA_APP";
|
||||
constexpr const char *GET_DATA_TYPE = "GET_DATA_TYPE";
|
||||
constexpr const char *LOCAL_DEV_TYPE = "LOCAL_DEV_TYPE";
|
||||
constexpr const char *COVER_DELAY_DATA = "COVER_DELAY_DATA";
|
||||
constexpr const char *SEND_BROADCAST_TIME = "SEND_BROADCAST_TIME_64";
|
||||
constexpr const char *RECEIVE_BROADCAST_TIME = "RECEIVE_BROADCAST_TIME_64";
|
||||
constexpr const char *SEQ_ID = "SEQ_ID";
|
||||
constexpr const char *CONCURRENT_ID = "CONCURRENT_ID";
|
||||
constexpr const char *DIS_SYNC_TIME = "DIS_SYNC_TIME";
|
||||
constexpr const char *PACKAGE_NAME = "PACKAGE_NAME";
|
||||
constexpr const char *PEER_NET_ID = "PEER_NET_ID";
|
||||
constexpr const char *PEER_UDID = "PEER_UDID";
|
||||
constexpr HiviewDFX::HiSysEvent::EventType TYPE = HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
|
||||
|
||||
#define RADAR_REPORT(bizScene, bizStage, stageRes, ...) \
|
||||
@ -135,4 +136,4 @@ constexpr HiviewDFX::HiSysEvent::EventType TYPE = HiviewDFX::HiSysEvent::EventTy
|
||||
} // namespace RadarReporter
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
#endif //DISTRIBUTEDDATAMGR_PASTEBOARD_EVENT_DFX_H
|
||||
#endif // DISTRIBUTEDDATAMGR_PASTEBOARD_EVENT_DFX_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user