mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2025-02-21 08:14:07 +00:00
modify review
Signed-off-by: wuliangdong <wuliangdong1@huawei.com> Change-Id: I4635016c2433cb71770069ad1bb68ad98f57eb3c
This commit is contained in:
parent
b3b8d4b41b
commit
de4bd5f84f
@ -32,7 +32,7 @@ public:
|
||||
int32_t UpdateDragMessage(const std::u16string &message);
|
||||
int32_t GetDragTargetPid();
|
||||
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback);
|
||||
int32_t StopDrag(int32_t dragResult);
|
||||
int32_t StopDrag(int32_t result);
|
||||
private:
|
||||
std::mutex mtx_;
|
||||
std::function<void(int32_t&)> stopCallback_;
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
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 StopDrag(int32_t dragResult);
|
||||
int32_t StopDrag(int32_t result);
|
||||
int32_t GetDragTargetPid();
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
|
@ -41,18 +41,22 @@ int32_t DragManagerImpl::UpdateDragMessage(const std::u16string &message)
|
||||
int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (dragData.buffer.size() > VerifyBound::BUFFER_SIZE) {
|
||||
FI_HILOGE("Invalid buffer, bufferSize: %{public}zu", dragData.buffer.size());
|
||||
if (dragData.buffer.size() > MAX_BUFFER_SIZE) {
|
||||
FI_HILOGE("Invalid buffer, bufferSize:%{public}zu", dragData.buffer.size());
|
||||
return RET_ERR;
|
||||
}
|
||||
if (dragData.pixelMap->GetWidth() > VerifyBound::MAX_PIXEL_MAP_WIDTH ||
|
||||
dragData.pixelMap->GetHeight() > VerifyBound::MAX_PIXEL_MAP_HEIGHT) {
|
||||
FI_HILOGE("Too big pixelMap, width: %{public}d, height: %{public}d",
|
||||
if (dragData.pixelMap == nullptr) {
|
||||
FI_HILOGE("dragData.pixelMap is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
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",
|
||||
dragData.pixelMap->GetWidth(), dragData.pixelMap->GetHeight());
|
||||
return RET_ERR;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
FI_HILOGE("Callback is null");
|
||||
FI_HILOGE("Callback is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
@ -60,10 +64,10 @@ int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::function<void(
|
||||
return DeviceStatusClient::GetInstance().StartDrag(dragData);
|
||||
}
|
||||
|
||||
int32_t DragManagerImpl::StopDrag(int32_t dragResult)
|
||||
int32_t DragManagerImpl::StopDrag(int32_t result)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return DeviceStatusClient::GetInstance().StopDrag(dragResult);
|
||||
return DeviceStatusClient::GetInstance().StopDrag(result);
|
||||
}
|
||||
|
||||
int32_t DragManagerImpl::GetDragTargetPid()
|
||||
|
@ -80,11 +80,10 @@ int32_t InteractionManager::StartDrag(const DragData &dragData, std::function<vo
|
||||
return InteractionMgrImpl.StartDrag(dragData, callback);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::StopDrag(int32_t dragResult)
|
||||
int32_t InteractionManager::StopDrag(int32_t result)
|
||||
{
|
||||
return InteractionMgrImpl.StopDrag(dragResult);
|
||||
return InteractionMgrImpl.StopDrag(result);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::GetDragTargetPid()
|
||||
{
|
||||
return InteractionMgrImpl.GetDragTargetPid();
|
||||
|
@ -178,10 +178,10 @@ int32_t InteractionManagerImpl::StartDrag(const DragData &dragData, std::functio
|
||||
return dragManagerImpl_.StartDrag(dragData, callback);
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::StopDrag(int32_t dragResult)
|
||||
int32_t InteractionManagerImpl::StopDrag(int32_t result)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return dragManagerImpl_.StopDrag(dragResult);
|
||||
return dragManagerImpl_.StopDrag(result);
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::GetDragTargetPid()
|
||||
|
@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "coordination_message.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "devicestatus_errors.h"
|
||||
@ -50,8 +51,12 @@ void InteractionManagerTest::TearDown()
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<OHOS::Media::PixelMap> ConstructPixmap(int32_t pixelMapWidth, int32_t pixelMapHeight)
|
||||
std::unique_ptr<OHOS::Media::PixelMap> CreatePixelMap(int32_t pixelMapWidth, int32_t pixelMapHeight)
|
||||
{
|
||||
if (pixelMapWidth <= 0 || pixelMapHeight <= 0 || (INT32_MAX / pixelMapWidth <= pixelMapHeight)) {
|
||||
std::cout << "Invalid pixelMapWidth or pixelMapHeight" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<OHOS::Media::PixelMap> pixelMap = std::make_unique<OHOS::Media::PixelMap>();
|
||||
OHOS::Media::ImageInfo info;
|
||||
info.size.width = pixelMapWidth;
|
||||
@ -59,20 +64,13 @@ std::unique_ptr<OHOS::Media::PixelMap> ConstructPixmap(int32_t pixelMapWidth, in
|
||||
info.pixelFormat = OHOS::Media::PixelFormat::RGB_888;
|
||||
info.colorSpace = OHOS::Media::ColorSpace::SRGB;
|
||||
pixelMap->SetImageInfo(info);
|
||||
if (INT32_MAX / pixelMapWidth < pixelMapHeight) {
|
||||
std::cout << "Invalid pixelMapWidth or pixelMapHeight" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
int32_t bufferSize = pixelMapWidth * pixelMapHeight;
|
||||
if (bufferSize <= 0) {
|
||||
return nullptr;
|
||||
}
|
||||
void *buffer = malloc(bufferSize);
|
||||
if (buffer == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
char *character = reinterpret_cast<char *>(buffer);
|
||||
for (unsigned int i = 0; i < bufferSize; i++) {
|
||||
for (uint32_t i = 0; i < bufferSize; i++) {
|
||||
*(character++) = static_cast<char>(i);
|
||||
}
|
||||
|
||||
@ -83,10 +81,10 @@ std::unique_ptr<OHOS::Media::PixelMap> ConstructPixmap(int32_t pixelMapWidth, in
|
||||
|
||||
void SetParam(int32_t width, int32_t height, DragData& dragData)
|
||||
{
|
||||
dragData.pixelMap = ConstructPixmap(width, height);
|
||||
dragData.pixelMap = CreatePixelMap(width, height);
|
||||
dragData.x = INT32_MAX;
|
||||
dragData.y = INT32_MAX;
|
||||
dragData.buffer = std::vector<uint8_t>(VerifyBound::BUFFER_SIZE, 0);
|
||||
dragData.buffer = std::vector<uint8_t>(MAX_BUFFER_SIZE, 0);
|
||||
dragData.sourceType = -1;
|
||||
}
|
||||
|
||||
|
@ -273,14 +273,22 @@ int32_t DeviceStatusClient::StartDrag(const DragData &dragData)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
FI_HILOGE("Client has not connect server");
|
||||
return RET_ERR;
|
||||
}
|
||||
return devicestatusProxy_->StartDrag(dragData);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::StopDrag(int32_t dragResult)
|
||||
int32_t DeviceStatusClient::StopDrag(int32_t result)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->StopDrag(dragResult);
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
FI_HILOGE("Client has not connect server");
|
||||
return RET_ERR;
|
||||
}
|
||||
return devicestatusProxy_->StopDrag(result);
|
||||
}
|
||||
|
||||
} // namespace DeviceStatus
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
#include <singleton.h>
|
||||
|
||||
#include "devicestatus_common.h"
|
||||
@ -54,7 +55,7 @@ public:
|
||||
int32_t GetCoordinationState(int32_t userData, const std::string &deviceId);
|
||||
|
||||
int32_t StartDrag(const DragData &dragData);
|
||||
int32_t StopDrag(int32_t dragResult);
|
||||
int32_t StopDrag(int32_t result);
|
||||
int32_t UpdateDragStyle(int32_t style);
|
||||
int32_t UpdateDragMessage(const std::u16string &message);
|
||||
int32_t GetDragTargetPid();
|
||||
|
@ -24,7 +24,10 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
|
||||
namespace DeviceStatus {
|
||||
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;
|
||||
int32_t x { -1 };
|
||||
@ -33,12 +36,6 @@ struct DragData {
|
||||
int32_t sourceType { -1 };
|
||||
};
|
||||
|
||||
struct VerifyBound {
|
||||
static const int32_t MAX_PIXEL_MAP_WIDTH = 200;
|
||||
static const int32_t MAX_PIXEL_MAP_HEIGHT = 200;
|
||||
static const int32_t BUFFER_SIZE = 512;
|
||||
};
|
||||
|
||||
enum class DragState {
|
||||
FREE = 0,
|
||||
DRAGGING = 1,
|
||||
@ -49,6 +46,7 @@ enum class DragResult {
|
||||
DRAG_FAIL = 1,
|
||||
DRAG_CANCEL = 2,
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // DRAG_DATA_H
|
@ -92,17 +92,17 @@ public:
|
||||
* @param dragData 拖拽传入数据
|
||||
* @param dragData 拖拽结束回调
|
||||
* @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。
|
||||
* @since 9
|
||||
* @since 10
|
||||
*/
|
||||
int32_t StartDrag(const DragData &dragData, std::function<void(int32_t&)> callback);
|
||||
|
||||
/**
|
||||
* @brief 结束拖拽接口。
|
||||
* @param dragResult 传出参数,标识拖拽调用结果 0-成功,1-失败,2-取消
|
||||
* @param result 传出参数,标识拖拽调用结果 0-成功,1-失败,2-取消
|
||||
* @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。
|
||||
* @since 9
|
||||
* @since 10
|
||||
*/
|
||||
int32_t StopDrag(int32_t dragResult);
|
||||
int32_t StopDrag(int32_t result);
|
||||
|
||||
/**
|
||||
* @brief 更新拖拽中的光标样式。
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
virtual int32_t StopCoordination(int32_t userData) = 0;
|
||||
virtual int32_t GetCoordinationState(int32_t userData, const std::string &deviceId) = 0;
|
||||
virtual int32_t StartDrag(const DragData &dragData) = 0;
|
||||
virtual int32_t StopDrag(int32_t dragResult) = 0;
|
||||
virtual int32_t StopDrag(int32_t result) = 0;
|
||||
virtual int32_t UpdateDragStyle(int32_t style) = 0;
|
||||
virtual int32_t UpdateDragMessage(const std::u16string &message) = 0;
|
||||
virtual int32_t GetDragTargetPid() = 0;
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
virtual int32_t GetCoordinationState(int32_t userData, const std::string &deviceId) override;
|
||||
|
||||
virtual int32_t StartDrag(const DragData &dragData) override;
|
||||
virtual int32_t StopDrag(int32_t dragResult) override;
|
||||
virtual int32_t StopDrag(int32_t result) override;
|
||||
virtual int32_t UpdateDragStyle(int32_t style) override;
|
||||
virtual int32_t UpdateDragMessage(const std::u16string &message) override;
|
||||
virtual int32_t GetDragTargetPid() override;
|
||||
|
@ -341,7 +341,7 @@ int32_t DeviceStatusSrvProxy::StartDrag(const DragData &dragData)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DeviceStatusSrvProxy::StopDrag(int32_t dragResult)
|
||||
int32_t DeviceStatusSrvProxy::StopDrag(int32_t result)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel data;
|
||||
@ -349,7 +349,7 @@ int32_t DeviceStatusSrvProxy::StopDrag(int32_t dragResult)
|
||||
FI_HILOGE("Failed to write descriptor");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
WRITEINT32(data, dragResult, ERR_INVALID_VALUE);
|
||||
WRITEINT32(data, result, ERR_INVALID_VALUE);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
|
@ -300,17 +300,17 @@ int32_t DeviceStatusSrvStub::StubStartDrag(MessageParcel& data, MessageParcel& r
|
||||
CALL_DEBUG_ENTER;
|
||||
DragData dragData;
|
||||
dragData.pixelMap = std::unique_ptr<OHOS::Media::PixelMap> (OHOS::Media::PixelMap::Unmarshalling(data));
|
||||
if (dragData.pixelMap->GetWidth() > VerifyBound::MAX_PIXEL_MAP_WIDTH ||
|
||||
dragData.pixelMap->GetHeight() > VerifyBound::MAX_PIXEL_MAP_HEIGHT) {
|
||||
FI_HILOGE("Too big pixelMap, width: %{public}d, height: %{public}d",
|
||||
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",
|
||||
dragData.pixelMap->GetWidth(), dragData.pixelMap->GetHeight());
|
||||
return RET_ERR;
|
||||
}
|
||||
READINT32(data, dragData.x, E_DEVICESTATUS_READ_PARCEL_ERROR);
|
||||
READINT32(data, dragData.y, E_DEVICESTATUS_READ_PARCEL_ERROR);
|
||||
READUINT8VECTOR(data, dragData.buffer, E_DEVICESTATUS_READ_PARCEL_ERROR);
|
||||
if (dragData.buffer.size() > VerifyBound::BUFFER_SIZE) {
|
||||
FI_HILOGE("Invalid buffer, bufferSize: %{public}zu", dragData.buffer.size());
|
||||
if (dragData.buffer.size() > MAX_BUFFER_SIZE) {
|
||||
FI_HILOGE("Invalid buffer, bufferSize:%{public}zu", dragData.buffer.size());
|
||||
return RET_ERR;
|
||||
}
|
||||
READINT32(data, dragData.sourceType, E_DEVICESTATUS_READ_PARCEL_ERROR);
|
||||
|
@ -100,7 +100,7 @@ public:
|
||||
int32_t GetCoordinationState(int32_t userData, const std::string &deviceId) override;
|
||||
|
||||
int32_t StartDrag(const DragData &dragData) override;
|
||||
int32_t StopDrag(int32_t dragResult) override;
|
||||
int32_t StopDrag(int32_t result) override;
|
||||
int32_t UpdateDragStyle(int32_t style) override;
|
||||
int32_t UpdateDragMessage(const std::u16string &message) override;
|
||||
int32_t GetDragTargetPid() override;
|
||||
@ -126,7 +126,7 @@ private:
|
||||
void DisableDevMgr();
|
||||
|
||||
int32_t OnStartDrag(const DragData &dragData, int32_t pid);
|
||||
int32_t OnStopDrag(int32_t dragResult);
|
||||
int32_t OnStopDrag(int32_t result);
|
||||
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
int32_t OnRegisterCoordinationListener(int32_t pid);
|
||||
|
@ -659,11 +659,11 @@ int32_t DeviceStatusService::StartDrag(const DragData &dragData)
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceStatusService::StopDrag(int32_t dragResult)
|
||||
int32_t DeviceStatusService::StopDrag(int32_t result)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
int32_t ret = delegateTasks_.PostSyncTask(
|
||||
std::bind(&DeviceStatusService::OnStopDrag, this, dragResult));
|
||||
std::bind(&DeviceStatusService::OnStopDrag, this, result));
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("OnStopDrag failed, ret:%{public}d", ret);
|
||||
return ret;
|
||||
@ -819,7 +819,7 @@ int32_t DeviceStatusService::OnStartDrag(const DragData &dragData, int32_t pid)
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceStatusService::OnStopDrag(int32_t dragResult)
|
||||
int32_t DeviceStatusService::OnStopDrag(int32_t result)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_OK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user