mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-23 07:29:52 +00:00
Merge master
Signed-off-by: wuliangdong <wuliangdong1@huawei.com> Change-Id: I0939124a83d111a862e6279e4da5477be99beccd
This commit is contained in:
commit
fd9cad84b1
1
BUILD.gn
1
BUILD.gn
@ -41,6 +41,7 @@ group("device_status_tests") {
|
||||
"intention/common/channel:intention_channel_test",
|
||||
"intention/cooperate/test:device_status_unittests",
|
||||
"intention/services/test:intention_services_test",
|
||||
"intention/stationary/test:intention_stationary_test",
|
||||
"services/native/test:devicestatussrv_test",
|
||||
"test/fuzztest:device_status_fuzztest",
|
||||
"test/unittest:device_status_unittest",
|
||||
|
@ -48,8 +48,7 @@
|
||||
"dsoftbus",
|
||||
"motion",
|
||||
"ylong_runtime",
|
||||
"dfs_service",
|
||||
"hicollie"
|
||||
"dfs_service"
|
||||
],
|
||||
"third_party": [
|
||||
"libxml2",
|
||||
@ -113,7 +112,8 @@
|
||||
"//base/msdp/device_status/test/fuzztest:device_status_fuzztest",
|
||||
"//base/msdp/device_status//frameworks/native/interaction/test:interaction_manager_test",
|
||||
"//base/msdp/device_status/intention/adapters/test:intention_adapter_test",
|
||||
"//base/msdp/device_status/intention/services/test:intention_services_test"
|
||||
"//base/msdp/device_status/intention/services/test:intention_services_test",
|
||||
"//base/msdp/device_status/intention/stationary/test:intention_stationary_test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ void JsEventCooperateTarget::OnCoordinationMessage(const std::string &networkId,
|
||||
CHKRV(napi_get_uv_event_loop(item->env, &loop), GET_UV_EVENT_LOOP);
|
||||
uv_work_t *uvWork = new (std::nothrow) uv_work_t;
|
||||
CHKPV(uvWork);
|
||||
item->data.msg = msg;
|
||||
item->data.msgInfo.msg = msg;
|
||||
item->data.deviceDescriptor = networkId;
|
||||
item->IncStrongRef(nullptr);
|
||||
uvWork->data = item.GetRefPtr();
|
||||
|
@ -29,6 +29,8 @@ namespace {
|
||||
inline constexpr std::string_view GET_BOOLEAN { "napi_get_boolean" };
|
||||
inline constexpr std::string_view COERCE_TO_BOOL { "napi_coerce_to_bool" };
|
||||
inline constexpr std::string_view CREATE_ERROR { "napi_create_error" };
|
||||
inline constexpr uint32_t SUB_SYSTEM_ID { 203 };
|
||||
inline constexpr uint32_t MODULE_ID { 3 };
|
||||
} // namespace
|
||||
|
||||
napi_value JsUtilCooperate::GetEnableInfo(sptr<CallbackInfo> cb)
|
||||
@ -90,8 +92,10 @@ napi_value JsUtilCooperate::GetResult(napi_env env, bool result, const Coordinat
|
||||
|
||||
int32_t JsUtilCooperate::GetErrCode(const CoordinationMsgInfo &msgInfo)
|
||||
{
|
||||
auto errCode = (static_cast<uint32_t> (msgInfo.msg) << 4) | (static_cast<uint32_t> (msgInfo.errCode));
|
||||
return static_cast<int32_t> (errCode);
|
||||
uint32_t errCode = ((static_cast<uint32_t> (msgInfo.msg) << 4) | (static_cast<uint32_t> (msgInfo.errCode)));
|
||||
uint32_t dfxErrCode = ((SUB_SYSTEM_ID << 21) | (MODULE_ID << 16) | (errCode));
|
||||
FI_HILOGI("DFX errCode:%{public}u", dfxErrCode);
|
||||
return static_cast<int32_t> (dfxErrCode);
|
||||
}
|
||||
|
||||
bool JsUtilCooperate::GetErrMsg(const CoordinationMsgInfo &msgInfo, std::string &msg)
|
||||
|
@ -29,6 +29,8 @@ namespace {
|
||||
inline constexpr std::string_view GET_BOOLEAN { "napi_get_boolean" };
|
||||
inline constexpr std::string_view COERCE_TO_BOOL { "napi_coerce_to_bool" };
|
||||
inline constexpr std::string_view CREATE_ERROR { "napi_create_error" };
|
||||
inline constexpr uint32_t SUB_SYSTEM_ID { 203 };
|
||||
inline constexpr uint32_t MODULE_ID { 3 };
|
||||
} // namespace
|
||||
|
||||
napi_value JsUtil::GetPrepareInfo(sptr<CallbackInfo> cb)
|
||||
@ -107,8 +109,10 @@ bool JsUtil::GetErrMsg(const CoordinationMsgInfo &msgInfo, std::string &msg)
|
||||
|
||||
int32_t JsUtil::GetErrCode(const CoordinationMsgInfo &msgInfo)
|
||||
{
|
||||
auto errCode = (static_cast<uint32_t> (msgInfo.msg) << 4) | (static_cast<uint32_t> (msgInfo.errCode));
|
||||
return static_cast<int32_t> (errCode);
|
||||
uint32_t errCode = ((static_cast<uint32_t> (msgInfo.msg) << 4) | (static_cast<uint32_t> (msgInfo.errCode)));
|
||||
uint32_t dfxErrCode = ((SUB_SYSTEM_ID << 21) | (MODULE_ID << 16) | (errCode));
|
||||
FI_HILOGI("DFX errCode:%{public}u", dfxErrCode);
|
||||
return static_cast<int32_t> (dfxErrCode);
|
||||
}
|
||||
|
||||
napi_value JsUtil::GetCrossingSwitchStateResult(napi_env env, bool result)
|
||||
|
@ -327,7 +327,7 @@ void InteractionManagerTest::EnableCooperate()
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto fun = [&promiseFlag](const std::string &listener, const CoordinationMessage &coordinationMessages) {
|
||||
auto fun = [&promiseFlag](const std::string &listener, const CoordinationMsgInfo &coordinationMessages) {
|
||||
FI_HILOGD("Prepare coordination success, listener:%{public}s", listener.c_str());
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
@ -641,7 +641,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_PrepareCoordination, Tes
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto fun = [&promiseFlag](const std::string &listener, const CoordinationMessage &coordinationMessages) {
|
||||
auto fun = [&promiseFlag](const std::string &listener, const CoordinationMsgInfo &coordinationMessages) {
|
||||
FI_HILOGD("Prepare coordination success, listener:%{public}s", listener.c_str());
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
@ -771,7 +771,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_ActivateCoordination, Te
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
std::string remoteNetworkId("");
|
||||
int32_t startDeviceId = -1;
|
||||
auto fun = [](const std::string &listener, const CoordinationMessage &coordinationMessages) {
|
||||
auto fun = [](const std::string &listener, const CoordinationMsgInfo &coordinationMessages) {
|
||||
FI_HILOGD("Start coordination success");
|
||||
(void) listener;
|
||||
};
|
||||
@ -796,7 +796,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_DeactivateCoordination,
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
auto fun = [](const std::string &listener, const CoordinationMessage &coordinationMessages) {
|
||||
auto fun = [](const std::string &listener, const CoordinationMsgInfo &coordinationMessages) {
|
||||
FI_HILOGD("Stop coordination success");
|
||||
(void) listener;
|
||||
};
|
||||
@ -918,7 +918,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UnprepareCoordination, T
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto fun = [&promiseFlag](const std::string &listener, const CoordinationMessage &coordinationMessages) {
|
||||
auto fun = [&promiseFlag](const std::string &listener, const CoordinationMsgInfo &coordinationMessages) {
|
||||
FI_HILOGD("Prepare coordination success, listener:%{public}s", listener.c_str());
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include <cinttypes>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "xcollie/watchdog.h"
|
||||
|
||||
#include "devicestatus_client.h"
|
||||
#include "fd_listener.h"
|
||||
#include "fi_log.h"
|
||||
@ -36,7 +34,6 @@ namespace DeviceStatus {
|
||||
using namespace AppExecFwk;
|
||||
namespace {
|
||||
const std::string THREAD_NAME { "os_ClientEventHandler" };
|
||||
const uint64_t WATCHDOG_TIMWVAL { 5000 };
|
||||
} // namespace
|
||||
|
||||
Client::~Client()
|
||||
@ -109,10 +106,6 @@ bool Client::StartEventRunner()
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPF(runner);
|
||||
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_ClientEventHandler", eventHandler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
|
||||
FI_HILOGI("Create event handler, thread name:%{public}s", runner->GetRunnerThreadName().c_str());
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-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
|
||||
@ -212,4 +212,81 @@ COOPERATE_DRAG_RESULT_FAILED:
|
||||
MSG: {type: STRING, desc: Coordination Drag Result Failed}
|
||||
DEVICEID: {type: STRING, desc: remotedeviceId}
|
||||
SESSIONID: {type: STRING, desc: sessionId}
|
||||
CURSTATE: {type: STRING, desc: CurCoordinationState}
|
||||
CURSTATE: {type: STRING, desc: CurCoordinationState}
|
||||
|
||||
ENABLE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: enable cooperate}
|
||||
MSG: {type: STRING, desc: Enable cooperate successfully}
|
||||
|
||||
ENABLE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: enable cooperate}
|
||||
MSG: {type: STRING, desc: Enable cooperate failed}
|
||||
|
||||
DISABLE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: disable cooperate}
|
||||
MSG: {type: STRING, desc: Disable cooperate successfully}
|
||||
|
||||
DISABLE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: disable cooperate}
|
||||
MSG: {type: STRING, desc: Disable cooperate failed}
|
||||
|
||||
LOCAL_ACTIVATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: local start cooperate}
|
||||
MSG: {type: STRING, desc: Local start cooperate successfully}
|
||||
|
||||
LOCAL_ACTIVATE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: local start cooperate}
|
||||
MSG: {type: STRING, desc: Local start cooperate failed}
|
||||
|
||||
REMOTE_ACTIVATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: remote start cooperate}
|
||||
MSG: {type: STRING, desc: Remote start cooperate successfully}
|
||||
|
||||
REMOTE_ACTIVATE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: remote start cooperate}
|
||||
MSG: {type: STRING, desc: Remote start cooperate failed}
|
||||
|
||||
LOCAL_DEACTIVATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: local stop cooperate}
|
||||
MSG: {type: STRING, desc: Local stop cooperate successfully}
|
||||
|
||||
LOCAL_DEACTIVATE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: local stop cooperate}
|
||||
MSG: {type: STRING, desc: Local stop cooperate failed}
|
||||
|
||||
REMOTE_DEACTIVATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: remote stop cooperate}
|
||||
MSG: {type: STRING, desc: Remote stop cooperate successfully}
|
||||
|
||||
REMOTE_DEACTIVATE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: remote stop cooperate}
|
||||
MSG: {type: STRING, desc: Remote stop cooperate failed}
|
||||
|
||||
OPENSESSION_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: open session}
|
||||
MSG: {type: STRING, desc: Open session successfully}
|
||||
|
||||
OPENSESSION_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: open session}
|
||||
MSG: {type: STRING, desc: Open session failed}
|
||||
|
||||
UPDATESTATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Cooperate update}
|
||||
MSG: {type: STRING, desc: Update cooperatestate successfully}
|
||||
CURSTATE: {type: STRING, desc: CurrentState}
|
||||
|
||||
START_SUCCESS:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Start client}
|
||||
MSG: {type: STRING, desc: Start client successfully}
|
||||
|
||||
START_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Start client}
|
||||
MSG: {type: STRING, desc: Start client failed}
|
||||
|
||||
STOP_SUCCESS:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Stop client}
|
||||
MSG: {type: STRING, desc: Stop client successfully}
|
||||
|
||||
STOP_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Stop client}
|
||||
MSG: {type: STRING, desc: Stop client failed}
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2023-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
|
||||
@ -41,6 +41,7 @@ ohos_source_set("intention_dsoftbus_adapter") {
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/dfx:cooperate_dfx",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -22,6 +22,7 @@
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include "cooperate_hisysevent.h"
|
||||
#include "dfs_session.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_bus_center.h"
|
||||
@ -119,6 +120,11 @@ int32_t DSoftbusAdapterImpl::OpenSession(const std::string &networkId)
|
||||
std::chrono::steady_clock::now() - startStamp).count();
|
||||
FI_HILOGI("[PERF] OpenSessionLocked ret:%{public}d, elapsed: %{public}lld ms", ret, openSessionDuration);
|
||||
#endif // ENABLE_PERFORMANCE_CHECK
|
||||
if (ret != RET_OK) {
|
||||
CooperateDFX::WriteOpenSession(OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
|
||||
} else {
|
||||
CooperateDFX::WriteOpenSession(OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,6 @@ ohos_unittest("DDInputAdapterTest") {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
blocklist = "./ipc_blocklist.txt"
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
@ -84,6 +83,7 @@ ohos_unittest("DsoftbusAdapterTest") {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
blocklist = "./ipc_blocklist.txt"
|
||||
}
|
||||
|
||||
cflags = [ "-Dprivate=public" ]
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2023-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
|
||||
@ -45,6 +45,8 @@ ohos_unittest("intention_channel_test") {
|
||||
|
||||
sources = [ "test/channel_test.cpp" ]
|
||||
|
||||
cflags = [ "-Dprivate=public" ]
|
||||
|
||||
deps = [
|
||||
":intention_channel",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -34,6 +34,13 @@ class Channel {
|
||||
std::is_copy_constructible_v<Event>));
|
||||
|
||||
public:
|
||||
enum ChannelError {
|
||||
NO_ERROR = 0,
|
||||
QUEUE_IS_FULL = -1,
|
||||
NO_CHANNEL = -2,
|
||||
INACTIVE_CHANNEL = -3,
|
||||
};
|
||||
|
||||
class Sender final {
|
||||
friend class Channel<Event>;
|
||||
|
||||
@ -64,11 +71,12 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Send(const Event &event)
|
||||
int32_t Send(const Event &event)
|
||||
{
|
||||
if (channel_ != nullptr) {
|
||||
channel_->Send(event);
|
||||
if (channel_ == nullptr) {
|
||||
return ChannelError::NO_CHANNEL;
|
||||
}
|
||||
return channel_->Send(event);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -109,6 +117,20 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Enable()
|
||||
{
|
||||
if (channel_ != nullptr) {
|
||||
channel_->Enable();
|
||||
}
|
||||
}
|
||||
|
||||
void Disable()
|
||||
{
|
||||
if (channel_ != nullptr) {
|
||||
channel_->Disable();
|
||||
}
|
||||
}
|
||||
|
||||
Event Peek()
|
||||
{
|
||||
return (channel_ != nullptr ? channel_->Peek() : Event());
|
||||
@ -140,7 +162,9 @@ public:
|
||||
static std::pair<Sender, Receiver> OpenChannel();
|
||||
|
||||
private:
|
||||
void Send(const Event &event);
|
||||
void Enable();
|
||||
void Disable();
|
||||
int32_t Send(const Event &event);
|
||||
Event Peek();
|
||||
void Pop();
|
||||
Event Receive();
|
||||
@ -148,7 +172,7 @@ private:
|
||||
static inline constexpr size_t QUEUE_CAPACITY { 1024 };
|
||||
|
||||
std::mutex lock_;
|
||||
std::condition_variable full_;
|
||||
bool isActive_ { false };
|
||||
std::condition_variable empty_;
|
||||
std::deque<Event> queue_;
|
||||
};
|
||||
@ -161,19 +185,36 @@ std::pair<typename Channel<Event>::Sender, typename Channel<Event>::Receiver> Ch
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
void Channel<Event>::Send(const Event &event)
|
||||
void Channel<Event>::Enable()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(lock_);
|
||||
isActive_ = true;
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
void Channel<Event>::Disable()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(lock_);
|
||||
isActive_ = false;
|
||||
queue_.clear();
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
int32_t Channel<Event>::Send(const Event &event)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(lock_);
|
||||
if (!isActive_) {
|
||||
return ChannelError::INACTIVE_CHANNEL;
|
||||
}
|
||||
if (queue_.size() >= QUEUE_CAPACITY) {
|
||||
full_.wait(lock, [this] {
|
||||
return (queue_.size() < QUEUE_CAPACITY);
|
||||
});
|
||||
return ChannelError::QUEUE_IS_FULL;
|
||||
}
|
||||
bool needNotify = queue_.empty();
|
||||
queue_.push_back(event);
|
||||
if (needNotify) {
|
||||
empty_.notify_one();
|
||||
empty_.notify_all();
|
||||
}
|
||||
return ChannelError::NO_ERROR;
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
@ -197,11 +238,7 @@ void Channel<Event>::Pop()
|
||||
return !queue_.empty();
|
||||
});
|
||||
}
|
||||
bool needNotify(queue_.size() >= QUEUE_CAPACITY);
|
||||
queue_.pop_front();
|
||||
if (needNotify) {
|
||||
full_.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
@ -213,12 +250,8 @@ Event Channel<Event>::Receive()
|
||||
return !queue_.empty();
|
||||
});
|
||||
}
|
||||
bool needNotify(queue_.size() >= QUEUE_CAPACITY);
|
||||
Event event = queue_.front();
|
||||
queue_.pop_front();
|
||||
if (needNotify) {
|
||||
full_.notify_one();
|
||||
}
|
||||
return event;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -27,6 +27,9 @@
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr size_t DEFAULT_WAIT_TIME { 10 };
|
||||
}
|
||||
using namespace testing::ext;
|
||||
|
||||
class ChannelTest : public testing::Test {
|
||||
@ -45,19 +48,20 @@ public:
|
||||
HWTEST_F(ChannelTest, ChannelTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
auto [sender, receiver] = Channel<int32_t>::OpenChannel();
|
||||
constexpr int32_t count = 65535;
|
||||
auto [sender, receiver] = Channel<size_t>::OpenChannel();
|
||||
constexpr size_t count = Channel<size_t>::QUEUE_CAPACITY;
|
||||
receiver.Enable();
|
||||
|
||||
std::thread worker([sender = sender, count]() mutable {
|
||||
for (int32_t index = 0; index < count; ++index) {
|
||||
sender.Send(index);
|
||||
for (size_t index = 0; index < count; ++index) {
|
||||
EXPECT_EQ(sender.Send(index), Channel<size_t>::NO_ERROR);
|
||||
}
|
||||
});
|
||||
for (int32_t expected = 0; expected < count;) {
|
||||
int32_t received = receiver.Receive();
|
||||
ASSERT_EQ(received, expected);
|
||||
for (size_t expected = 0; expected < count;) {
|
||||
size_t received = receiver.Receive();
|
||||
EXPECT_EQ(received, expected);
|
||||
if ((++expected % 10) == 0) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_WAIT_TIME));
|
||||
}
|
||||
}
|
||||
if (worker.joinable()) {
|
||||
@ -73,25 +77,57 @@ HWTEST_F(ChannelTest, ChannelTest001, TestSize.Level0)
|
||||
HWTEST_F(ChannelTest, ChannelTest002, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
auto [sender, receiver] = Channel<int32_t>::OpenChannel();
|
||||
constexpr int32_t count = 65535;
|
||||
auto [sender, receiver] = Channel<size_t>::OpenChannel();
|
||||
constexpr size_t count = Channel<size_t>::QUEUE_CAPACITY;
|
||||
receiver.Enable();
|
||||
|
||||
std::thread worker([sender = sender, count]() mutable {
|
||||
for (int32_t index = 0; index < count;) {
|
||||
sender.Send(index);
|
||||
for (size_t index = 0; index < count;) {
|
||||
EXPECT_EQ(sender.Send(index), Channel<size_t>::NO_ERROR);
|
||||
if ((++index % 10) == 0) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_WAIT_TIME));
|
||||
}
|
||||
}
|
||||
});
|
||||
for (int32_t expected = 0; expected < count; ++expected) {
|
||||
int32_t received = receiver.Receive();
|
||||
for (size_t expected = 0; expected < count; ++expected) {
|
||||
size_t received = receiver.Receive();
|
||||
ASSERT_EQ(received, expected);
|
||||
}
|
||||
if (worker.joinable()) {
|
||||
worker.join();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ChannelTest003
|
||||
* @tc.desc: Disallow sending of events when channel is inactive.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ChannelTest, ChannelTest003, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
auto [sender, receiver] = Channel<size_t>::OpenChannel();
|
||||
const size_t data = 1;
|
||||
EXPECT_TRUE(sender.Send(data) == Channel<size_t>::INACTIVE_CHANNEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ChannelTest004
|
||||
* @tc.desc: Disallow sending of events when queue is full.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ChannelTest, ChannelTest004, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
auto [sender, receiver] = Channel<size_t>::OpenChannel();
|
||||
size_t data = 1;
|
||||
receiver.Enable();
|
||||
|
||||
for (size_t index = 0; index < Channel<size_t>::QUEUE_CAPACITY; ++index) {
|
||||
EXPECT_EQ(sender.Send(data++), Channel<size_t>::NO_ERROR);
|
||||
};
|
||||
EXPECT_TRUE(sender.Send(data) == Channel<size_t>::QUEUE_IS_FULL);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2023-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
|
||||
@ -46,6 +46,7 @@ ohos_source_set("intention_cooperate_client") {
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/cooperate/data:intention_cooperate_data",
|
||||
"${device_status_root_path}/intention/data:intention_data",
|
||||
"${device_status_root_path}/intention/dfx:cooperate_dfx",
|
||||
"${device_status_root_path}/intention/ipc/socket:intention_socket_connection",
|
||||
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_client",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -20,6 +20,7 @@
|
||||
#include <numeric>
|
||||
#endif // ENABLE_PERFORMANCE_CHECK
|
||||
|
||||
#include "cooperate_hisysevent.h"
|
||||
#include "cooperate_params.h"
|
||||
#include "default_params.h"
|
||||
#include "devicestatus_define.h"
|
||||
@ -148,10 +149,12 @@ int32_t CooperateClient::Start(ITunnelClient &tunnel, const std::string &remoteN
|
||||
|
||||
int32_t ret = tunnel.Start(Intention::COOPERATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
CooperateDFX::WriteStart(OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
|
||||
FI_HILOGE("Activate cooperate failed");
|
||||
return ret;
|
||||
}
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
CooperateDFX::WriteStart(OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@ -166,9 +169,11 @@ int32_t CooperateClient::Stop(ITunnelClient &tunnel,
|
||||
|
||||
int32_t ret = tunnel.Stop(Intention::COOPERATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
CooperateDFX::WriteStop(OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
|
||||
FI_HILOGE("Deactivate cooperate failed");
|
||||
return ret;
|
||||
}
|
||||
CooperateDFX::WriteStop(OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2023-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
|
||||
@ -56,6 +56,7 @@ ohos_shared_library("intention_cooperate") {
|
||||
"${device_status_root_path}/intention/adapters/ddm_adapter:intention_ddm_adapter",
|
||||
"${device_status_root_path}/intention/adapters/ddp_adapter:intention_ddp_adapter",
|
||||
"${device_status_root_path}/intention/common/channel:intention_channel",
|
||||
"${device_status_root_path}/intention/dfx:cooperate_dfx",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
@ -68,7 +69,6 @@ ohos_shared_library("intention_cooperate") {
|
||||
"c_utils:utils",
|
||||
"device_manager:devicemanagersdk",
|
||||
"eventhandler:libeventhandler",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
|
@ -36,6 +36,7 @@ Cooperate::Cooperate(IContext *env)
|
||||
{
|
||||
auto [sender, receiver] = Channel<CooperateEvent>::OpenChannel();
|
||||
receiver_ = receiver;
|
||||
receiver_.Enable();
|
||||
context_.AttachSender(sender);
|
||||
context_.Enable();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -18,8 +18,8 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "display_manager.h"
|
||||
#include "xcollie/watchdog.h"
|
||||
|
||||
#include "cooperate_hisysevent.h"
|
||||
#include "ddm_adapter.h"
|
||||
#include "ddp_adapter.h"
|
||||
#include "devicestatus_define.h"
|
||||
@ -37,7 +37,6 @@ namespace {
|
||||
const std::string COOPERATE_SWITCH { "currentStatus" };
|
||||
const std::string THREAD_NAME { "os_Cooperate_EventHandler" };
|
||||
constexpr double PERCENT { 100.0 };
|
||||
const uint64_t WATCHDOG_TIMWVAL { 5000 };
|
||||
} // namespace
|
||||
|
||||
class BoardObserver final : public IBoardObserver {
|
||||
@ -190,11 +189,6 @@ int32_t Context::StartEventHandler()
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPR(runner, RET_ERR);
|
||||
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_Cooperate_EventHandler", eventHandler_,
|
||||
WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@ -268,7 +262,10 @@ void Context::EnableCooperate(const EnableCooperateEvent &event)
|
||||
{
|
||||
int32_t ret = env_->GetDP().UpdateCrossingSwitchState(true);
|
||||
if (ret != RET_OK) {
|
||||
CooperateDFX::WriteEnable(OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
|
||||
FI_HILOGE("Failed to update switch status");
|
||||
} else {
|
||||
CooperateDFX::WriteEnable(OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,7 +273,10 @@ void Context::DisableCooperate(const DisableCooperateEvent &event)
|
||||
{
|
||||
int32_t ret = env_->GetDP().UpdateCrossingSwitchState(false);
|
||||
if (ret != RET_OK) {
|
||||
CooperateDFX::WriteDisable(OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
|
||||
FI_HILOGE("Failed to update switch status");
|
||||
} else {
|
||||
CooperateDFX::WriteDisable(OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
#include "event_manager.h"
|
||||
|
||||
#include "cooperate_hisysevent.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "utility.h"
|
||||
|
||||
@ -125,6 +126,11 @@ void EventManager::RemoteStartFinish(const DSoftbusStartCooperateFinished &event
|
||||
CoordinationMessage::ACTIVATE_SUCCESS :
|
||||
CoordinationMessage::ACTIVATE_FAIL };
|
||||
OnCooperateMessage(msg, event.networkId);
|
||||
if (msg == CoordinationMessage::ACTIVATE_SUCCESS) {
|
||||
CooperateDFX::WriteRemoteStart(OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
|
||||
} else {
|
||||
CooperateDFX::WriteRemoteStart(OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::OnUnchain(const StopCooperateEvent &event)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
#include "cooperate_events.h"
|
||||
#include "cooperate_free.h"
|
||||
#include "cooperate_hisysevent.h"
|
||||
#include "cooperate_in.h"
|
||||
#include "cooperate_out.h"
|
||||
#include "devicestatus_define.h"
|
||||
@ -104,6 +105,8 @@ void StateMachine::TransiteTo(Context &context, CooperateState state)
|
||||
states_[current_]->OnLeaveState(context);
|
||||
current_ = state;
|
||||
states_[current_]->OnEnterState(context);
|
||||
auto curState = static_cast<OHOS::Msdp::DeviceStatus::CooperateState>(state);
|
||||
CooperateDFX::WriteCooperateState(curState);
|
||||
}
|
||||
}
|
||||
|
||||
|
53
intention/dfx/BUILD.gn
Normal file
53
intention/dfx/BUILD.gn
Normal file
@ -0,0 +1,53 @@
|
||||
# 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")
|
||||
|
||||
config("cooperate_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("cooperate_dfx") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"/third_party/cJSON",
|
||||
]
|
||||
|
||||
sources = [ "src/cooperate_hisysevent.cpp" ]
|
||||
|
||||
public_configs = [ ":cooperate_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [ "${device_status_utils_path}:devicestatus_util" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
80
intention/dfx/include/cooperate_hisysevent.h
Normal file
80
intention/dfx/include/cooperate_hisysevent.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 COOPERATE_HISYSEVENT_H
|
||||
#define COOPERATE_HISYSEVENT_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "hisysevent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
enum CooperateType : int32_t {
|
||||
ENABLE_SUCC = 0,
|
||||
ENABLE_FAIL = 1,
|
||||
DISABLE_SUCC = 2,
|
||||
DISABLE_FAIL = 3,
|
||||
LOCAL_ACTIVATE_SUCC = 4,
|
||||
LOCAL_ACTIVATE_FAIL = 5,
|
||||
REMOTE_ACTIVATE_SUCC = 6,
|
||||
REMOTE_ACTIVATE_FAIL = 7,
|
||||
LOCAL_DEACTIVATE_SUCC = 8,
|
||||
LOCAL_DEACTIVATE_FAIL = 9,
|
||||
REMOTE_DEACTIVATE_SUCC = 10,
|
||||
REMOTE_DEACTIVATE_FAIL = 11,
|
||||
OPENSESSION_SUCC = 12,
|
||||
OPENSESSION_FAIL = 13,
|
||||
UPDATESTATE_SUCC = 14,
|
||||
START_SUCC = 15,
|
||||
START_FAIL = 16,
|
||||
STOP_SUCC = 17,
|
||||
STOP_FAIL = 18,
|
||||
};
|
||||
enum CooperateState : size_t {
|
||||
COOPERATE_STATE_FREE = 0,
|
||||
COOPERATE_STATE_OUT,
|
||||
COOPERATE_STATE_IN,
|
||||
N_COOPERATE_STATES,
|
||||
};
|
||||
|
||||
class CooperateDFX {
|
||||
public:
|
||||
|
||||
static int32_t WriteEnable(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteDisable(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteLocalStart(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteLocalStop(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteRemoteStart(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteRemoteStop(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteOpenSession(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteStart(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteStop(OHOS::HiviewDFX::HiSysEvent::EventType type);
|
||||
static int32_t WriteCooperateState(CooperateState curState);
|
||||
template<typename... Types>
|
||||
static int32_t WriteInputFunc(const CooperateType &cooperateType,
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType eventType, Types... paras);
|
||||
|
||||
private:
|
||||
static std::map<CooperateState, std::string> CooperateState_;
|
||||
static std::map<CooperateType, std::pair<std::string, std::string>> serialStr_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_HISYSEVENT_H
|
165
intention/dfx/src/cooperate_hisysevent.cpp
Normal file
165
intention/dfx/src/cooperate_hisysevent.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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 "cooperate_hisysevent.h"
|
||||
|
||||
#include "fi_log.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "CooperateHiSysEvent"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
|
||||
std::map<CooperateState, std::string> CooperateDFX::CooperateState_ = {
|
||||
{ CooperateState::COOPERATE_STATE_FREE, "STATE_FREE" },
|
||||
{ CooperateState::COOPERATE_STATE_IN, "STATE_IN" },
|
||||
{ CooperateState::COOPERATE_STATE_OUT, "STATE_OUT" },
|
||||
};
|
||||
|
||||
std::map<CooperateType, std::pair<std::string, std::string>> CooperateDFX::serialStr_ = {
|
||||
{ CooperateType::ENABLE_SUCC, { "ENABLE_SUCCESS", "Enable cooperate successfully" } },
|
||||
{ CooperateType::ENABLE_FAIL, { "ENABLE_FAILED", "Enable cooperate failed" } },
|
||||
{ CooperateType::DISABLE_SUCC, { "DISABLE_SUCCESS", "Disenable cooperate successfully" } },
|
||||
{ CooperateType::DISABLE_FAIL, { "DISABLE_FAILED", "Disenable cooperate failed" } },
|
||||
{ CooperateType::LOCAL_ACTIVATE_SUCC, { "LOCAL_ACTIVATE_SUCCESS", "Local start cooperate successfully" } },
|
||||
{ CooperateType::LOCAL_ACTIVATE_FAIL, { "LOCAL_ACTIVATEE_FAILED", "Local start cooperate failed" } },
|
||||
{ CooperateType::REMOTE_ACTIVATE_SUCC, { "REMOTE_ACTIVATE_SUCCESS", "Remote start cooperate successfully" } },
|
||||
{ CooperateType::REMOTE_ACTIVATE_FAIL, { "REMOTE_ACTIVATE_FAILED", "Remote start cooperate failed" } },
|
||||
{ CooperateType::LOCAL_DEACTIVATE_SUCC, { "LOCAL_DEACTIVATE_SUCCESS", "Local stop cooperate successfully" } },
|
||||
{ CooperateType::LOCAL_DEACTIVATE_FAIL, { "LOCAL_DEACTIVATE_FAILED", "Local stop cooperate failed" } },
|
||||
{ CooperateType::REMOTE_DEACTIVATE_SUCC, { "REMOTE_DEACTIVATE_SUCCESS", "Remote stop cooperate successfully" } },
|
||||
{ CooperateType::REMOTE_DEACTIVATE_FAIL, { "REMOTE_DEACTIVATE_FAILED", "Remote stop cooperate failed" } },
|
||||
{ CooperateType::OPENSESSION_SUCC, { "OPENSESSION_SUCCESS", "Open session successfully" } },
|
||||
{ CooperateType::OPENSESSION_FAIL, { "OPENSESSION_FAILED", "Open session failed" } },
|
||||
{ CooperateType::UPDATESTATE_SUCC, { "UPDATESTATE_SUCCESS", "Update cooperatestate successfully" } },
|
||||
{ CooperateType::START_SUCC, { "START_SUCCESS", "Start client successfully" } },
|
||||
{ CooperateType::START_FAIL, { "START_FAILED", "Start client failed" } },
|
||||
{ CooperateType::STOP_SUCC, { "STOP_SUCCESS", "Stop client successfully" } },
|
||||
{ CooperateType::STOP_FAIL, { "STOP_FAILED", "Stop client failed" } },
|
||||
};
|
||||
|
||||
|
||||
template<typename... Types>
|
||||
int32_t CooperateDFX::WriteInputFunc(const CooperateType &cooperateType,
|
||||
OHOS::HiviewDFX::HiSysEvent::EventType eventType, Types... paras)
|
||||
{
|
||||
if (serialStr_.find(cooperateType) == serialStr_.end()) {
|
||||
FI_HILOGE("serialStr_ can't find the cooperate hisysevent type");
|
||||
return RET_ERR;
|
||||
}
|
||||
auto &[label, dec] = serialStr_[cooperateType];
|
||||
int32_t ret = HiSysEventWrite(
|
||||
OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
|
||||
label,
|
||||
eventType,
|
||||
paras...,
|
||||
"MSG",
|
||||
dec);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("HiviewDFX write failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteEnable(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::ENABLE_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::ENABLE_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteDisable(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::DISABLE_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::DISABLE_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteLocalStart(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::LOCAL_ACTIVATE_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::LOCAL_ACTIVATE_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteRemoteStart(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::REMOTE_ACTIVATE_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::REMOTE_ACTIVATE_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteLocalStop(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::LOCAL_DEACTIVATE_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::LOCAL_DEACTIVATE_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteRemoteStop(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::REMOTE_DEACTIVATE_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::REMOTE_DEACTIVATE_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteOpenSession(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::OPENSESSION_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::OPENSESSION_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteStart(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::START_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::START_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteStop(OHOS::HiviewDFX::HiSysEvent::EventType type)
|
||||
{
|
||||
if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) {
|
||||
return WriteInputFunc(CooperateType::STOP_SUCC, type);
|
||||
}
|
||||
return WriteInputFunc(CooperateType::STOP_FAIL, type);
|
||||
}
|
||||
|
||||
int32_t CooperateDFX::WriteCooperateState(CooperateState curState)
|
||||
{
|
||||
if (curState == CooperateState::N_COOPERATE_STATES) {
|
||||
return RET_ERR;
|
||||
}
|
||||
if (CooperateState_.find(curState) == CooperateState_.end()) {
|
||||
FI_HILOGE("CooperateState_ can't find the current cooperate state");
|
||||
return RET_ERR;
|
||||
}
|
||||
auto type = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
|
||||
std::string currentState = CooperateState_[curState];
|
||||
return WriteInputFunc(CooperateType::UPDATESTATE_SUCC, type, "CurrentState", currentState);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -140,7 +140,6 @@ ohos_source_set("intention_socket_connection") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "socket_client.h"
|
||||
|
||||
#include "event_handler.h"
|
||||
#include "xcollie/watchdog.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "intention_identity.h"
|
||||
@ -31,7 +30,6 @@ namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
const std::string THREAD_NAME { "os_ClientEventHandler" };
|
||||
const uint64_t WATCHDOG_TIMWVAL { 5000 };
|
||||
}
|
||||
|
||||
SocketClient::SocketClient(std::shared_ptr<ITunnelClient> tunnel)
|
||||
@ -39,10 +37,6 @@ SocketClient::SocketClient(std::shared_ptr<ITunnelClient> tunnel)
|
||||
{
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_ClientEventHandler", eventHandler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool SocketClient::RegisterEvent(MessageId id, std::function<int32_t(const StreamClient&, NetPacket&)> callback)
|
||||
|
20
intention/stationary/test/BUILD.gn
Normal file
20
intention/stationary/test/BUILD.gn
Normal file
@ -0,0 +1,20 @@
|
||||
# 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("//build/test.gni")
|
||||
import("../../../device_status.gni")
|
||||
|
||||
group("intention_stationary_test") {
|
||||
testonly = true
|
||||
deps = [ "unittest:unittest" ]
|
||||
}
|
55
intention/stationary/test/unittest/BUILD.gn
Normal file
55
intention/stationary/test/unittest/BUILD.gn
Normal file
@ -0,0 +1,55 @@
|
||||
# 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("//build/test.gni")
|
||||
import("../../../../device_status.gni")
|
||||
|
||||
module_output_path = "${device_status_part_name}/unit_out"
|
||||
|
||||
ohos_unittest("StationaryServerTest") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"${device_status_root_path}/intention/stationary/data/include",
|
||||
"${device_status_root_path}/intention/stationary/server/include",
|
||||
"${device_status_root_path}/libs/interface",
|
||||
"${device_status_service_path}/communication/service/include",
|
||||
]
|
||||
sources = [ "src/stationary_server_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_interfaces_path}/innerkits:devicestatus_client",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/services:devicestatus_static_service",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
"window_manager:libdm",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":StationaryServerTest" ]
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "devicestatus_callback_stub.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "fi_log.h"
|
||||
#include "stationary_params.h"
|
||||
#include "stationary_server.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "StationaryServerTest"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
using namespace testing::ext;
|
||||
|
||||
CallingContext context_;
|
||||
MessageParcel data_;
|
||||
MessageParcel reply_;
|
||||
StationaryServer stationary_;
|
||||
uint32_t SUBSCRIBE_STATIONARY_ONE = 1U;
|
||||
uint32_t SUBSCRIBE_STATIONARY_TWO = 2U;
|
||||
uint32_t SUBSCRIBE_STATIONARY_THREE = 3U;
|
||||
|
||||
class StationaryServerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {};
|
||||
static void TearDownTestCase() {};
|
||||
void SetUp() {};
|
||||
void TearDown() {};
|
||||
public:
|
||||
class StationaryServerTestCallback : public DeviceStatusCallbackStub {
|
||||
public:
|
||||
void OnDeviceStatusChanged(const Data& devicestatusData);
|
||||
};
|
||||
};
|
||||
|
||||
void StationaryServerTest::StationaryServerTestCallback::OnDeviceStatusChanged(const
|
||||
Data& devicestatusData)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "StationaryServerTestCallback type: " << devicestatusData.type;
|
||||
GTEST_LOG_(INFO) << "StationaryServerTestCallback value: " << devicestatusData.value;
|
||||
EXPECT_TRUE(devicestatusData.type == Type::TYPE_VERTICAL_POSITION &&
|
||||
devicestatusData.value >= OnChangedValue::VALUE_INVALID &&
|
||||
devicestatusData.value <= OnChangedValue::VALUE_EXIT) << "StationaryServerTestCallback failed";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: EnableTest001
|
||||
* @tc.desc: Test func named enable
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, EnableTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.Enable(context_, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DisableTest001
|
||||
* @tc.desc: Test func named disable
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, DisableTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.Disable(context_, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StartTest001
|
||||
* @tc.desc: Test func named start
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, StartTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.Start(context_, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StopTest001
|
||||
* @tc.desc: Test func named stop
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, StopTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.Stop(context_, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetParamTest001
|
||||
* @tc.desc: Test func named SetParam
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, SetParamTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.SetParam(context_, SUBSCRIBE_STATIONARY_ONE, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetParamTest001
|
||||
* @tc.desc: Test func named GetParam
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, GetParamTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.GetParam(context_, SUBSCRIBE_STATIONARY_ONE, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
ret = stationary_.GetParam(context_, SUBSCRIBE_STATIONARY_THREE, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ControlTest001
|
||||
* @tc.desc: Test func named Control
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, ControlTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.Control(context_, SUBSCRIBE_STATIONARY_ONE, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddWatchTest001
|
||||
* @tc.desc: Test func named addWatch success
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, AddWatchTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
sptr<IRemoteDevStaCallback> cb = new (std::nothrow) StationaryServerTestCallback();
|
||||
ASSERT_NE(cb, nullptr);
|
||||
SubscribeStationaryParam param;
|
||||
param.type_ = TYPE_HORIZONTAL_POSITION;
|
||||
param.event_ = ENTER;
|
||||
param.latency_ = SHORT;
|
||||
param.callback_ = cb;
|
||||
bool isSuccess = param.Marshalling(data_);
|
||||
EXPECT_TRUE(isSuccess);
|
||||
int32_t ret = stationary_.AddWatch(context_, SUBSCRIBE_STATIONARY_ONE, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
UnsubscribeStationaryParam param1;
|
||||
param1 = param;
|
||||
isSuccess = param1.Marshalling(data_);
|
||||
EXPECT_TRUE(isSuccess);
|
||||
ret = stationary_.RemoveWatch(context_, SUBSCRIBE_STATIONARY_TWO, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddWatchTest002
|
||||
* @tc.desc: Test func named addWatch fail
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, AddWatchTest002, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.AddWatch(context_, SUBSCRIBE_STATIONARY_TWO, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveWatchTest001
|
||||
* @tc.desc: Test func named RemoveWatch
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(StationaryServerTest, RemoveWatchTest001, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
int32_t ret = stationary_.RemoveWatch(context_, SUBSCRIBE_STATIONARY_ONE, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
ret = stationary_.RemoveWatch(context_, SUBSCRIBE_STATIONARY_TWO, data_, reply_);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -67,10 +67,9 @@ ohos_shared_library("devicestatus_client") {
|
||||
sources += [ "${device_status_root_path}/intention/frameworks/client/src/intention_manager.cpp" ]
|
||||
} else {
|
||||
sources += [ "${device_status_frameworks_path}/native/interaction/src/interaction_manager_impl.cpp" ]
|
||||
}
|
||||
|
||||
if (fusion_interaction_coordination) {
|
||||
sources += [ "${device_status_frameworks_path}/native/interaction/src/coordination_manager_impl.cpp" ]
|
||||
if (fusion_interaction_coordination) {
|
||||
sources += [ "${device_status_frameworks_path}/native/interaction/src/coordination_manager_impl.cpp" ]
|
||||
}
|
||||
}
|
||||
|
||||
configs = [ "${device_status_utils_path}:devicestatus_utils_config" ]
|
||||
@ -106,7 +105,6 @@ ohos_shared_library("devicestatus_client") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"image_framework:image_native",
|
||||
|
@ -37,10 +37,10 @@
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::GetUdKey(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>&)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::RegisterCoordinationListener(std::__h::shared_ptr<OHOS::Msdp::ICoordinationListener>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::UnregisterCoordinationListener(std::__h::shared_ptr<OHOS::Msdp::ICoordinationListener>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::PrepareCoordination(std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMessage)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::UnprepareCoordination(std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMessage)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::ActivateCoordination(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, int, std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMessage)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::DeactivateCoordination(bool, std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMessage)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::PrepareCoordination(std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMsgInfo const&)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::UnprepareCoordination(std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMsgInfo const&)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::ActivateCoordination(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, int, std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMsgInfo const&)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::DeactivateCoordination(bool, std::__h::function<void (std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Msdp::CoordinationMsgInfo const&)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::GetCoordinationState(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::function<void (bool)>, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::GetCoordinationState(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, bool&)";
|
||||
"OHOS::Msdp::DeviceStatus::InteractionManager::RegisterEventListener(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::shared_ptr<OHOS::Msdp::IEventListener>)";
|
||||
|
@ -81,7 +81,6 @@ ohos_shared_library("interaction_drag") {
|
||||
"graphic_2d:libcomposer",
|
||||
"graphic_2d:librender_service_base",
|
||||
"graphic_2d:window_animation",
|
||||
"hicollie:libhicollie",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
|
@ -61,12 +61,15 @@ public:
|
||||
|
||||
class DrawMouseIconModifier : public Rosen::RSContentStyleModifier {
|
||||
public:
|
||||
DrawMouseIconModifier() = default;
|
||||
explicit DrawMouseIconModifier(MMI::PointerStyle pointerStyle) : pointerStyle_(pointerStyle) {}
|
||||
~DrawMouseIconModifier() = default;
|
||||
void Draw(Rosen::RSDrawingContext &context) const override;
|
||||
|
||||
private:
|
||||
void OnDraw(std::shared_ptr<Media::PixelMap> pixelMap, int32_t pointerStyleId) const;
|
||||
void OnDraw(std::shared_ptr<Media::PixelMap> pixelMap) const;
|
||||
|
||||
private:
|
||||
MMI::PointerStyle pointerStyle_;
|
||||
};
|
||||
|
||||
class DrawDynamicEffectModifier : public Rosen::RSContentStyleModifier {
|
||||
@ -334,6 +337,7 @@ private:
|
||||
uint64_t screenId_ { 0 };
|
||||
Rosen::Rotation rotation_ { Rosen::Rotation::ROTATION_0 };
|
||||
ScreenSizeType currentScreenSize_ = ScreenSizeType::UNDEFINED;
|
||||
MMI::PointerStyle pointerStyle_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include "ui/rs_surface_extractor.h"
|
||||
#include "ui/rs_surface_node.h"
|
||||
#include "ui/rs_ui_director.h"
|
||||
#include "xcollie/watchdog.h"
|
||||
|
||||
#include "animation_curve.h"
|
||||
#include "devicestatus_define.h"
|
||||
@ -146,7 +145,6 @@ constexpr float SCALE_MD { 4.0f / 8 };
|
||||
constexpr float SCALE_LG { 5.0f / 12 };
|
||||
const std::string THREAD_NAME { "os_AnimationEventRunner" };
|
||||
const std::string SUPER_HUB_THREAD_NAME { "os_SuperHubEventRunner" };
|
||||
const uint64_t WATCHDOG_TIMWVAL { 5000 };
|
||||
const std::string COPY_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_Drag.svg" };
|
||||
const std::string COPY_ONE_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_One_Drag.svg" };
|
||||
const std::string FORBID_DRAG_PATH { "/system/etc/device_status/drag_icon/Forbid_Drag.svg" };
|
||||
@ -546,10 +544,6 @@ std::shared_ptr<AppExecFwk::EventHandler> DragDrawing::GetSuperHubHandler()
|
||||
{
|
||||
if (superHubHandler_ == nullptr) {
|
||||
auto runner = AppExecFwk::EventRunner::Create(SUPER_HUB_THREAD_NAME);
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread(SUPER_HUB_THREAD_NAME, handler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
superHubHandler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
|
||||
}
|
||||
return superHubHandler_;
|
||||
@ -701,10 +695,6 @@ void DragDrawing::OnDragStyleAnimation()
|
||||
if (handler_ == nullptr) {
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_AnimationEventRunner", handler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
}
|
||||
CheckStyleNodeModifier(dragStyleNode);
|
||||
handler_->PostTask(std::bind(&DragDrawing::ChangeStyleAnimation, this));
|
||||
@ -722,10 +712,6 @@ void DragDrawing::OnDragStyle(std::shared_ptr<Rosen::RSCanvasNode> dragStyleNode
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPV(runner);
|
||||
handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_AnimationEventRunner", handler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
}
|
||||
if (drawSVGModifier_ != nullptr) {
|
||||
dragStyleNode->RemoveModifier(drawSVGModifier_);
|
||||
@ -801,10 +787,6 @@ void DragDrawing::OnStopDragSuccess(std::shared_ptr<Rosen::RSCanvasNode> shadowN
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPV(runner);
|
||||
handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_AnimationEventRunner", handler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
if (!handler_->PostTask(std::bind(&DragDrawing::OnStopAnimationSuccess, this))) {
|
||||
FI_HILOGE("Failed to stop style animation");
|
||||
RunAnimation(animateCb);
|
||||
@ -869,10 +851,6 @@ void DragDrawing::OnStopDragFail(std::shared_ptr<Rosen::RSSurfaceNode> surfaceNo
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPV(runner);
|
||||
handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_AnimationEventRunner", handler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
if (!handler_->PostTask(std::bind(&DragDrawing::OnStopAnimationFail, this))) {
|
||||
FI_HILOGE("Failed to stop style animation");
|
||||
RunAnimation(animateCb);
|
||||
@ -895,10 +873,6 @@ int32_t DragDrawing::RunAnimation(std::function<int32_t()> cb)
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPR(runner, RET_ERR);
|
||||
handler_ = std::make_shared<AppExecFwk::EventHandler>(std::move(runner));
|
||||
int ret = HiviewDFX::Watchdog::GetInstance().AddThread("os_AnimationEventRunner", handler_, WATCHDOG_TIMWVAL);
|
||||
if (ret != 0) {
|
||||
FI_HILOGW("add watch dog failed");
|
||||
}
|
||||
if (!handler_->PostTask(cb)) {
|
||||
FI_HILOGE("Send vsync event failed");
|
||||
return RET_ERR;
|
||||
@ -943,7 +917,12 @@ int32_t DragDrawing::DrawMouseIcon()
|
||||
mouseIconNode->RemoveModifier(drawMouseIconModifier_);
|
||||
drawMouseIconModifier_ = nullptr;
|
||||
}
|
||||
drawMouseIconModifier_ = std::make_shared<DrawMouseIconModifier>();
|
||||
int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle_);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
|
||||
return RET_ERR;
|
||||
}
|
||||
drawMouseIconModifier_ = std::make_shared<DrawMouseIconModifier>(pointerStyle_);
|
||||
mouseIconNode->AddModifier(drawMouseIconModifier_);
|
||||
FI_HILOGD("leave");
|
||||
return RET_OK;
|
||||
@ -1968,20 +1947,13 @@ void DragDrawing::DoDrawMouse()
|
||||
FI_HILOGE("Check nodes valid failed");
|
||||
return;
|
||||
}
|
||||
MMI::PointerStyle pointerStyle;
|
||||
int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
|
||||
return;
|
||||
}
|
||||
if (g_drawingInfo.nodes.size() <= MOUSE_ICON_INDEX) {
|
||||
FI_HILOGE("The index is out of bounds, node size is %{public}zu", g_drawingInfo.nodes.size());
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<Rosen::RSCanvasNode> mouseIconNode = g_drawingInfo.nodes[MOUSE_ICON_INDEX];
|
||||
CHKPV(mouseIconNode);
|
||||
int32_t pointerStyleId = pointerStyle.id;
|
||||
if (pointerStyleId == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
|
||||
if (pointerStyle_.id == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
|
||||
int32_t positionX = g_drawingInfo.displayX - (g_drawingInfo.mouseWidth / CURSOR_CIRCLE_MIDDLE);
|
||||
int32_t positionY = g_drawingInfo.displayY - (g_drawingInfo.mouseHeight / CURSOR_CIRCLE_MIDDLE);
|
||||
mouseIconNode->SetBounds(positionX, positionY, g_drawingInfo.mouseWidth, g_drawingInfo.mouseHeight);
|
||||
@ -2316,6 +2288,7 @@ void DragDrawing::ResetParameter()
|
||||
g_drawingInfo.needDestroyDragWindow = false;
|
||||
needRotatePixelMapXY_ = false;
|
||||
hasRunningStopAnimation_ = false;
|
||||
pointerStyle_ = {};
|
||||
g_drawingInfo.sourceType = -1;
|
||||
g_drawingInfo.currentDragNum = -1;
|
||||
g_drawingInfo.pixelMapX = -1;
|
||||
@ -2501,6 +2474,8 @@ void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
|
||||
Rosen::Drawing::AdaptiveImageInfo rsImageInfo = { 1, 0, {}, 1, 0, pixelMapWidth, pixelMapHeight };
|
||||
auto cvs = pixelMapNode->BeginRecording(pixelMapWidth, pixelMapHeight);
|
||||
CHKPV(cvs);
|
||||
Rosen::Drawing::Brush brush;
|
||||
cvs->AttachBrush(brush);
|
||||
FilterInfo filterInfo = g_drawingInfo.filterInfo;
|
||||
if (g_drawingInfo.filterInfo.shadowEnable && !filterInfo.path.empty() &&
|
||||
g_drawingInfo.filterInfo.dragType == "text") {
|
||||
@ -2512,6 +2487,7 @@ void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
|
||||
} else {
|
||||
cvs->DrawPixelMapWithParm(g_drawingInfo.pixelMap, rsImageInfo, Rosen::Drawing::SamplingOptions());
|
||||
}
|
||||
cvs->DetachBrush();
|
||||
pixelMapNode->SetClipToBounds(true);
|
||||
pixelMapNode->FinishRecording();
|
||||
Rosen::RSTransaction::FlushImplicitTransaction();
|
||||
@ -2522,14 +2498,7 @@ void DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const
|
||||
{
|
||||
FI_HILOGD("enter");
|
||||
std::string imagePath;
|
||||
MMI::PointerStyle pointerStyle;
|
||||
int32_t ret = MMI::InputManager::GetInstance()->GetPointerStyle(GLOBAL_WINDOW_ID, pointerStyle);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
|
||||
return;
|
||||
}
|
||||
int32_t pointerStyleId = pointerStyle.id;
|
||||
if (pointerStyleId == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
|
||||
if (pointerStyle_.id == MOUSE_DRAG_CURSOR_CIRCLE_STYLE) {
|
||||
imagePath = MOUSE_DRAG_CURSOR_CIRCLE_PATH;
|
||||
} else {
|
||||
imagePath = MOUSE_DRAG_DEFAULT_PATH;
|
||||
@ -2539,7 +2508,7 @@ void DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const
|
||||
uint32_t errCode = 0;
|
||||
auto imageSource = Media::ImageSource::CreateImageSource(imagePath, opts, errCode);
|
||||
CHKPV(imageSource);
|
||||
int32_t pointerSize = pointerStyle.size;
|
||||
int32_t pointerSize = pointerStyle_.size;
|
||||
if (pointerSize < DEFAULT_MOUSE_SIZE) {
|
||||
FI_HILOGD("Invalid pointerSize:%{public}d", pointerSize);
|
||||
pointerSize = DEFAULT_MOUSE_SIZE;
|
||||
@ -2549,17 +2518,17 @@ void DrawMouseIconModifier::Draw(Rosen::RSDrawingContext &context) const
|
||||
.width = pow(INCREASE_RATIO, pointerSize - 1) * DEVICE_INDEPENDENT_PIXEL * GetScaling(),
|
||||
.height = pow(INCREASE_RATIO, pointerSize - 1) * DEVICE_INDEPENDENT_PIXEL * GetScaling()
|
||||
};
|
||||
int32_t pointerColor = pointerStyle.color;
|
||||
int32_t pointerColor = pointerStyle_.color;
|
||||
if (pointerColor != INVALID_COLOR_VALUE) {
|
||||
decodeOpts.SVGOpts.fillColor = {.isValidColor = true, .color = pointerColor};
|
||||
}
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errCode);
|
||||
CHKPV(pixelMap);
|
||||
OnDraw(pixelMap, pointerStyleId);
|
||||
OnDraw(pixelMap);
|
||||
FI_HILOGD("leave");
|
||||
}
|
||||
|
||||
void DrawMouseIconModifier::OnDraw(std::shared_ptr<Media::PixelMap> pixelMap, int32_t pointerStyleId) const
|
||||
void DrawMouseIconModifier::OnDraw(std::shared_ptr<Media::PixelMap> pixelMap) const
|
||||
{
|
||||
FI_HILOGD("enter");
|
||||
CHKPV(pixelMap);
|
||||
|
@ -21,6 +21,7 @@ group("device_status_unittest") {
|
||||
"intention/common:unittest",
|
||||
"intention/scheduler:unittest",
|
||||
"intentiontest:DragManagerTest",
|
||||
"intentiontest:DragServerTest",
|
||||
"intentiontest:SocketSessionTest",
|
||||
"utils:UtilityTest",
|
||||
]
|
||||
|
@ -12,4 +12,5 @@
|
||||
# limitations under the License.
|
||||
|
||||
[cfi]
|
||||
type:*OHOS::Msdp::DeviceStatus::ContextService*
|
||||
src:*timer_manager_test.cpp
|
@ -96,10 +96,66 @@ ohos_unittest("SocketSessionTest") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("DragServerTest") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${device_status_root_path}/libs/interface",
|
||||
"${device_status_service_path}/communication/service/include",
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
sources = [ "src/drag_server_test.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_interfaces_path}/innerkits:devicestatus_client",
|
||||
"${device_status_root_path}/intention/data:intention_data",
|
||||
"${device_status_root_path}/intention/drag/client:intention_drag_client",
|
||||
"${device_status_root_path}/intention/drag/data:intention_drag_data",
|
||||
"${device_status_root_path}/intention/drag/server:intention_drag_server",
|
||||
"${device_status_root_path}/intention/ipc/socket:intention_socket_connection",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/services:devicestatus_static_service",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_service_path}/interaction/coordination:coordination",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
]
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"device_manager:devicemanagersdk",
|
||||
"graphic_2d:libcomposer",
|
||||
"graphic_2d:librender_service_base",
|
||||
"graphic_2d:window_animation",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"image_framework:image_native",
|
||||
"init:libbegetutil",
|
||||
"input:libmmi-client",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":DragManagerTest",
|
||||
":DragServerTest",
|
||||
":SocketSessionTest",
|
||||
]
|
||||
}
|
||||
|
47
test/unittest/intentiontest/include/drag_server_test.h
Normal file
47
test/unittest/intentiontest/include/drag_server_test.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 DRAG_MANAGER_TEST_H
|
||||
#define DRAG_MANAGER_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "delegate_tasks.h"
|
||||
#include "device_manager.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "devicestatus_delayed_sp_singleton.h"
|
||||
#include "drag_client.h"
|
||||
#include "drag_manager.h"
|
||||
#include "i_context.h"
|
||||
#include "socket_session_manager.h"
|
||||
#include "timer_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class DragServerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height);
|
||||
static std::optional<DragData> CreateDragData(int32_t sourceType, int32_t pointerId, int32_t dragNum,
|
||||
bool hasCoordinateCorrected, int32_t shadowNum);
|
||||
void AssignToAnimation(PreviewAnimation &animation);
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // DRAG_MANAGER_TEST_H
|
@ -483,7 +483,8 @@ HWTEST_F(DragManagerTest, DragManagerTest14, TestSize.Level0)
|
||||
ret = InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
EXPECT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);}
|
||||
std::future_status::timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DragManagerTest15
|
||||
|
1176
test/unittest/intentiontest/src/drag_server_test.cpp
Normal file
1176
test/unittest/intentiontest/src/drag_server_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -38,6 +38,7 @@ std::unique_ptr<SocketClient> g_client {nullptr};
|
||||
std::shared_ptr<SocketConnection> g_socket { nullptr };
|
||||
std::shared_ptr<SocketServer> g_socketServer { nullptr };
|
||||
std::shared_ptr<SocketSession> g_session { nullptr };
|
||||
std::shared_ptr<SocketSession> g_sessionOne { nullptr };
|
||||
std::shared_ptr<SocketSessionManager> g_socketSessionManager { nullptr };
|
||||
IContext *g_context { nullptr };
|
||||
Intention g_intention { Intention::UNKNOWN_INTENTION };
|
||||
@ -54,10 +55,11 @@ void SocketSessionTest::SetUp()
|
||||
g_socketSessionManager = std::make_shared<SocketSessionManager>();
|
||||
int32_t moduleType = 1;
|
||||
int32_t tokenType = 1;
|
||||
int32_t uid = 1;
|
||||
int32_t pid = 1;
|
||||
int32_t sockFds[2] { -1, -1 };
|
||||
g_session = std::make_shared<SocketSession>("", moduleType, tokenType, sockFds[0], uid, pid);
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
int32_t pid = IPCSkeleton::GetCallingPid();
|
||||
int32_t sockFds[2] { 0, -1 };
|
||||
g_session = std::make_shared<SocketSession>("test", moduleType, tokenType, sockFds[0], uid, pid);
|
||||
g_sessionOne = std::make_shared<SocketSession>("test1", moduleType, tokenType, sockFds[1], uid, pid);
|
||||
}
|
||||
void SocketSessionTest::TearDown()
|
||||
{
|
||||
@ -67,6 +69,7 @@ void SocketSessionTest::TearDown()
|
||||
g_socketSessionManager = nullptr;
|
||||
g_session = nullptr;
|
||||
g_socketServer = nullptr;
|
||||
g_sessionOne = nullptr;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
|
||||
}
|
||||
|
||||
@ -596,6 +599,21 @@ HWTEST_F(SocketSessionTest, SocketSessionTest29, TestSize.Level0)
|
||||
g_socketSessionManager->sessions_.clear();
|
||||
g_socketSessionManager->callbacks_.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SocketSessionTest30
|
||||
* @tc.desc: Drag Drawing
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(SocketSessionTest, SocketSessionTest30, TestSize.Level0)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
char buf[BUF_CMD_SIZE] = { 0 };
|
||||
size_t size = 1;
|
||||
bool ret = g_sessionOne->SendMsg(buf, size);
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -37,7 +37,7 @@ constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
|
||||
const std::string STR_INFO { "abc12345" };
|
||||
const std::string STR_PREFIX { "abc" };
|
||||
const std::string NETWORK_ID = { "abcd123456ef" };
|
||||
const std::string EXPECT_ID = { "abcd******56ef" };
|
||||
const std::string EXPECT_ID = { "abcd1******456ef" };
|
||||
const std::string COPY_DRAG_PATH { "/system/etc/device_status/drag_icon/Copy_Drag.svg" };
|
||||
constexpr int32_t FILE_SIZE_MAX { 0x5000 };
|
||||
constexpr size_t SIZE1 {10};
|
||||
@ -396,7 +396,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize1_002, TestSize.Level1)
|
||||
const char *id = "";
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id, Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("******", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("**********", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
@ -412,7 +412,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize1_003, TestSize.Level1)
|
||||
const char *id = "abcd123456";
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id, Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("******", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("abcd1*****23456", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize1_004, TestSize.Level1)
|
||||
const char *id = "abcd123456efghijklmnopqrstuvwxyzabcd";
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id, Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("abcd******56ef", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("abcd1*****zabcd", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize1_005, TestSize.Level1)
|
||||
const char *id = nullptr;
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id, Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("******", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("**********", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
@ -476,7 +476,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize2_002, TestSize.Level1)
|
||||
std::string id = "";
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id.c_str(), Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("******", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("**********", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
@ -492,7 +492,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize2_003, TestSize.Level1)
|
||||
std::string id = "abcd123456";
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id.c_str(), Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("******", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("abcd1*****23456", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
@ -508,7 +508,7 @@ HWTEST_F(UtilityTest, UtityTest_Anonymize2_004, TestSize.Level1)
|
||||
std::string id = "abcd123456efghijklmnopqrstuvwxyzabcd";
|
||||
FI_HILOGI("%{public}d: Before anonymous processing, it is %{public}s, and after processing, it is %{public}s.",
|
||||
__LINE__, id.c_str(), Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("abcd******abcd", Utility::Anonymize(id).c_str());
|
||||
bool isEqual = Utility::IsEqual("abcd1*****zabcd", Utility::Anonymize(id).c_str());
|
||||
ASSERT_TRUE(isEqual);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user