mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-27 09:41:43 +00:00
slove conflict
Signed-off-by: Dragon51 <longchao14@h-partners.com>
This commit is contained in:
commit
7d20022eea
@ -195,10 +195,17 @@ void JsEventTarget::AddListener(napi_env env, const std::string &type, napi_valu
|
||||
iter->second.push_back(monitor);
|
||||
}
|
||||
if (!isListeningProcess_) {
|
||||
int32_t errCode = INTERACTION_MGR->RegisterCoordinationListener(shared_from_this(), isCompatible);
|
||||
if (errCode != RET_OK) {
|
||||
UtilNapiError::HandleExecuteResult(env, errCode, "on", COOPERATE_PERMISSION);
|
||||
if (int32_t errCode = INTERACTION_MGR->RegisterCoordinationListener(shared_from_this(), isCompatible);
|
||||
errCode != RET_OK) {
|
||||
FI_HILOGE("RegisterEventListener failed, ret:%{public}d", errCode);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
if (auto iter = coordinationListeners_.find(listenerType); iter != coordinationListeners_.end()) {
|
||||
iter->second.pop_back();
|
||||
}
|
||||
}
|
||||
RELEASE_CALLBACKINFO(env, ref);
|
||||
UtilNapiError::HandleExecuteResult(env, errCode, "on", COOPERATE_PERMISSION);
|
||||
} else {
|
||||
isListeningProcess_ = true;
|
||||
}
|
||||
@ -275,8 +282,14 @@ void JsEventTarget::AddListener(napi_env env, const std::string &type, const std
|
||||
errCode != RET_OK) {
|
||||
FI_HILOGE("RegisterEventListener for networkId:%{public}s failed, ret:%{public}d",
|
||||
Utility::Anonymize(networkId).c_str(), errCode);
|
||||
UtilNapiError::HandleExecuteResult(env, errCode, "on", COOPERATE_PERMISSION);
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> guard(mutex_);
|
||||
if (auto iter = mouseLocationListeners_.find(networkId); iter != mouseLocationListeners_.end()) {
|
||||
iter->second.pop_back();
|
||||
}
|
||||
}
|
||||
RELEASE_CALLBACKINFO(env, ref);
|
||||
UtilNapiError::HandleExecuteResult(env, errCode, "on", COOPERATE_PERMISSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1310,6 +1310,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Mouse, TestSiz
|
||||
std::make_shared<UnitTestStartDragListener>(callback));
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
|
||||
InteractionManager::GetInstance()->SetDragWindowScreenId(TOUCH_POINTER_ID, TOUCH_POINTER_ID);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
|
||||
|
@ -267,6 +267,8 @@ struct CooperateEvent {
|
||||
inline constexpr int32_t DEFAULT_TIMEOUT { 3000 };
|
||||
inline constexpr int32_t REPEAT_ONCE { 1 };
|
||||
inline constexpr int32_t DEFAULT_COOLING_TIME { 10 };
|
||||
inline constexpr int32_t UP_WAIT_TIMEOUT { 100 };
|
||||
inline constexpr uint32_t MOTION_DRAG_PRIV { 0x1 };
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -62,6 +62,7 @@ private:
|
||||
|
||||
void SetPointerVisible(Context &context);
|
||||
void UnchainConnections(Context &context, const StopCooperateEvent &event) const;
|
||||
void OnSetCooperatePriv(uint32_t priv);
|
||||
|
||||
IContext *env_ { nullptr };
|
||||
std::shared_ptr<Initial> initial_ { nullptr };
|
||||
|
@ -64,6 +64,7 @@ private:
|
||||
void StopCooperate(Context &context, const CooperateEvent &event);
|
||||
void SetPointerVisible(Context &context);
|
||||
void UnchainConnections(Context &context, const StopCooperateEvent &event) const;
|
||||
void OnSetCooperatePriv(uint32_t priv);
|
||||
|
||||
IContext *env_ { nullptr };
|
||||
std::shared_ptr<Initial> initial_ { nullptr };
|
||||
|
@ -44,6 +44,7 @@ private:
|
||||
void ReportPointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
|
||||
|
||||
IContext *env_ { nullptr };
|
||||
int32_t timerId_ { -1 };
|
||||
int32_t interceptorId_ { -1 };
|
||||
std::string remoteNetworkId_;
|
||||
Channel<CooperateEvent>::Sender sender_;
|
||||
|
@ -60,11 +60,11 @@ void CooperateFree::OnLeaveState(Context &context)
|
||||
|
||||
void CooperateFree::SetPointerVisible(Context &context)
|
||||
{
|
||||
CHKPV(env_);
|
||||
bool hasLocalPointerDevice = env_->GetDeviceManager().HasLocalPointerDevice();
|
||||
bool visible = !context.NeedHideCursor() && hasLocalPointerDevice;
|
||||
FI_HILOGI("Set pointer visible:%{public}s, HasLocalPointerDevice:%{public}s",
|
||||
visible ? "true" : "false", hasLocalPointerDevice ? "true" : "false");
|
||||
CHKPV(env_);
|
||||
env_->GetInput().SetPointerVisibility(visible, PRIORITY);
|
||||
}
|
||||
|
||||
@ -78,6 +78,12 @@ void CooperateFree::UnchainConnections(Context &context, const StopCooperateEven
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateFree::OnSetCooperatePriv(uint32_t priv)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
env_->GetDragManager().SetCooperatePriv(priv);
|
||||
}
|
||||
|
||||
CooperateFree::Initial::Initial(CooperateFree &parent)
|
||||
: ICooperateStep(parent, nullptr), parent_(parent)
|
||||
{
|
||||
@ -173,6 +179,7 @@ void CooperateFree::Initial::OnRemoteStart(Context &context, const CooperateEven
|
||||
CALL_INFO_TRACE;
|
||||
DSoftbusStartCooperate notice = std::get<DSoftbusStartCooperate>(event.event);
|
||||
context.OnRemoteStartCooperate(notice.extra);
|
||||
parent_.OnSetCooperatePriv(notice.extra.priv);
|
||||
context.eventMgr_.RemoteStart(notice);
|
||||
context.RemoteStartSuccess(notice);
|
||||
context.inputEventBuilder_.Enable(context);
|
||||
|
@ -58,14 +58,20 @@ void CooperateOut::OnLeaveState(Context &context)
|
||||
|
||||
void CooperateOut::SetPointerVisible(Context &context)
|
||||
{
|
||||
CHKPV(env_);
|
||||
bool hasLocalPointerDevice = env_->GetDeviceManager().HasLocalPointerDevice();
|
||||
bool visible = !context.NeedHideCursor() && hasLocalPointerDevice;
|
||||
FI_HILOGI("Set pointer visible:%{public}s, HasLocalPointerDevice:%{public}s",
|
||||
visible ? "true" : "false", hasLocalPointerDevice ? "true" : "false");
|
||||
CHKPV(env_);
|
||||
env_->GetInput().SetPointerVisibility(visible, PRIORITY);
|
||||
}
|
||||
|
||||
void CooperateOut::OnSetCooperatePriv(uint32_t priv)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
env_->GetDragManager().SetCooperatePriv(priv);
|
||||
}
|
||||
|
||||
void CooperateOut::Initial::BuildChains(std::shared_ptr<Initial> self, CooperateOut &parent)
|
||||
{}
|
||||
|
||||
@ -169,6 +175,7 @@ void CooperateOut::Initial::OnComeBack(Context &context, const CooperateEvent &e
|
||||
}
|
||||
FI_HILOGI("[come back] From \'%{public}s\'", Utility::Anonymize(notice.networkId).c_str());
|
||||
context.OnRemoteStartCooperate(notice.extra);
|
||||
parent_.OnSetCooperatePriv(notice.extra.priv);
|
||||
DSoftbusStartCooperate startEvent {
|
||||
.networkId = notice.networkId,
|
||||
};
|
||||
|
@ -94,6 +94,15 @@ void InputEventInterceptor::OnPointerEvent(std::shared_ptr<MMI::PointerEvent> po
|
||||
FI_HILOGI("Reset to origin action:%{public}d", static_cast<int32_t>(originAction));
|
||||
pointerEvent->SetPointerAction(originAction);
|
||||
}
|
||||
if ((pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
|
||||
(pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP)) {
|
||||
timerId_ = env_->GetTimerManager().AddTimer(UP_WAIT_TIMEOUT, REPEAT_ONCE, [this]() {
|
||||
if (env_->GetDragManager().GetCooperatePriv() & MOTION_DRAG_PRIV) {
|
||||
FI_HILOGW("There is an up event when dragging");
|
||||
env_->GetDragManager().SetAllowStartDrag(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
NetPacket packet(MessageId::DSOFTBUS_INPUT_POINTER_EVENT);
|
||||
|
||||
int32_t ret = InputEventSerialization::Marshalling(pointerEvent, packet);
|
||||
|
@ -599,18 +599,23 @@ void StateMachine::AddMonitor(Context &context)
|
||||
return;
|
||||
}
|
||||
CHKPV(env_);
|
||||
monitorId_ = env_->GetInput().AddMonitor(
|
||||
[sender = context.Sender(), &hotArea = context.hotArea_, &mouseLocation = context.mouseLocation_] (
|
||||
monitorId_ = env_->GetInput().AddMonitor([&context, this] (
|
||||
std::shared_ptr<MMI::PointerEvent> pointerEvent) mutable {
|
||||
hotArea.ProcessData(pointerEvent);
|
||||
mouseLocation.ProcessData(pointerEvent);
|
||||
context.hotArea_.ProcessData(pointerEvent);
|
||||
context.mouseLocation_.ProcessData(pointerEvent);
|
||||
|
||||
MMI::PointerEvent::PointerItem pointerItem;
|
||||
if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
|
||||
FI_HILOGE("Corrupted pointer event");
|
||||
return;
|
||||
}
|
||||
auto ret = sender.Send(CooperateEvent(
|
||||
if ((env_->GetDragManager().GetCooperatePriv() & MOTION_DRAG_PRIV) &&
|
||||
(pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
|
||||
(pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP)) {
|
||||
FI_HILOGW("There is an up event when dragging");
|
||||
env_->GetDragManager().SetAllowStartDrag(false);
|
||||
}
|
||||
auto ret = context.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::INPUT_POINTER_EVENT,
|
||||
InputPointerEvent {
|
||||
.deviceId = pointerEvent->GetDeviceId(),
|
||||
|
@ -94,6 +94,9 @@ public:
|
||||
#ifndef OHOS_BUILD_ENABLE_ARKUI_X
|
||||
virtual int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) = 0;
|
||||
#endif // OHOS_BUILD_ENABLE_ARKUI_X
|
||||
virtual void SetAllowStartDrag(bool hasUpEvent) = 0;
|
||||
virtual void SetCooperatePriv(uint32_t priv) = 0;
|
||||
virtual uint32_t GetCooperatePriv() const = 0;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -89,6 +89,9 @@ public:
|
||||
int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) override;
|
||||
int32_t RotateDragWindow(Rosen::Rotation rotation) override;
|
||||
void SetDragWindowScreenId(uint64_t displayId, uint64_t screenId) override;
|
||||
void SetAllowStartDrag(bool hasUpEvent) override;
|
||||
void SetCooperatePriv(uint32_t priv) override;
|
||||
uint32_t GetCooperatePriv() const override;
|
||||
#ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
|
||||
class InterceptorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
@ -140,12 +143,15 @@ private:
|
||||
DragCursorStyle GetRealDragStyle(DragCursorStyle style);
|
||||
void GetDragBehavior(const DragDropResult &dropResult, DragBehavior &dragBehavior);
|
||||
int32_t NotifyAddSelectedPixelMapResult(bool result);
|
||||
bool IsAllowStartDrag() const;
|
||||
private:
|
||||
int32_t timerId_ { -1 };
|
||||
StateChangeNotify stateNotify_;
|
||||
DragState dragState_ { DragState::STOP };
|
||||
DragResult dragResult_ { DragResult::DRAG_FAIL };
|
||||
int32_t keyEventMonitorId_ { -1 };
|
||||
bool hasUpEvent_ { true };
|
||||
uint32_t priv_ { 0 };
|
||||
std::atomic<DragAction> dragAction_ { DragAction::MOVE };
|
||||
#ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
|
||||
int32_t pointerEventInterceptorId_ { -1 };
|
||||
|
@ -191,18 +191,28 @@ void DragManager::PrintDragData(const DragData &dragData, const std::string &pac
|
||||
int32_t DragManager::StartDrag(const DragData &dragData, int32_t pid)
|
||||
{
|
||||
FI_HILOGI("enter");
|
||||
if (!IsAllowStartDrag()) {
|
||||
FI_HILOGE("Dragging is not allowed when there is an up event");
|
||||
SetAllowStartDrag(true);
|
||||
SetCooperatePriv(0);
|
||||
return RET_ERR;
|
||||
}
|
||||
if (dragState_ == DragState::START) {
|
||||
FI_HILOGE("Drag instance already exists, no need to start drag again");
|
||||
return RET_ERR;
|
||||
}
|
||||
std::string packageName = std::string();
|
||||
CHKPR(context_, RET_ERR);
|
||||
dragOutSession_ = context_->GetSocketSessionManager().FindSessionByPid(pid);
|
||||
if (dragOutSession_ != nullptr) {
|
||||
if (pid == -1) {
|
||||
packageName = "Cross-device drag";
|
||||
} else {
|
||||
context_->GetSocketSessionManager().AddSessionDeletedCallback(pid,
|
||||
[this](SocketSessionPtr session) { this->OnSessionLost(session); });
|
||||
dragOutSession_ = context_->GetSocketSessionManager().FindSessionByPid(pid);
|
||||
if (dragOutSession_ != nullptr) {
|
||||
packageName = dragOutSession_->GetProgramName();
|
||||
}
|
||||
}
|
||||
packageName = (pid == -1) ? "Cross-device drag" : dragOutSession_->GetProgramName();
|
||||
PrintDragData(dragData, packageName);
|
||||
if (InitDataManager(dragData) != RET_OK) {
|
||||
FI_HILOGE("Failed to init data manager");
|
||||
@ -260,6 +270,8 @@ int32_t DragManager::StopDrag(const DragDropResult &dropResult, const std::strin
|
||||
FI_HILOGE("Notify drag result failed");
|
||||
}
|
||||
DRAG_DATA_MGR.ResetDragData();
|
||||
SetAllowStartDrag(true);
|
||||
SetCooperatePriv(0);
|
||||
dragResult_ = static_cast<DragResult>(dropResult.result);
|
||||
StateChangedNotify(DragState::STOP);
|
||||
SetDragState(DragState::STOP);
|
||||
@ -1333,6 +1345,26 @@ int32_t DragManager::AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap>
|
||||
FI_HILOGD("leave");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void DragManager::SetAllowStartDrag(bool hasUpEvent)
|
||||
{
|
||||
hasUpEvent_ = hasUpEvent;
|
||||
}
|
||||
|
||||
bool DragManager::IsAllowStartDrag() const
|
||||
{
|
||||
return hasUpEvent_;
|
||||
}
|
||||
|
||||
void DragManager::SetCooperatePriv(uint32_t priv)
|
||||
{
|
||||
priv_ = priv;
|
||||
}
|
||||
|
||||
uint32_t DragManager::GetCooperatePriv() const
|
||||
{
|
||||
return priv_;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -66,9 +66,7 @@ void DragVSyncStation::StopVSyncRequest()
|
||||
handler_->RemoveAllFileDescriptorListeners();
|
||||
handler_ = nullptr;
|
||||
}
|
||||
if (receiver_ != nullptr) {
|
||||
receiver_ = nullptr;
|
||||
}
|
||||
receiver_ = nullptr;
|
||||
vSyncPeriod_ = 0;
|
||||
if (mmiHandleTid_ > 0) {
|
||||
OHOS::QOS::ResetQosForOtherThread(mmiHandleTid_);
|
||||
@ -157,7 +155,7 @@ void DragVSyncStation::OnVSyncInner(uint64_t nanoTimestamp)
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
vSyncCallbacks.swap(vSyncCallbacks_);
|
||||
}
|
||||
for (auto &callback : vSyncCallbacks) {
|
||||
for (auto const &callback : vSyncCallbacks) {
|
||||
if (callback.second != nullptr) {
|
||||
(*callback.second)(nanoTimestamp);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ group("device_status_fuzztest") {
|
||||
"devicestatusclient_fuzzer:fuzztest",
|
||||
"devicesubscribestub_fuzzer:fuzztest",
|
||||
"deviceunsubscribestub_fuzzer:fuzztest",
|
||||
"dsoftbusadapter_fuzzer:fuzztest",
|
||||
"entertexteditorarea_fuzzer:fuzztest",
|
||||
"getdragaction_fuzzer:fuzztest",
|
||||
"getdragdata_fuzzer:fuzztest",
|
||||
|
73
test/fuzztest/dsoftbusadapter_fuzzer/BUILD.gn
Normal file
73
test/fuzztest/dsoftbusadapter_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,73 @@
|
||||
# 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.
|
||||
import("../../../device_status.gni")
|
||||
|
||||
###############################hydra_fuzz#################################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "${device_status_fuzz_output_path}"
|
||||
deps_ex = [
|
||||
"ability_runtime:app_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"device_manager:devicemanagersdk",
|
||||
"graphic_2d:libcomposer",
|
||||
"graphic_2d:window_animation",
|
||||
"graphic_2d:librender_service_client",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
"window_manager:libdm",
|
||||
]
|
||||
|
||||
###############################fuzztest#################################
|
||||
ohos_fuzztest("DsoftbusAdapterFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"${device_status_root_path}/test/fuzztest/dsoftbusadapter_fuzzer"
|
||||
include_dirs = [
|
||||
"${device_status_root_path}/libs/interface",
|
||||
"${device_status_service_path}/interaction/drag/include",
|
||||
"${device_status_service_path}/communication/service/include",
|
||||
"${device_status_utils_path}/include",
|
||||
"//third_party/cJSON",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-fno-omit-frame-pointer",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
|
||||
sources = [ "dsoftbusadapter_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_interfaces_path}/innerkits:devicestatus_client",
|
||||
"${device_status_root_path}/intention/adapters/dsoftbus_adapter:intention_dsoftbus_adapter",
|
||||
"${device_status_root_path}/services:devicestatus_static_service",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
]
|
||||
|
||||
external_deps = deps_ex
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":DsoftbusAdapterFuzzTest" ]
|
||||
}
|
14
test/fuzztest/dsoftbusadapter_fuzzer/corpus/init
Normal file
14
test/fuzztest/dsoftbusadapter_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# 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.
|
||||
|
||||
FUZZ
|
114
test/fuzztest/dsoftbusadapter_fuzzer/dsoftbusadapter_fuzzer.cpp
Normal file
114
test/fuzztest/dsoftbusadapter_fuzzer/dsoftbusadapter_fuzzer.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "dsoftbusadapter_fuzzer.h"
|
||||
|
||||
#include "singleton.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "dsoftbus_adapter_impl.h"
|
||||
#include "socket_session_manager.h"
|
||||
|
||||
#include "message_parcel.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "DsoftbusAdapterFuzzTest"
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
#define SERVER_SESSION_NAME "ohos.msdp.device_status.intention.serversession"
|
||||
constexpr size_t PKG_NAME_SIZE_MAX { 65 };
|
||||
constexpr size_t DEVICE_NAME_SIZE_MAX { 256 };
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
class DSoftbusObserver final : public IDSoftbusObserver {
|
||||
public:
|
||||
DSoftbusObserver() = default;
|
||||
~DSoftbusObserver() = default;
|
||||
|
||||
void OnBind(const std::string &networkId) {}
|
||||
void OnShutdown(const std::string &networkId) {}
|
||||
void OnConnected(const std::string &networkId) {}
|
||||
bool OnPacket(const std::string &networkId, NetPacket &packet)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool OnRawData(const std::string &networkId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
bool DsoftbusAdapterFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
std::shared_ptr<IDSoftbusObserver> observer = std::make_shared<DSoftbusObserver>();
|
||||
std::string networkId(reinterpret_cast<const char*>(data), size);
|
||||
NetPacket packet(MessageId::DSOFTBUS_START_COOPERATE);
|
||||
int32_t socket = *(reinterpret_cast<const int32_t*>(data));
|
||||
uint32_t dataLen = *(reinterpret_cast<const uint32_t*>(data));
|
||||
int32_t *g_data = new int32_t(socket);
|
||||
CircleStreamBuffer circleBuffer;
|
||||
Parcel parcel;
|
||||
|
||||
char name[DEVICE_NAME_SIZE_MAX] { SERVER_SESSION_NAME };
|
||||
char pkgName[PKG_NAME_SIZE_MAX] { FI_PKG_NAME };
|
||||
SocketInfo info {
|
||||
.name = name,
|
||||
.pkgName = pkgName,
|
||||
.dataType = DATA_TYPE_BYTES
|
||||
};
|
||||
|
||||
DSoftbusAdapterImpl::GetInstance()->Enable();
|
||||
DSoftbusAdapterImpl::GetInstance()->AddObserver(observer);
|
||||
DSoftbusAdapterImpl::GetInstance()->RemoveObserver(observer);
|
||||
DSoftbusAdapterImpl::GetInstance()->CheckDeviceOnline(networkId);
|
||||
DSoftbusAdapterImpl::GetInstance()->OpenSession(networkId);
|
||||
DSoftbusAdapterImpl::GetInstance()->FindConnection(networkId);
|
||||
DSoftbusAdapterImpl::GetInstance()->SendPacket(networkId, packet);
|
||||
DSoftbusAdapterImpl::GetInstance()->OnShutdown(socket, SHUTDOWN_REASON_UNKNOWN);
|
||||
DSoftbusAdapterImpl::GetInstance()->OnBytes(socket, g_data, dataLen);
|
||||
DSoftbusAdapterImpl::GetInstance()->InitSocket(info, socket, socket);
|
||||
DSoftbusAdapterImpl::GetInstance()->SetupServer();
|
||||
DSoftbusAdapterImpl::GetInstance()->ShutdownServer();
|
||||
DSoftbusAdapterImpl::GetInstance()->OpenSessionLocked(networkId);
|
||||
DSoftbusAdapterImpl::GetInstance()->OnConnectedLocked(networkId);
|
||||
DSoftbusAdapterImpl::GetInstance()->CloseAllSessionsLocked();
|
||||
DSoftbusAdapterImpl::GetInstance()->ConfigTcpAlive(socket);
|
||||
DSoftbusAdapterImpl::GetInstance()->HandleSessionData(networkId, circleBuffer);
|
||||
DSoftbusAdapterImpl::GetInstance()->SendParcel(networkId, parcel);
|
||||
DSoftbusAdapterImpl::GetInstance()->BroadcastPacket(packet);
|
||||
DSoftbusAdapterImpl::GetInstance()->HandlePacket(networkId, packet);
|
||||
DSoftbusAdapterImpl::GetInstance()->HandleRawData(networkId, g_data, dataLen);
|
||||
DSoftbusAdapterImpl::GetInstance()->CloseSession(networkId);
|
||||
DSoftbusAdapterImpl::GetInstance()->CloseAllSessions();
|
||||
DSoftbusAdapterImpl::GetInstance()->Disable();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace OHOS
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OHOS::DsoftbusAdapterFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 DSOFTBUSADAPTER_FUZZER_H
|
||||
#define DSOFTBUSADAPTER_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "dsoftbusadapter_fuzzer"
|
||||
|
||||
#endif // DSOFTBUSADAPTER_FUZZER_H
|
25
test/fuzztest/dsoftbusadapter_fuzzer/project.xml
Normal file
25
test/fuzztest/dsoftbusadapter_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2023 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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
Loading…
Reference in New Issue
Block a user