!913 fix:shareOption增加local device判断

Merge pull request !913 from quyihao/master
This commit is contained in:
openharmony_ci 2024-10-18 12:20:53 +00:00 committed by Gitee
commit 6ce5424633
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 41 additions and 12 deletions

View File

@ -2048,20 +2048,17 @@ bool PasteboardService::SetDistributedData(int32_t user, PasteData &data)
if (!IsAllowSendData()) {
return false;
}
if (data.GetShareOption() == InApp) {
PASTEBOARD_HILOGE(
PASTEBOARD_MODULE_SERVICE, "data share option is in app, dataId:%{public}d", data.GetDataId());
return false;
}
ShareOption shareOpt = data.GetShareOption();
PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(shareOpt != InApp, false, PASTEBOARD_MODULE_SERVICE,
"data share option is in app, dataId:%{public}u", data.GetDataId());
PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(shareOpt != LocalDevice, false, PASTEBOARD_MODULE_SERVICE,
"data share option is local device, dataId:%{public}u", data.GetDataId());
auto networkId = DMAdapter::GetInstance().GetLocalNetworkId();
if (networkId.empty()) {
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "networkId is empty.");
return false;
}
PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(!networkId.empty(), false, PASTEBOARD_MODULE_SERVICE, "networkId is empty.");
auto clipPlugin = GetClipPlugin();
if (clipPlugin == nullptr) {
RADAR_REPORT(DFX_SET_PASTEBOARD, DFX_CHECK_ONLINE_DEVICE, DFX_SUCCESS);
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "clip plugin is null, dataId:%{public}d", data.GetDataId());
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "clip plugin is null, dataId:%{public}u", data.GetDataId());
return false;
}
RADAR_REPORT(DFX_SET_PASTEBOARD, DFX_LOAD_DISTRIBUTED_PLUGIN, DFX_SUCCESS);
@ -2076,7 +2073,7 @@ bool PasteboardService::SetDistributedData(int32_t user, PasteData &data)
event.status = ClipPlugin::EVT_NORMAL;
event.dataType = data.GetMimeTypes();
currentEvent_ = event;
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "dataId:%{public}d, seqId:%{public}d, expiration:%{public}" PRIu64,
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "dataId:%{public}u, seqId:%{public}hu, expiration:%{public}" PRIu64,
data.GetDataId(), event.seqId, event.expiration);
std::thread thread([this, clipPlugin, event, user, data]() mutable {
if (data.IsDelayRecord()) {
@ -2086,7 +2083,7 @@ bool PasteboardService::SetDistributedData(int32_t user, PasteData &data)
std::vector<uint8_t> rawData;
if (!data.Encode(rawData)) {
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE,
"distributed data encode failed, dataId:%{public}d, seqId:%{public}d", data.GetDataId(), event.seqId);
"distributed data encode failed, dataId:%{public}u, seqId:%{public}hu", data.GetDataId(), event.seqId);
} else {
clipPlugin->SetPasteData(event, rawData);
}

View File

@ -95,6 +95,38 @@ static constexpr OHOS::HiviewDFX::HiLogLabel PASTEBOARD[PASTEBOARD_MODULE_BUTT]
"%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__)); \
} \
} while (0)
// check then return ret and print log
#define CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, log, label, fmt, ...) \
do { \
if (!(cond)) { \
log(label, fmt, ##__VA_ARGS__); \
return ret; \
} \
} while (0)
// check then return and print log
#define CHECK_AND_RETURN_LOG_INNER(cond, log, label, fmt, ...) \
do { \
if (!(cond)) { \
log(label, fmt, ##__VA_ARGS__); \
return; \
} \
} while (0)
#define PASTEBOARD_CHECK_AND_RETURN_RET_LOGD(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGD, label, fmt, ##__VA_ARGS__)
#define PASTEBOARD_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGW, label, fmt, ##__VA_ARGS__)
#define PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGE, label, fmt, ##__VA_ARGS__)
#define PASTEBOARD_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGD, label, fmt, ##__VA_ARGS__)
#define PASTEBOARD_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGW, label, fmt, ##__VA_ARGS__)
#define PASTEBOARD_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGE, label, fmt, ##__VA_ARGS__)
} // namespace MiscServices
} // namespace OHOS