add interface RegisterThumbnailDraw UnregisterThumbnailDraw

Signed-off-by: mayunteng_1 <mayunteng@huawei.com>
Change-Id: I771cf7ccff3c3f3a99f509bae43c672dbe5bc02e
This commit is contained in:
mayunteng_1 2023-02-09 06:32:14 +00:00
commit 93b1c2c51e
34 changed files with 462 additions and 102 deletions

View File

@ -200,10 +200,10 @@ void DeviceStatusEvent::SendRet(int32_t eventType, int32_t value, napi_value &re
DEV_HILOGE(JS_NAPI, "Failed to set name");
return;
}
bool flag = (value == 1);
status = napi_get_boolean(env_, flag, &tmpValue);
status = napi_create_int32(env_, value, &tmpValue);
if (status != napi_ok) {
DEV_HILOGE(JS_NAPI, "Failed to get_boolean");
DEV_HILOGE(JS_NAPI, "Failed to create value");
return;
}
status = napi_set_named_property(env_, result, "value", tmpValue);

View File

@ -37,14 +37,14 @@ public:
int32_t UpdateDragStyle(int32_t style);
int32_t UpdateDragMessage(const std::u16string &message);
int32_t GetDragTargetPid();
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback);
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t)> callback);
int32_t StopDrag(int32_t result);
int32_t RegisterThumbnailDraw(std::function<void(int32_t, int32_t)> startCallback,
std::function<void(int32_t, int32_t)> noticeCallback, std::function<void(int32_t)> endCallback);
int32_t UnregisterThumbnailDraw(std::function<void(int32_t)> callback);
private:
std::mutex mtx_;
std::function<void(int32_t&)> stopCallback_;
std::function<void(int32_t)> stopCallback_;
bool hasRegisterThumbnailDraw_ { false };
ThumbnailDrawCallback thumbnailDrawCallback_;
};

View File

@ -42,7 +42,7 @@ public:
int32_t GetCoordinationState(const std::string &deviceId, std::function<void(bool)> callback);
int32_t UpdateDragStyle(int32_t style);
int32_t UpdateDragMessage(const std::u16string &message);
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback);
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t)> callback);
int32_t StopDrag(int32_t result);
int32_t GetDragTargetPid();
int32_t RegisterThumbnailDraw(std::function<void(int32_t, int32_t)> startCallback,

View File

@ -38,7 +38,7 @@ int32_t DragManagerImpl::UpdateDragMessage(const std::u16string &message)
return DeviceStatusClient::GetInstance().UpdateDragMessage(message);
}
int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback)
int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::function<void(int32_t)> callback)
{
CALL_DEBUG_ENTER;
if (callback == nullptr) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -75,7 +75,7 @@ int32_t InteractionManager::UpdateDragMessage(const std::u16string &message)
return InteractionMgrImpl.UpdateDragMessage(message);
}
int32_t InteractionManager::StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback)
int32_t InteractionManager::StartDrag(const DragData &dragData, std::function<void(int32_t)> callback)
{
return InteractionMgrImpl.StartDrag(dragData, callback);
}

View File

@ -188,7 +188,7 @@ int32_t InteractionManagerImpl::UpdateDragMessage(const std::u16string &message)
return dragManagerImpl_.UpdateDragMessage(message);
}
int32_t InteractionManagerImpl::StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback)
int32_t InteractionManagerImpl::StartDrag(const DragData &dragData, std::function<void(int32_t)> callback)
{
CALL_DEBUG_ENTER;
std::lock_guard<std::mutex> guard(mutex_);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -51,14 +51,14 @@ void InteractionManagerTest::TearDown()
}
std::unique_ptr<OHOS::Media::PixelMap> CreatePixelMap(int32_t pixelMapWidth, int32_t pixelMapHeight)
std::shared_ptr<OHOS::Media::PixelMap> CreatePixelMap(int32_t pixelMapWidth, int32_t pixelMapHeight)
{
if (pixelMapWidth <= 0 || pixelMapWidth > MAX_PIXEL_MAP_WIDTH ||
pixelMapHeight <= 0 || pixelMapHeight > MAX_PIXEL_MAP_HEIGHT) {
std::cout << "Invalid pixelMapWidth or pixelMapHeight" << std::endl;
return nullptr;
}
std::unique_ptr<OHOS::Media::PixelMap> pixelMap = std::make_unique<OHOS::Media::PixelMap>();
std::shared_ptr<OHOS::Media::PixelMap> pixelMap = std::make_shared<OHOS::Media::PixelMap>();
OHOS::Media::ImageInfo info;
info.size.width = pixelMapWidth;
info.size.height = pixelMapHeight;
@ -84,7 +84,8 @@ void SetParam(int32_t width, int32_t height, DragData& dragData)
dragData.x = 0;
dragData.y = 0;
dragData.buffer = std::vector<uint8_t>(MAX_BUFFER_SIZE, 0);
dragData.sourceType = -1;
dragData.sourceType = 0;
dragData.dragNum = 0;
}
/**
@ -240,6 +241,24 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetCoordinationState, Te
#endif // OHOS_BUILD_ENABLE_COORDINATION
}
/**
* @tc.name: InteractionManagerTest_StartDrag
* @tc.desc: Start Drag
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag, TestSize.Level1)
{
CALL_TEST_DEBUG;
DragData dragData;
SetParam(3, 4, dragData);
std::function<void(int32_t)> callback = [](int32_t result) {
FI_HILOGD("StartDrag success");
};
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData, callback);
ASSERT_EQ(ret, RET_OK);
}
/**
* @tc.name: InteractionManagerTest_StopDrag
* @tc.desc: Stop drag
@ -254,24 +273,6 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag, TestSize.Level
ASSERT_EQ(ret, RET_OK);
}
/**
* @tc.name: InteractionManagerTest_StartDrag
* @tc.desc: Start Drag
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_001, TestSize.Level1)
{
CALL_TEST_DEBUG;
DragData dragData;
SetParam(3, 4, dragData);
std::function<void(int32_t &)> callback = [](int32_t &result) {
FI_HILOGD("StartDrag success");
};
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData, callback);
ASSERT_EQ(ret, RET_OK);
}
/**
* @tc.name: InteractionManagerTest_GetDragTargetPid
* @tc.desc: Get Drag Target Pid

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -29,11 +29,12 @@ static const int32_t MAX_PIXEL_MAP_WIDTH = 200;
static const int32_t MAX_PIXEL_MAP_HEIGHT = 200;
static const int32_t MAX_BUFFER_SIZE = 512;
struct DragData {
std::unique_ptr<OHOS::Media::PixelMap> pixelMap;
std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
int32_t x { -1 };
int32_t y { -1 };
std::vector<uint8_t> buffer;
int32_t sourceType { -1 };
int32_t dragNum { -1 };
};
enum class DragState {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -94,10 +94,10 @@ public:
* @return 0
* @since 10
*/
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback);
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t)> callback);
/**
* @brief
* @brief
* @param result 0-,1-,2-
* @return 0
* @since 10

View File

@ -71,7 +71,7 @@ private:
int32_t timerFd_ {-1};
int32_t epFd_ {-1};
std::mutex mutex_;
std::vector<int32_t> enabledType_;
std::vector<Type> enabledType_;
std::atomic<bool> alive_ {false};
std::shared_ptr<std::thread> thread_;
};

View File

@ -73,7 +73,7 @@ void AlgoBase::UpdateStateAndReport(OnChangedValue value, int32_t state, Type ty
state_ = state;
reportInfo_.type = type;
reportInfo_.value = value;
DEV_HILOGI(SERVICE, "type:%{public}d,value:%{public}d", type, value);
callback_->OnResult(reportInfo_);
}
} // namespace DeviceStatus

View File

@ -57,6 +57,8 @@ bool DeviceStatusDataParse::ParseDeviceStatusData(Data& data, Type type)
std::string jsonBuf = ReadJsonFile(MSDP_DATA_PATH.c_str());
if (jsonBuf.empty()) {
DEV_HILOGE(SERVICE, "read json failed, errno is %{public}d", errno);
data.type = type;
data.value = OnChangedValue::VALUE_INVALID;
return false;
}
return DeviceStatusDataInit(jsonBuf, true, type, data);

View File

@ -36,6 +36,11 @@ DeviceStatusMsdpMock* g_msdpMock = nullptr;
} // namespace
DeviceStatusMsdpMock::DeviceStatusMsdpMock()
{
enabledType_ = {
TYPE_STILL,
TYPE_RELATIVE_STILL,
TYPE_CAR_BLUETOOTH,
};
if (dataParse_ == nullptr) {
dataParse_ = std::make_unique<DeviceStatusDataParse>();
}
@ -106,6 +111,7 @@ ErrCode DeviceStatusMsdpMock::NotifyMsdpImpl(const Data& data)
DEV_HILOGE(SERVICE, "callbacksImpl is nullptr");
return RET_ERR;
}
DEV_HILOGI(SERVICE, "type:%{public}d,value:%{public}d", data.type, data.value);
g_msdpMock->GetCallbackImpl()->OnResult(data);
return RET_OK;
@ -176,8 +182,8 @@ void DeviceStatusMsdpMock::TimerCallback()
void DeviceStatusMsdpMock::GetDeviceStatusData()
{
for (int32_t n = int(Type::TYPE_ABSOLUTE_STILL); n < Type::TYPE_MAX; ++n) {
Type type = Type(n);
for (auto item : enabledType_) {
Type type = item;
if (dataParse_ == nullptr) {
DEV_HILOGE(SERVICE, "dataParse_ is nullptr");
return;

View File

@ -28,8 +28,8 @@ config("devicestatus_services_private_config") {
"//base/msdp/device_status/libs/interface",
"${ability_runtime_path}/interfaces/kits/native/ability/native/",
"${relational_store_innerapi_path}/appdatafwk/include/",
"${device_status_service_path}/interaction/coordination/lib/include",
"${device_status_service_path}//interaction/drag/include",
"interaction/coordination/lib/include",
"interaction/drag/include",
"//utils/system/safwk/native/include",
"communication/base",
"communication/service/include",
@ -45,7 +45,7 @@ config("devicestatus_services_public_config") {
"native/include",
"timer_manager/include",
"device_manager/include",
"${device_status_service_path}//interaction/drag/include",
"interaction/drag/include",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event/include",
"//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include",
]
@ -78,6 +78,7 @@ ohos_shared_library("devicestatus_service") {
"${device_status_interfaces_path}/innerkits:devicestatus_client",
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
"${device_status_utils_path}:devicestatus_util",
"interaction/drag:interaction_drag",
"//drivers/peripheral/sensor/hal:hdi_sensor",
"//third_party/openssl:libcrypto_shared",
]

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -330,6 +330,7 @@ int32_t DeviceStatusSrvProxy::StartDrag(const DragData &dragData)
WRITEINT32(data, dragData.y, ERR_INVALID_VALUE);
WRITEUINT8VECTOR(data, dragData.buffer, ERR_INVALID_VALUE);
WRITEINT32(data, dragData.sourceType, ERR_INVALID_VALUE);
WRITEINT32(data, dragData.dragNum, ERR_INVALID_VALUE);
MessageParcel reply;
MessageOption option;
sptr<IRemoteObject> remote = Remote();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -328,7 +328,7 @@ int32_t DeviceStatusSrvStub::StubStartDrag(MessageParcel& data, MessageParcel& r
auto pixelMap = OHOS::Media::PixelMap::Unmarshalling(data);
CHKPR(pixelMap, RET_ERR);
DragData dragData;
dragData.pixelMap = std::unique_ptr<OHOS::Media::PixelMap> (pixelMap);
dragData.pixelMap = std::shared_ptr<OHOS::Media::PixelMap> (pixelMap);
if (dragData.pixelMap->GetWidth() > MAX_PIXEL_MAP_WIDTH ||
dragData.pixelMap->GetHeight() > MAX_PIXEL_MAP_HEIGHT) {
FI_HILOGE("Too big pixelMap, width:%{public}d, height:%{public}d",
@ -343,6 +343,7 @@ int32_t DeviceStatusSrvStub::StubStartDrag(MessageParcel& data, MessageParcel& r
return RET_ERR;
}
READINT32(data, dragData.sourceType, E_DEVICESTATUS_READ_PARCEL_ERROR);
READINT32(data, dragData.dragNum, E_DEVICESTATUS_READ_PARCEL_ERROR);
int32_t ret = StartDrag(dragData);
if (ret != RET_OK) {
FI_HILOGE("Call StartDrag failed ret:%{public}d", ret);

View File

@ -0,0 +1,54 @@
# 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.
import("//base/msdp/device_status/device_status.gni")
config("drag_private_config") {
include_dirs = [ "include" ]
}
ohos_shared_library("interaction_drag") {
include_dirs = [
"${device_status_interfaces_path}/innerkits/interaction/include",
"${device_status_utils_path}/include",
"${device_status_service_path}/context/include",
]
sources = [
"src/drag_data_adapter.cpp",
"src/drag_manager.cpp",
]
configs = [ ":drag_private_config" ]
defines = device_status_default_defines
deps = [
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
"${device_status_utils_path}:devicestatus_util",
]
external_deps = [
"c_utils:utils",
"eventhandler:libeventhandler",
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
"input:libmmi-client",
"ipc:ipc_core",
"multimedia_image_framework:image_native",
"window_manager:libdm",
]
subsystem_name = "msdp"
part_name = "${device_status_part_name}"
}

View File

@ -0,0 +1,61 @@
/*
* 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.
*/
#ifndef DRAG_DATA_ADAPTER_H
#define DRAG_DATA_ADAPTER_H
#include <string>
#include <utility>
#include "extra_data.h"
#include "hitrace_meter.h"
#include "pixel_map.h"
#include "pointer_style.h"
#include "singleton.h"
#include "drag_data.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DragDataAdapter final {
DECLARE_SINGLETON(DragDataAdapter);
public:
DISALLOW_MOVE(DragDataAdapter);
void Init(const DragData &dragData, const MMI::PointerStyle &pointerStyle);
OHOS::MMI::ExtraData GetExtraData() const;
std::pair<int, int> GetCoordinate() const;
OHOS::Media::PixelMap GetPixelMap() const;
int32_t GetDragNum() const;
int32_t GetDragStyle() const;
std::u16string GetDragMessage() const;
private:
OHOS::Media::PixelMap pixelMap_;
OHOS::MMI::ExtraData extraData_;
std::pair<int, int> coordinate_;
int32_t dragNum_ { -1 };
int32_t dragStyle_ { -1 };
std::u16string dragMessage_;
OHOS::MMI::PointerStyle pointerStyle_;
};
#define DataAdapter ::OHOS::Singleton<DragDataAdapter>::GetInstance()
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS
#endif // DRAG_DATA_ADAPTER_H

View File

@ -0,0 +1,48 @@
/*
* 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.
*/
#ifndef DRAG_MANAGER_H
#define DRAG_MANAGER_H
#include <string>
#include "i_input_event_consumer.h"
#include "input_manager.h"
#include "pixel_map.h"
#include "devicestatus_define.h"
#include "drag_data.h"
#include "stream_session.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DragManager {
public:
DragManager() = default;
~DragManager() = default;
int32_t StartDrag(const DragData &dragData, SessionPtr sess);
int32_t StopDrag(int32_t result);
int32_t GetDragTargetPid() const;
private:
DragState dragState_ { DragState::FREE };
SessionPtr dragOutSession_ { nullptr };
int32_t dragTargetPid_ { -1 };
};
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS
#endif // DRAG_MANAGER_H

View File

@ -0,0 +1,78 @@
/*
* 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.
*/
#include "drag_data_adapter.h"
#include "hitrace_meter.h"
#include "pointer_style.h"
#include "devicestatus_define.h"
#include "drag_data.h"
#include "fi_log.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DragDataAdapter" };
} // namespace
DragDataAdapter::DragDataAdapter() = default;
DragDataAdapter::~DragDataAdapter() = default;
void DragDataAdapter::Init(const DragData &dragData, const MMI::PointerStyle &pointerStyle)
{
CALL_DEBUG_ENTER;
extraData_.buffer = dragData.buffer;
extraData_.sourceType = dragData.sourceType;
extraData_.appended = false;
coordinate_ = std::make_pair(dragData.x, dragData.y);
pixelMap_ = *dragData.pixelMap;
dragNum_ = dragData.dragNum;
pointerStyle_ = pointerStyle;
}
OHOS::MMI::ExtraData DragDataAdapter::GetExtraData() const
{
return extraData_;
}
std::pair<int, int> DragDataAdapter::GetCoordinate() const
{
return coordinate_;
}
OHOS::Media::PixelMap DragDataAdapter::GetPixelMap() const
{
return pixelMap_;
}
int32_t DragDataAdapter::GetDragNum() const
{
return dragNum_;
}
int32_t DragDataAdapter::GetDragStyle() const
{
return dragStyle_;
}
std::u16string DragDataAdapter::GetDragMessage() const
{
return dragMessage_;
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -0,0 +1,68 @@
/*
* 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.
*/
#include "drag_manager.h"
#include "extra_data.h"
#include "hitrace_meter.h"
#include "input_manager.h"
#include "pixel_map.h"
#include "pointer_style.h"
#include "devicestatus_define.h"
#include "drag_data.h"
#include "drag_data_adapter.h"
#include "fi_log.h"
#include "proto.h"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
namespace {
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DragManager" };
} // namespace
int32_t DragManager::StartDrag(const DragData &dragData, SessionPtr sess)
{
CALL_DEBUG_ENTER;
if (dragState_ == DragState::DRAGGING) {
FI_HILOGE("Drag instance is running, can not start drag again");
return RET_ERR;
}
CHKPR(sess, RET_ERR);
dragOutSession_ = sess;
dragState_ = DragState::DRAGGING;
return RET_OK;
}
int32_t DragManager::StopDrag(int32_t result)
{
CALL_DEBUG_ENTER;
if (dragState_ == DragState::FREE) {
FI_HILOGE("No drag instance running, can not stop drag");
return RET_ERR;
}
dragState_ = DragState::FREE;
return RET_OK;
}
int32_t DragManager::GetDragTargetPid() const
{
return dragTargetPid_;
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -29,6 +29,7 @@
#include "devicestatus_manager.h"
#include "devicestatus_delayed_sp_singleton.h"
#include "drag_data.h"
#include "drag_manager.h"
#include "i_context.h"
#include "idevicestatus_callback.h"
#include "stream_server.h"
@ -148,6 +149,7 @@ private:
DelegateTasks delegateTasks_;
DeviceManager devMgr_;
TimerManager timerMgr_;
DragManager dragMgr_;
std::atomic<bool> ready_ = false;
std::shared_ptr<DeviceStatusManager> devicestatusManager_;
std::shared_ptr<DeviceStatusMsdpClientImpl> msdpImpl_;

View File

@ -151,6 +151,7 @@ int32_t DeviceStatusManager::SensorDataCallback(struct SensorEvents *event)
int32_t DeviceStatusManager::NotifyDeviceStatusChange(const Data& devicestatusData)
{
DEV_HILOGD(SERVICE, "Enter");
DEV_HILOGI(SERVICE, "type:%{public}d,value:%{public}d", devicestatusData.type,devicestatusData.value);
std::set<const sptr<IRemoteDevStaCallback>, classcomp> listeners;
auto iter = listenerMap_.find(devicestatusData.type);
if (iter == listenerMap_.end()) {

View File

@ -858,12 +858,16 @@ int32_t DeviceStatusService::OnGetCoordinationState(
int32_t DeviceStatusService::OnStartDrag(const DragData &dragData, int32_t pid)
{
CALL_DEBUG_ENTER;
auto sess = GetSession(GetClientFd(pid));
CHKPR(sess, RET_ERR);
dragMgr_.StartDrag(dragData, sess);
return RET_OK;
}
int32_t DeviceStatusService::OnStopDrag(int32_t result)
{
CALL_DEBUG_ENTER;
dragMgr_.StopDrag(result);
return RET_OK;
}
} // namespace DeviceStatus

View File

@ -42,7 +42,6 @@ ohos_unittest("test_devicestatus_service") {
"${ability_runtime_path}/frameworks/native/appkit:appkit_native",
"${device_status_frameworks_path}/js/napi:stationary",
"${device_status_interfaces_path}/innerkits:devicestatus_client",
"${device_status_service_path}:devicestatus_service",
"//drivers/peripheral/sensor/hal:hdi_sensor",
"//third_party/googletest:gtest_main",
]
@ -78,7 +77,6 @@ ohos_unittest("DeviceStatusAgentTest") {
deps = [
"//base/msdp/device_status/frameworks/native/src:deviceagent",
"//base/msdp/device_status/services:devicestatus_service",
"//third_party/googletest:gtest_main",
]
external_deps = [

View File

@ -26,7 +26,6 @@
#include "devicestatus_common.h"
#include "devicestatus_client.h"
#include "devicestatus_dumper.h"
#include "devicestatus_service.h"
using namespace testing::ext;
using namespace OHOS::Msdp::DeviceStatus;

View File

@ -14,7 +14,6 @@
*/
#include "devicestatusagent_fuzzer.h"
#include "devicestatus_hilog_wrapper.h"
using namespace std;
using namespace OHOS;
@ -22,11 +21,11 @@ using namespace OHOS::Msdp::DeviceStatus;
namespace {
const int WAIT_TIME = 1000;
}
static std::shared_ptr<DeviceStatusAgentFuzzer::DeviceStatusAgentClient> agentEvent_ =
std::make_shared<DeviceStatusAgentFuzzer::DeviceStatusAgentClient>();
static std::shared_ptr<DevicestatusAgentFuzzer::DeviceStatusAgentClient> agentEvent_ =
std::make_shared<DevicestatusAgentFuzzer::DeviceStatusAgentClient>();
static std::shared_ptr<DeviceStatusAgent> agent_ = std::make_shared<DeviceStatusAgent>();
bool DeviceStatusAgentFuzzer::DeviceStatusAgentClient::OnEventResult(
bool DevicestatusAgentFuzzer::DeviceStatusAgentClient::OnEventResult(
const Data& devicestatusData)
{
std::cout << "type: " << devicestatusData.type << std::endl;
@ -34,54 +33,76 @@ bool DeviceStatusAgentFuzzer::DeviceStatusAgentClient::OnEventResult(
return true;
}
void DeviceStatusAgentFuzzer::TestSubscribeAgentEvent(const uint8_t* data)
void DevicestatusAgentFuzzer::TestSubscribeAgentEvent(const uint8_t* data)
{
std::cout << "TestSubscribeAgentEvent: Enter " << std::endl;
agent_->SubscribeAgentEvent(Type::TYPE_LID_OPEN, ActivityEvent::ENTER_EXIT, ReportLatencyNs::LONG, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeAgentEvent(agent_);
}
void DeviceStatusAgentFuzzer::TestUnsubscribeAgentEvent(std::shared_ptr<DeviceStatusAgent> agent)
{
std::cout << "TestUnsubscribeAgentEvent: Enter " << std::endl;
if (agent == nullptr) {
DEV_HILOGE(SERVICE, "Agent is nullptr");
return;
int32_t type[1];
int32_t idSize = 4;
if ((memcpy_s(type, sizeof(type), data, idSize)) != EOK) {
return;
}
agent->UnsubscribeAgentEvent(Type::TYPE_LID_OPEN, ActivityEvent::ENTER_EXIT);
agent_->SubscribeAgentEvent(static_cast<Type>(type[0]), ActivityEvent::ENTER_EXIT,
ReportLatencyNs::LONG, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnSubscribeAgentEvent(static_cast<Type>(type[0]));
}
void DeviceStatusAgentFuzzer::TestSubscribeAgentEventIsNullptr(const uint8_t* data)
void DevicestatusAgentFuzzer::TestUnSubscribeAgentEvent(Type type)
{
std::cout << "TestUnSubscribeAgentEvent: Enter " << std::endl;
agent_->UnsubscribeAgentEvent(type, ActivityEvent::ENTER_EXIT);
}
void DevicestatusAgentFuzzer::TestSubscribeAgentEventIsNullptr(const uint8_t* data)
{
std::cout << "TestSubscribeAgentEventIsNullptr: Enter " << std::endl;
int32_t type[1];
int32_t idSize = 4;
if ((memcpy_s(type, sizeof(type), data, idSize)) != EOK) {
return;
}
agentEvent_ = nullptr;
agent_->SubscribeAgentEvent(Type::TYPE_LID_OPEN, ActivityEvent::ENTER_EXIT, ReportLatencyNs::LONG, agentEvent_);
agent_->SubscribeAgentEvent(static_cast<Type>(type[0]), ActivityEvent::ENTER_EXIT,
ReportLatencyNs::LONG, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeAgentEvent(agent_);
TestUnSubscribeAgentEvent(static_cast<Type>(type[0]));
}
void DeviceStatusAgentFuzzer::TestSubscribeAgentEventTypeIsNullptr(const uint8_t* data)
void DevicestatusAgentFuzzer::TestSubscribeAgentEventTypeIsNullptr(const uint8_t* data)
{
std::cout << "TestSubscribeAgentEventTypeIsNullptr: Enter " << std::endl;
agent_->SubscribeAgentEvent(Type::TYPE_INVALID, ActivityEvent::ENTER_EXIT, ReportLatencyNs::LONG, agentEvent_);
int32_t type[1];
int32_t idSize = 4;
if ((memcpy_s(type, sizeof(type), data, idSize)) != EOK) {
return;
}
agent_->SubscribeAgentEvent(static_cast<Type>(type[0]), ActivityEvent::ENTER_EXIT,
ReportLatencyNs::LONG, agentEvent_);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeAgentEventTypeIsNullptr(agent_);
TestUnSubscribeAgentEventTypeIsNullptr(static_cast<Type>(type[0]));
}
void DeviceStatusAgentFuzzer::TestUnsubscribeAgentEventTypeIsNullptr(const std::shared_ptr<DeviceStatusAgent>& agent_)
void DevicestatusAgentFuzzer::TestUnSubscribeAgentEventTypeIsNullptr(Type type)
{
std::cout << "TestUnsubscribeAgentEventTypeIsNullptr: Enter " << std::endl;
agent_->UnsubscribeAgentEvent(Type::TYPE_INVALID, ActivityEvent::ENTER_EXIT);
std::cout << "TestUnSubscribeAgentEventTypeIsNullptr: Enter " << std::endl;
agent_->UnsubscribeAgentEvent(type, ActivityEvent::ENTER_EXIT);
}
bool DeviceStatusAgentFuzzer::DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
bool DevicestatusAgentFuzzer::DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
int idSize = 8;
if (static_cast<int>(size) > idSize) {
TestSubscribeAgentEvent(data);
TestSubscribeAgentEventIsNullptr(data);
TestSubscribeAgentEventTypeIsNullptr(data);
DevicestatusAgentFuzzer::TestSubscribeAgentEvent(data);
DevicestatusAgentFuzzer::TestSubscribeAgentEventIsNullptr(data);
DevicestatusAgentFuzzer::TestSubscribeAgentEventTypeIsNullptr(data);
}
return true;
}
@ -90,6 +111,6 @@ bool DeviceStatusAgentFuzzer::DoSomethingInterestingWithMyAPI(const uint8_t* dat
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::Msdp::DeviceStatus::DeviceStatusAgentFuzzer::DoSomethingInterestingWithMyAPI(data, size);
OHOS::Msdp::DeviceStatus::DevicestatusAgentFuzzer::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}

View File

@ -39,14 +39,14 @@ enum class ApiNumber {
NUM_TWO,
NUM_THREE
};
class DeviceStatusAgentFuzzer {
class DevicestatusAgentFuzzer {
public:
static bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size);
static void TestSubscribeAgentEvent(const uint8_t* data);
static void TestUnsubscribeAgentEvent(std::shared_ptr<DeviceStatusAgent> agent);
static void TestUnSubscribeAgentEvent(Type type);
static void TestSubscribeAgentEventIsNullptr(const uint8_t* data);
static void TestSubscribeAgentEventTypeIsNullptr(const uint8_t* data);
static void TestUnsubscribeAgentEventTypeIsNullptr(const std::shared_ptr<DeviceStatusAgent>& agent_);
static void TestUnSubscribeAgentEventTypeIsNullptr(Type type);
class DeviceStatusAgentClient : public DeviceStatusAgent::DeviceStatusAgentEvent {
public:
virtual ~DeviceStatusAgentClient() {};

View File

@ -15,16 +15,19 @@
#include "devicestatusclient_fuzzer.h"
#include <cstring>
#include <stddef.h>
#include <stdint.h>
#include "securec.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Msdp::DeviceStatus;
auto &client_ = DeviceStatusClient::GetInstance();
auto& client_ = DeviceStatusClient::GetInstance();
sptr<DeviceStatusClientFuzzer::DeviceStatusTestCallback> cb = new DeviceStatusClientFuzzer::DeviceStatusTestCallback();
const int WAIT_TIME = 1000;
void DeviceStatusClientFuzzer::DeviceStatusTestCallback::OnDeviceStatusChanged(const Data& devicestatusData)
void DeviceStatusClientFuzzer::DeviceStatusTestCallback::OnDeviceStatusChanged(const \
Data& devicestatusData)
{
std::cout << "DeviceStatusTestCallback type: " << devicestatusData.type << std::endl;
std::cout << "DeviceStatusTestCallback value: " << devicestatusData.value << std::endl;
@ -33,32 +36,40 @@ void DeviceStatusClientFuzzer::DeviceStatusTestCallback::OnDeviceStatusChanged(c
void DeviceStatusClientFuzzer::TestSubscribeCallback(const uint8_t* data)
{
std::cout << "TestSubscribeCallback: Enter " << std::endl;
int32_t type[1];
int32_t idSize = 4;
if ((memcpy_s(type, sizeof(type), data, idSize)) != EOK) {
return;
}
client_.SubscribeCallback(Type::TYPE_LID_OPEN, ActivityEvent::ENTER_EXIT, ReportLatencyNs::LONG, cb);
client_.SubscribeCallback(static_cast<Type>(type[0]), ActivityEvent::ENTER_EXIT, ReportLatencyNs::LONG, cb);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestGetDeviceStatusData();
TestGetDevicestatusData(static_cast<Type>(type[0]));
}
void DeviceStatusClientFuzzer::TestGetDeviceStatusData()
void DeviceStatusClientFuzzer::TestGetDevicestatusData(Type type)
{
std::cout << "TestGetDeviceStatusData: Enter " << std::endl;
client_.GetDeviceStatusData(Type::TYPE_LID_OPEN);
std::cout << "TestGetDevicestatusData: Enter " << std::endl;
client_.GetDeviceStatusData(type);
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
TestUnsubscribeCallback();
TestUnSubscribeCallback(type);
}
void DeviceStatusClientFuzzer::TestUnsubscribeCallback()
void DeviceStatusClientFuzzer::TestUnSubscribeCallback(Type type)
{
std::cout << "TestUnsubscribeCallback: Enter " << std::endl;
std::cout << "TestUnSubscribeCallback: Enter " << std::endl;
client_.UnsubscribeCallback(Type::TYPE_LID_OPEN, ActivityEvent::ENTER_EXIT, cb);
client_.UnsubscribeCallback(type, ActivityEvent::ENTER_EXIT, cb);
}
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
DeviceStatusClientFuzzer::TestSubscribeCallback(data);
int32_t idSize = 8;
if (static_cast<int32_t>(size) > idSize) {
DeviceStatusClientFuzzer::TestSubscribeCallback(data);
}
return true;
}

View File

@ -23,6 +23,7 @@
#include <cstdlib>
#include <fcntl.h>
#include <iostream>
#include <random>
#include <thread>
#include "devicestatus_client.h"
@ -32,12 +33,13 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DeviceStatusClientFuzzer {
public:
static bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size);
static void TestSubscribeCallback(const uint8_t* data);
static void TestGetDeviceStatusData();
static void TestUnsubscribeCallback();
static void TestGetDevicestatusData(Type type);
static void TestUnSubscribeCallback(Type type);
class DeviceStatusTestCallback : public DeviceStatusCallbackStub {
public: