Merge branch 'master' of gitee.com:openharmony/msdp_device_status into master

Signed-off-by: 李少雄 <lishaoxiong10@huawei.com>
This commit is contained in:
李少雄 2024-04-28 13:06:37 +00:00 committed by Gitee
commit ad853efa07
35 changed files with 1591 additions and 74 deletions

View File

@ -37,6 +37,7 @@ group("device_status_tests") {
testonly = true
deps = [
"frameworks/native/interaction/test:interaction_manager_test",
"intention/adapters:intention_adapter_test",
"intention/common/channel:intention_channel_test",
"intention/services/test:intention_services_test",
"services/native/test:devicestatussrv_test",

View File

@ -48,7 +48,8 @@
"dsoftbus",
"motion",
"ylong_runtime",
"dfs_service"
"dfs_service",
"hicollie"
],
"third_party": [
"libxml2",

View File

@ -43,6 +43,7 @@ device_status_libs_path = "${device_status_root_path}/libs"
device_status_frameworks_path = "${device_status_root_path}/frameworks"
device_status_service_path = "${device_status_root_path}/services"
device_status_utils_path = "${device_status_root_path}/utils/common"
device_status_intention_path = "${device_status_root_path}/intention"
device_status_fuzz_output_path = "${device_status_part_name}/device_status"
intention_root_path = "//base/msdp/device_status/intention"
file_dfs_service_path = "//foundation/filemanagement/dfs_service"

View File

@ -33,12 +33,13 @@ namespace Msdp {
namespace DeviceStatus {
class DeviceStatusCallback : public DeviceStatusCallbackStub {
public:
DeviceStatusCallback() {}
DeviceStatusCallback(napi_env env);
virtual ~DeviceStatusCallback() {};
void OnDeviceStatusChanged(const Data &devicestatusData) override;
static void EmitOnEvent(const Data &data);
private:
inline static std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
napi_env env_ { nullptr };
std::mutex mutex_;
};

View File

@ -46,14 +46,20 @@ thread_local DeviceStatusNapi *g_obj = nullptr;
std::map<int32_t, sptr<IRemoteDevStaCallback>> DeviceStatusNapi::callbacks_;
napi_ref DeviceStatusNapi::devicestatusValueRef_ = nullptr;
void DeviceStatusCallback::OnDeviceStatusChanged(const Data &devicestatusData)
DeviceStatusCallback::DeviceStatusCallback(napi_env env)
{
CALL_DEBUG_ENTER;
std::lock_guard<std::mutex> guard(mutex_);
env_ = env;
auto runner = AppExecFwk::EventRunner::GetMainEventRunner();
if (runner != nullptr) {
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
}
void DeviceStatusCallback::OnDeviceStatusChanged(const Data &devicestatusData)
{
CALL_DEBUG_ENTER;
std::lock_guard<std::mutex> guard(mutex_);
auto task = [devicestatusData]() {
FI_HILOGI("Execute lamdba");
EmitOnEvent(devicestatusData);
@ -348,7 +354,7 @@ napi_value DeviceStatusNapi::SubscribeDeviceStatusCallback(napi_env env, napi_ca
FI_HILOGD("Callback exists");
return nullptr;
}
sptr<IRemoteDevStaCallback> callback = new (std::nothrow) DeviceStatusCallback();
sptr<IRemoteDevStaCallback> callback = new (std::nothrow) DeviceStatusCallback(env);
CHKPP(callback);
int32_t subscribeRet = StationaryManager::GetInstance()->SubscribeCallback(static_cast<Type>(type),
static_cast<ActivityEvent>(event), static_cast<ReportLatencyNs>(latency), callback);

View File

@ -2495,6 +2495,259 @@ HWTEST_F(InteractionManagerTest, CheckDragBehavior_006, TestSize.Level1)
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_Shadow
* @tc.desc: Check drag shadow
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Shadow, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 10, \"drag_shadow_offsetY\": 10,"
"\"drag_shadow_argb\": \"ffffffff\", \"drag_shadow_path\": \"M 10 10 H 90 V 90 H 10 L 10 10\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_ShadowAlpha
* @tc.desc: Check drag shadow alpha
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_ShadowAlpha, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 10, \"drag_shadow_offsetY\": 10,"
"\"drag_shadow_argb\": \"33ffffff\", \"drag_shadow_path\": \"M 10 10 H 90 V 90 H 10 L 10 10\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_ShadowColor
* @tc.desc: Check drag shadow color
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_ShadowColor, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 10, \"drag_shadow_offsetY\": 10,"
"\"drag_shadow_argb\": \"ffff0000\", \"drag_shadow_path\": \"M 10 10 H 90 V 90 H 10 L 10 10\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_ShadowOffset
* @tc.desc: Check drag shadow offset
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_ShadowOffset, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 30, \"drag_shadow_offsetY\": 30,"
"\"drag_shadow_argb\": \"ffffffff\", \"drag_shadow_path\": \"M 10 10 H 90 V 90 H 10 L 10 10\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_ShadowCornerRadius
* @tc.desc: Check drag shadow corner radius
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_ShadowCornerRadius, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->extraInfo = "{ \"drag_corner_radius\": 30, \"drag_allow_distributed\": false }";
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 10, \"drag_shadow_offsetY\": 10,"
"\"drag_shadow_argb\": \"ffffffff\", \"drag_shadow_path\": \"M 10 10 H 90 V 90 H 10 L 10 10\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_ShadowPath001
* @tc.desc: Check drag shadow path
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_ShadowPath001, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 30, \"drag_shadow_offsetY\": 30,"
"\"drag_shadow_argb\": \"ffffffff\", \"drag_shadow_path\": \"M 10 10 H 80 V 80 H 10 L 10 10\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
/**
* @tc.name: InteractionManagerTest_StartDrag_ShadowPath002
* @tc.desc: Check drag shadow path
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_ShadowPath002, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("Param displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
dragData->filterInfo = "{ \"dip_scale\": 3.5, \"drag_shadow_offsetX\": 30, \"drag_shadow_offsetY\": 30,"
"\"drag_shadow_argb\": \"ffffffff\" }";
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
std::make_shared<UnitTestStartDragListener>(callback));
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -18,6 +18,8 @@
#include <cinttypes>
#include <condition_variable>
#include "xcollie/watchdog.h"
#include "devicestatus_client.h"
#include "fd_listener.h"
#include "fi_log.h"
@ -34,6 +36,7 @@ namespace DeviceStatus {
using namespace AppExecFwk;
namespace {
const std::string THREAD_NAME { "os_ClientEventHandler" };
const uint64_t WATCHDOG_TIMWVAL { 5000 };
} // namespace
Client::~Client()
@ -106,6 +109,10 @@ 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());

View File

@ -0,0 +1,21 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("../../device_status.gni")
group("intention_adapter_test") {
testonly = true
deps = []
deps += [ "unittest:unittest" ]
}

View File

@ -0,0 +1,86 @@
# 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("InputAdapterTest") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
module_out_path = module_output_path
include_dirs = [
"${device_status_utils_path}",
"${device_status_utils_path}/include",
"${device_status_intention_path}/prototype/include",
]
sources = [ "src/input_adapter_test.cpp" ]
deps = [ "${device_status_intention_path}/adapters/input_adapter:intention_input_adapter" ]
external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"c_utils:utils",
"hilog:libhilog",
"input:libmmi-client",
]
}
ohos_unittest("DDInputAdapterTest") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
module_out_path = module_output_path
include_dirs = [
"${device_status_interfaces_path}/innerkits/interaction/include",
"${device_status_utils_path}",
"${device_status_utils_path}/include",
"${device_status_intention_path}/prototype/include",
"${device_status_root_path}/utils/ipc/include",
]
sources = [ "src/ddinput_adapter_test.cpp" ]
deps = [ "${device_status_intention_path}/adapters/dinput_adapter:intention_dinput_adapter" ]
external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"c_utils:utils",
"hilog:libhilog",
"image_framework:image_native",
"input:libmmi-client",
"ipc:ipc_single",
"window_manager:libdm",
]
}
group("unittest") {
testonly = true
deps = [
":DDInputAdapterTest",
":InputAdapterTest",
]
}

View File

@ -0,0 +1,304 @@
/*
* 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 <future>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include <unistd.h>
#include "accesstoken_kit.h"
#include <gtest/gtest.h>
#include "input_device.h"
#include "pointer_event.h"
#include "securec.h"
#include "devicestatus_define.h"
#include "devicestatus_errors.h"
#include "i_dinput_adapter.h"
#include "dinput_adapter.h"
#include "drag_data.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
#undef LOG_TAG
#define LOG_TAG "DDnputAdapterTest"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
using namespace testing::ext;
namespace {
constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
const std::string SYSTEM_CORE { "system_core" };
uint64_t g_tokenID { 0 };
const char* g_cores[] = { "ohos.permission.INPUT_MONITORING" };
std::string defaultNetworkId { "Default NetworkId" };
} // namespace
class DDnputAdapterTest : public testing::Test {
public:
void SetUp();
void TearDown();
static void SetUpTestCase();
static void SetPermission(const std::string &level, const char** perms, size_t permAmount);
static void RemovePermission();
};
void DDnputAdapterTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
{
CALL_DEBUG_ENTER;
if (perms == nullptr || permAmount == 0) {
FI_HILOGE("The perms is empty");
return;
}
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = permAmount,
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.processName = "DDnputAdapterTest",
.aplStr = level.c_str(),
};
g_tokenID = GetAccessTokenId(&infoInstance);
SetSelfTokenID(g_tokenID);
OHOS::Security::AccessToken::AccessTokenKit::AccessTokenKit::ReloadNativeTokenInfo();
}
void DDnputAdapterTest::RemovePermission()
{
CALL_DEBUG_ENTER;
int32_t ret = OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(g_tokenID);
if (ret != RET_OK) {
FI_HILOGE("Failed to remove permission");
return;
}
}
void DDnputAdapterTest::SetUpTestCase() {}
void DDnputAdapterTest::SetUp() {}
void DDnputAdapterTest::TearDown()
{
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
}
/**
* @tc.name: TestNeedFilterOut
* @tc.desc: Test NeedFilterOut
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, TestNeedFilterOut, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
bool ret = dinputAdapter->IsNeedFilterOut(defaultNetworkId, std::move(businessEvent));
ASSERT_TRUE(ret);
RemovePermission();
}
/**
* @tc.name: TestStartRemoteInput
* @tc.desc: Test StartRemoteInput
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, StartRemoteInput, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->StartRemoteInput(defaultNetworkId, defaultNetworkId, inputDeviceDhids, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestStopRemoteInput
* @tc.desc: Test StopRemoteInput
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, StopRemoteInput, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->StopRemoteInput(defaultNetworkId, defaultNetworkId, inputDeviceDhids, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestStopRemoteInput_0
* @tc.desc: Test StopRemoteInput_0
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, StopRemoteInput_0, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->StopRemoteInput(defaultNetworkId, inputDeviceDhids, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestPrepareRemoteInput
* @tc.desc: Test PrepareRemoteInput
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, PrepareRemoteInput, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->PrepareRemoteInput(defaultNetworkId, defaultNetworkId, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestUnPrepareRemoteInput
* @tc.desc: Test UnPrepareRemoteInput
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->UnPrepareRemoteInput(defaultNetworkId, defaultNetworkId, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestPrepareRemoteInput_0
* @tc.desc: Test PrepareRemoteInput_0
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, PrepareRemoteInput_0, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->PrepareRemoteInput(defaultNetworkId, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestUnPrepareRemoteInput_0
* @tc.desc: Test UnPrepareRemoteInput_0
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput_0, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
IDInputAdapter::BusinessEvent businessEvent;
DInputAdapter::DInputCallback callback = [] (bool param) {
FI_HILOGI("On callback");
};
std::vector<std::string> inputDeviceDhids {};
bool ret = dinputAdapter->UnPrepareRemoteInput(defaultNetworkId, callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestRegisterSessionStateCb
* @tc.desc: Test RegisterSessionStateCb
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, RegisterSessionStateCb, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
auto callback = [] (uint32_t param) {
FI_HILOGI("On callback");
};
bool ret = dinputAdapter->RegisterSessionStateCb(callback);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestUnPrepareRemoteInput_1
* @tc.desc: Test UnPrepareRemoteInput_1
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DDnputAdapterTest, UnPrepareRemoteInput_1, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IDInputAdapter> dinputAdapter = std::make_shared<DInputAdapter>(nullptr);
dinputAdapter->UnregisterSessionStateCb();
RemovePermission();
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -0,0 +1,303 @@
/*
* 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 <memory>
#include <utility>
#include <vector>
#include <unistd.h>
#include "accesstoken_kit.h"
#include <gtest/gtest.h>
#include "input_device.h"
#include "pointer_event.h"
#include "securec.h"
#include "devicestatus_define.h"
#include "devicestatus_errors.h"
#include "input_adapter.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
#undef LOG_TAG
#define LOG_TAG "InputAdapterTest"
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
using namespace testing::ext;
namespace {
constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
const std::string SYSTEM_CORE { "system_core" };
uint64_t g_tokenID { 0 };
const char* g_cores[] = { "ohos.permission.INPUT_MONITORING" };
} // namespace
class InputAdapterTest : public testing::Test {
public:
void SetUp();
void TearDown();
static void SetUpTestCase();
static void SetPermission(const std::string &level, const char** perms, size_t permAmount);
static void RemovePermission();
};
void InputAdapterTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
{
CALL_DEBUG_ENTER;
if (perms == nullptr || permAmount == 0) {
FI_HILOGE("The perms is empty");
return;
}
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = permAmount,
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.processName = "InputAdapterTest",
.aplStr = level.c_str(),
};
g_tokenID = GetAccessTokenId(&infoInstance);
SetSelfTokenID(g_tokenID);
OHOS::Security::AccessToken::AccessTokenKit::AccessTokenKit::ReloadNativeTokenInfo();
}
void InputAdapterTest::RemovePermission()
{
CALL_DEBUG_ENTER;
int32_t ret = OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(g_tokenID);
if (ret != RET_OK) {
FI_HILOGE("Failed to remove permission");
return;
}
}
void InputAdapterTest::SetUpTestCase() {}
void InputAdapterTest::SetUp() {}
void InputAdapterTest::TearDown()
{
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
}
/**
* @tc.name: TestPointerAddMonitor
* @tc.desc: Test AddMonitor
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestPointerAddMonitor, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
auto callback = [] (std::shared_ptr<OHOS::MMI::PointerEvent>) {
FI_HILOGI("OnEvent");
};
int32_t monitorId = inputAdapter->AddMonitor(callback);
ASSERT_TRUE(monitorId > 0);
inputAdapter->RemoveMonitor(monitorId);
RemovePermission();
}
/**
* @tc.name: TestPointerAddMonitor
* @tc.desc: Test AddMonitor
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestKeyAddMonitor, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
auto callback = [] (std::shared_ptr<OHOS::MMI::KeyEvent>) {
FI_HILOGI("OnEvent");
};
int32_t monitorId = inputAdapter->AddMonitor(callback);
ASSERT_TRUE(monitorId > 0);
inputAdapter->RemoveMonitor(monitorId);
RemovePermission();
}
/**
* @tc.name: TestAddKeyEventInterceptor
* @tc.desc: Test AddKeyEventInterceptor
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, AddKeyEventInterceptor, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
auto callback = [] (std::shared_ptr<OHOS::MMI::KeyEvent>) {
FI_HILOGI("OnEvent");
};
int32_t interceptorId = inputAdapter->AddInterceptor(callback);
ASSERT_TRUE(interceptorId > 0);
inputAdapter->RemoveInterceptor(interceptorId);
RemovePermission();
}
/**
* @tc.name: TestAddPointerEventInterceptor
* @tc.desc: Test AddPointerEventInterceptor
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, AddPointerEventInterceptor, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
auto callback = [] (std::shared_ptr<OHOS::MMI::PointerEvent>) {
FI_HILOGI("OnEvent");
};
int32_t interceptorId = inputAdapter->AddInterceptor(callback);
ASSERT_TRUE(interceptorId > 0);
inputAdapter->RemoveInterceptor(interceptorId);
RemovePermission();
}
/**
* @tc.name: TestAddBothEventInterceptor
* @tc.desc: Test AddBothEventInterceptor
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, AddBothEventInterceptor, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
auto pointerCallback = [] (std::shared_ptr<OHOS::MMI::PointerEvent>) {
FI_HILOGI("OnEvent");
};
auto keyCallback = [] (std::shared_ptr<OHOS::MMI::KeyEvent>) {
FI_HILOGI("OnEvent");
};
int32_t interceptorId = inputAdapter->AddInterceptor(pointerCallback, keyCallback);
ASSERT_TRUE(interceptorId > 0);
inputAdapter->RemoveInterceptor(interceptorId);
RemovePermission();
}
/**
* @tc.name: TestAddFilter
* @tc.desc: Test AddFilter
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, AddFilter, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
auto filterCallback = [] (std::shared_ptr<OHOS::MMI::PointerEvent>) -> bool {
FI_HILOGI("OnEvent");
return true;
};
int32_t filterId = inputAdapter->AddFilter(filterCallback);
ASSERT_TRUE(filterId > 0);
inputAdapter->RemoveFilter(filterId);
RemovePermission();
}
/**
* @tc.name: TestSetPointerVisibility
* @tc.desc: Test SetPointerVisibility
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestSetPointerVisibility, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
int32_t filterId = inputAdapter->SetPointerVisibility(true);
ASSERT_TRUE(filterId > 0);
RemovePermission();
}
/**
* @tc.name: TestSetPointerLocation
* @tc.desc: Test SetPointerLocation
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestSetPointerLocation, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
int32_t filterId = inputAdapter->SetPointerLocation(0, 0);
ASSERT_TRUE(filterId > 0);
RemovePermission();
}
/**
* @tc.name: TestEnableInputDevice
* @tc.desc: Test EnableInputDevice
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestEnableInputDevice, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
int32_t ret = inputAdapter->EnableInputDevice(true);
ASSERT_EQ(ret, RET_OK);
RemovePermission();
}
/**
* @tc.name: TestSimulateKeyEvent
* @tc.desc: Test SimulateKeyEvent
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestSimulateKeyEvent, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
inputAdapter->SimulateInputEvent(MMI::KeyEvent::Create());
RemovePermission();
}
/**
* @tc.name: TestSimulatePointerEvent
* @tc.desc: Test SimulatePointerEvent
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputAdapterTest, TestSimulatePointerEvent, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_CORE, g_cores, sizeof(g_cores) / sizeof(g_cores[0]));
std::shared_ptr<IInputAdapter> inputAdapter = std::make_shared<InputAdapter>();
inputAdapter->SimulateInputEvent(MMI::PointerEvent::Create());
RemovePermission();
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -63,10 +63,12 @@ ohos_shared_library("intention_cooperate") {
external_deps = [
"ability_runtime:app_manager",
"access_token:libaccesstoken_sdk",
"access_token:libtoken_setproc",
"c_utils:utils",
"device_manager:devicemanagersdk",
"eventhandler:libeventhandler",
"hicollie:libhicollie",
"hilog:libhilog",
"image_framework:image_native",
"input:libmmi-client",

View File

@ -43,7 +43,7 @@ public:
int32_t RegisterEventListener(int32_t pid, const std::string &networkId) override;
int32_t UnregisterEventListener(int32_t pid, const std::string &networkId) override;
int32_t Enable(int32_t pid, int32_t userData) override;
int32_t Enable(int32_t tokenId, int32_t pid, int32_t userData) override;
int32_t Disable(int32_t pid, int32_t userData) override;
int32_t Start(int32_t pid, int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId) override;
int32_t Stop(int32_t pid, int32_t userData, bool isUnchained) override;

View File

@ -90,7 +90,6 @@ struct RegisterListenerEvent {
using UnregisterListenerEvent = RegisterListenerEvent;
using RegisterHotareaListenerEvent = RegisterListenerEvent;
using UnregisterHotareaListenerEvent = RegisterListenerEvent;
using EnableCooperateEvent = RegisterListenerEvent;
using DisableCooperateEvent = RegisterListenerEvent;
struct StartCooperateEvent {
@ -101,6 +100,12 @@ struct StartCooperateEvent {
std::shared_ptr<std::promise<int32_t>> errCode;
};
struct EnableCooperateEvent {
int32_t tokenId;
int32_t pid;
int32_t userData;
};
struct StopCooperateEvent {
int32_t pid;
int32_t userData;
@ -211,6 +216,7 @@ struct CooperateEvent {
RegisterListenerEvent,
StartCooperateEvent,
StopCooperateEvent,
EnableCooperateEvent,
GetCooperateStateEvent,
RegisterEventListenerEvent,
DSoftbusSubscribeMouseLocation,

View File

@ -18,6 +18,7 @@
#include "nocopyable.h"
#include "accesstoken_kit.h"
#include "app_mgr_interface.h"
#include "iapplication_state_observer.h"
@ -63,7 +64,8 @@ private:
void OnSoftbusSessionClosed(Context &context, const CooperateEvent &event);
void Transfer(Context &context, const CooperateEvent &event);
sptr<AppExecFwk::IAppMgr> GetAppMgr();
int32_t RegisterApplicationStateObserver(Channel<CooperateEvent>::Sender sender);
int32_t RegisterApplicationStateObserver(Channel<CooperateEvent>::Sender sender, const std::string &bundleName);
std::string GetPackageName(Security::AccessToken::AccessTokenID tokenId);
void UnregisterApplicationStateObserver();
void AddSessionObserver(Context &context, const EnableCooperateEvent &event);
void RemoveSessionObserver(Context &context, const DisableCooperateEvent &event);
@ -77,6 +79,7 @@ private:
std::array<std::shared_ptr<ICooperateState>, N_COOPERATE_STATES> states_;
std::set<std::string> onlineBoards_;
int32_t monitorId_ { -1 };
std::vector<std::string> clientBundleNames_;
sptr<AppExecFwk::IApplicationStateObserver> appStateObserver_ { nullptr };
};
} // namespace Cooperate

View File

@ -110,13 +110,14 @@ int32_t Cooperate::UnregisterHotAreaListener(int32_t pid)
return RET_OK;
}
int32_t Cooperate::Enable(int32_t pid, int32_t userData)
int32_t Cooperate::Enable(int32_t tokenId, int32_t pid, int32_t userData)
{
CALL_DEBUG_ENTER;
StartWorker();
context_.Sender().Send(CooperateEvent(
CooperateEventType::ENABLE,
EnableCooperateEvent {
.tokenId = tokenId,
.pid = pid,
.userData = userData,
}));

View File

@ -18,6 +18,7 @@
#include <algorithm>
#include "display_manager.h"
#include "xcollie/watchdog.h"
#include "ddm_adapter.h"
#include "ddp_adapter.h"
@ -36,6 +37,7 @@ 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 {
@ -185,7 +187,13 @@ void Context::Disable()
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;
}

View File

@ -321,6 +321,7 @@ void StateMachine::Transfer(Context &context, const CooperateEvent &event)
sptr<AppExecFwk::IAppMgr> StateMachine::GetAppMgr()
{
CALL_INFO_TRACE;
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
CHKPP(saMgr);
auto appMgrObj = saMgr->GetSystemAbility(APP_MGR_SERVICE_ID);
@ -328,15 +329,17 @@ sptr<AppExecFwk::IAppMgr> StateMachine::GetAppMgr()
return iface_cast<AppExecFwk::IAppMgr>(appMgrObj);
}
int32_t StateMachine::RegisterApplicationStateObserver(Channel<CooperateEvent>::Sender sender)
int32_t StateMachine::RegisterApplicationStateObserver(Channel<CooperateEvent>::Sender sender,
const std::string &bundleName)
{
CALL_INFO_TRACE;
clientBundleNames_.push_back(bundleName);
FI_HILOGI("Register application %{public}s state observer", bundleName.c_str());
auto appMgr = GetAppMgr();
CHKPR(appMgr, RET_ERR);
appStateObserver_ = sptr<AppStateObserver>::MakeSptr(sender);
std::vector<std::string> bundleNames { "com.huawei.associateassistant" };
FI_HILOGI("Register application(\"com.huawei.associateassistant\") state observer");
auto err = appMgr->RegisterApplicationStateObserver(appStateObserver_, bundleNames);
if (err != ERR_OK) {
auto err = appMgr->RegisterApplicationStateObserver(appStateObserver_, clientBundleNames_);
if (err != RET_OK) {
appStateObserver_.clear();
FI_HILOGE("IAppMgr::RegisterApplicationStateObserver fail, error:%{public}d", err);
return RET_ERR;
@ -346,12 +349,13 @@ int32_t StateMachine::RegisterApplicationStateObserver(Channel<CooperateEvent>::
void StateMachine::UnregisterApplicationStateObserver()
{
CALL_INFO_TRACE;
CHKPV(appStateObserver_);
auto appMgr = GetAppMgr();
CHKPV(appMgr);
FI_HILOGI("Unregister application(\"com.huawei.associateassistant\") state observer");
FI_HILOGI("Unregister application associateassistant state observer");
auto err = appMgr->UnregisterApplicationStateObserver(appStateObserver_);
if (err != ERR_OK) {
if (err != RET_OK) {
FI_HILOGE("IAppMgr::UnregisterApplicationStateObserver fail, error:%{public}d", err);
}
appStateObserver_.clear();
@ -359,7 +363,42 @@ void StateMachine::UnregisterApplicationStateObserver()
void StateMachine::AddSessionObserver(Context &context, const EnableCooperateEvent &event)
{
RegisterApplicationStateObserver(context.Sender());
CALL_INFO_TRACE;
std::string packageName = GetPackageName(event.tokenId);
RegisterApplicationStateObserver(context.Sender(), packageName);
}
std::string StateMachine::GetPackageName(Security::AccessToken::AccessTokenID tokenId)
{
CALL_INFO_TRACE;
std::string bundleName {"Default"};
int32_t tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
switch (tokenType) {
case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: {
Security::AccessToken::HapTokenInfo hapInfo;
if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) != RET_OK) {
FI_HILOGE("Get hap token info failed");
} else {
bundleName = hapInfo.bundleName;
}
break;
}
case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE:
case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: {
Security::AccessToken::NativeTokenInfo tokenInfo;
if (Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, tokenInfo) != RET_OK) {
FI_HILOGE("Get native token info failed");
} else {
bundleName = tokenInfo.processName;
}
break;
}
default: {
FI_HILOGW("token type not match");
break;
}
}
return bundleName;
}
void StateMachine::RemoveSessionObserver(Context &context, const DisableCooperateEvent &event)

View File

@ -52,7 +52,7 @@ int32_t CooperateServer::Enable(CallingContext &context, MessageParcel &data, Me
}
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
CHKPR(cooperate, RET_ERR);
cooperate->Enable(context.pid, param.userData);
cooperate->Enable(context.tokenId, context.pid, param.userData);
return RET_OK;
}

View File

@ -140,6 +140,7 @@ ohos_source_set("intention_socket_connection") {
external_deps = [
"c_utils:utils",
"eventhandler:libeventhandler",
"hicollie:libhicollie",
"hilog:libhilog",
]

View File

@ -37,7 +37,7 @@ public:
int32_t GetPid() const override;
std::string ToString() const override;
std::string GetProgramName() const override;
void SetProgramName(const std::string programName) override;
void SetProgramName(const std::string &programName) override;
int32_t GetFd() const override;
void Dispatch(const struct epoll_event &ev) override;
@ -73,7 +73,7 @@ inline std::string SocketSession::GetProgramName() const
return programName_;
}
inline void SocketSession::SetProgramName(const std::string programName)
inline void SocketSession::SetProgramName(const std::string &programName)
{
programName_ = programName;
}

View File

@ -16,6 +16,7 @@
#include "socket_client.h"
#include "event_handler.h"
#include "xcollie/watchdog.h"
#include "devicestatus_define.h"
#include "intention_identity.h"
@ -30,6 +31,7 @@ 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)
@ -37,6 +39,10 @@ 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)

View File

@ -55,7 +55,7 @@ public:
virtual int32_t RegisterHotAreaListener(int32_t pid) = 0;
virtual int32_t UnregisterHotAreaListener(int32_t pid) = 0;
virtual int32_t Enable(int32_t pid, int32_t userData) = 0;
virtual int32_t Enable(int32_t tokenId, int32_t pid, int32_t userData) = 0;
virtual int32_t Disable(int32_t pid, int32_t userData) = 0;
virtual int32_t Start(int32_t pid, int32_t userData,
const std::string &remoteNetworkId, int32_t startDeviceId) = 0;

View File

@ -44,7 +44,7 @@ public:
virtual int32_t GetFd() const = 0;
virtual std::string ToString() const = 0;
virtual std::string GetProgramName() const = 0;
virtual void SetProgramName(const std::string programName) = 0;
virtual void SetProgramName(const std::string &programName) = 0;
};
using SocketSessionPtr = std::shared_ptr<ISocketSession>;

View File

@ -105,6 +105,7 @@ ohos_shared_library("devicestatus_client") {
external_deps = [
"c_utils:utils",
"eventhandler:libeventhandler",
"hicollie:libhicollie",
"hilog:libhilog",
"hitrace:hitrace_meter",
"image_framework:image_native",

View File

@ -82,6 +82,7 @@ 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",

View File

@ -28,6 +28,7 @@
#include "vsync_receiver.h"
#include "drag_data.h"
#include "i_context.h"
#include "i_drag_animation.h"
namespace OHOS {
@ -51,6 +52,9 @@ class DrawPixelMapModifier : public Rosen::RSContentStyleModifier {
public:
DrawPixelMapModifier() = default;
~DrawPixelMapModifier() = default;
void SetDragShadow(std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode) const;
void SetTextDragShadow(std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode) const;
Rosen::SHADOW_COLOR_STRATEGY ConvertShadowColorStrategy(int32_t shadowColorStrategy) const;
void Draw(Rosen::RSDrawingContext &context) const override;
};
@ -119,9 +123,21 @@ private:
};
struct FilterInfo {
std::string dragType;
bool shadowEnable { false };
bool shadowIsFilled { false };
bool shadowMask { false };
int32_t shadowColorStrategy { 0 };
float shadowCorner { 0.0F };
float dipScale { 0.0f };
float cornerRadius { 0.0f };
float opacity { 0.95f };
float offsetX { 0.0f };
float offsetY { 0.0f };
uint32_t argb { 0 };
std::string path;
float elevation { 0.0f };
bool isHardwareAcceleration { false };
};
struct ExtraInfo {
@ -152,6 +168,7 @@ struct DrawingInfo {
std::atomic_bool isCurrentDefaultStyle { false };
bool isInitUiDirector { true };
bool isExistScalingValue { false };
std::atomic_bool needDestroyDragWindow { false };
int32_t sourceType { -1 };
int32_t currentDragNum { -1 };
DragCursorStyle currentStyle { DragCursorStyle::DEFAULT };
@ -166,6 +183,8 @@ struct DrawingInfo {
int32_t mouseHeight { 0 };
int32_t rootNodeWidth { -1 };
int32_t rootNodeHeight { -1 };
std::atomic<int64_t> startNum { -1 };
int32_t timerId { -1 };
float scalingValue { 0.0 };
std::vector<std::shared_ptr<Rosen::RSCanvasNode>> nodes;
std::vector<std::shared_ptr<Rosen::RSCanvasNode>> multiSelectedNodes;
@ -175,6 +194,7 @@ struct DrawingInfo {
std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode { nullptr };
std::shared_ptr<Media::PixelMap> pixelMap { nullptr };
std::shared_ptr<Media::PixelMap> stylePixelMap { nullptr };
IContext* context { nullptr };
ExtraInfo extraInfo;
FilterInfo filterInfo;
};
@ -193,8 +213,8 @@ public:
int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle);
int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
int32_t StartVsync();
void OnDragSuccess();
void OnDragFail();
void OnDragSuccess(IContext* context);
void OnDragFail(IContext* context);
void EraseMouseIcon();
void DestroyDragWindow();
void UpdateDrawingState();
@ -241,6 +261,9 @@ private:
bool NeedAdjustSvgInfo();
void SetDecodeOptions(Media::DecodeOptions &decodeOpts);
bool ParserFilterInfo(const std::string &filterInfoStr, FilterInfo &filterInfo);
void ParserDragShadowInfo(const std::string &filterInfoStr, FilterInfo &filterInfo);
void ParserTextDragShadowInfo(const std::string &filterInfoStr, FilterInfo &filterInfo);
void PrintDragShadowInfo();
void ProcessFilter();
bool ParserExtraInfo(const std::string &extraInfoStr, ExtraInfo &extraInfo);
static float RadiusVp2Sigma(float radiusVp, float dipScale);
@ -266,11 +289,12 @@ private:
void RotateDisplayXY(int32_t &displayX, int32_t &displayY);
void RotatePixelMapXY(int32_t &pixelMapX, int32_t &pixelMapY);
void ResetAnimationParameter();
void ResetAnimationFlag(bool isForce = false);
void DoEndAnimation();
void ResetParameter();
int32_t DoRotateDragWindow(float rotation);
private:
int64_t startNum_ { -1 };
int64_t interruptNum_ { -1 };
std::shared_ptr<Rosen::RSCanvasNode> canvasNode_ { nullptr };
std::shared_ptr<DrawSVGModifier> drawSVGModifier_ { nullptr };
@ -288,7 +312,6 @@ private:
std::atomic_bool needBreakStyleScaleAnimation_ { false };
std::atomic_bool hasRunningAnimation_ { false };
void* dragExtHandler_ { nullptr };
bool needDestroyDragWindow_ { false };
bool needRotatePixelMapXY_ { false };
uint64_t screenId_ { 0 };
Rosen::Rotation rotation_ { Rosen::Rotation::ROTATION_0 };

View File

@ -38,6 +38,7 @@
#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"
@ -136,6 +137,7 @@ constexpr int32_t TIME_STOP_SUCCESS_STYLE { 150 };
constexpr int32_t TIME_STOP { 0 };
constexpr int64_t TIME_SLEEP { 30000 };
constexpr int32_t INTERRUPT_SCALE { 15 };
constexpr int32_t TIMEOUT_MS { 500 };
constexpr float MAX_SCREEN_WIDTH_SM { 320.0f };
constexpr float MAX_SCREEN_WIDTH_MD { 600.0f };
constexpr float MAX_SCREEN_WIDTH_LG { 840.0f };
@ -144,6 +146,7 @@ constexpr float SCALE_SM { 3.0f / 4 };
constexpr float SCALE_MD { 4.0f / 8 };
constexpr float SCALE_LG { 5.0f / 12 };
const std::string THREAD_NAME { "os_AnimationEventRunner" };
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" };
@ -371,7 +374,7 @@ int32_t DragDrawing::UpdateShadowPic(const ShadowInfo &shadowInfo)
return RET_OK;
}
void DragDrawing::OnDragSuccess()
void DragDrawing::OnDragSuccess(IContext* context)
{
FI_HILOGI("enter");
if (!CheckNodesValid()) {
@ -386,17 +389,19 @@ void DragDrawing::OnDragSuccess()
CHKPV(shadowNode);
std::shared_ptr<Rosen::RSCanvasNode> styleNode = g_drawingInfo.nodes[DRAG_STYLE_INDEX];
CHKPV(styleNode);
g_drawingInfo.context = context;
OnStopDragSuccess(shadowNode, styleNode);
FI_HILOGI("leave");
}
void DragDrawing::OnDragFail()
void DragDrawing::OnDragFail(IContext* context)
{
FI_HILOGI("enter");
std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode = g_drawingInfo.surfaceNode;
CHKPV(surfaceNode);
std::shared_ptr<Rosen::RSNode> rootNode = g_drawingInfo.rootNode;
CHKPV(rootNode);
g_drawingInfo.context = context;
OnStopDragFail(surfaceNode, rootNode);
FI_HILOGI("leave");
}
@ -427,7 +432,7 @@ void DragDrawing::EraseMouseIcon()
void DragDrawing::DestroyDragWindow()
{
FI_HILOGD("enter");
FI_HILOGI("enter");
ResetParameter();
RemoveModifier();
ClearMultiSelectedData();
@ -455,7 +460,7 @@ void DragDrawing::DestroyDragWindow()
CHKPV(rsUiDirector_);
rsUiDirector_->SetRoot(-1);
rsUiDirector_->SendMessages();
FI_HILOGD("leave");
FI_HILOGI("leave");
}
void DragDrawing::UpdateDrawingState()
@ -504,6 +509,10 @@ void DragDrawing::OnStartDrag(const DragAnimationData &dragAnimationData,
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(dragDropStartExtFunc, g_dragData))) {
FI_HILOGE("Start style animation failed");
@ -583,20 +592,20 @@ void DragDrawing::RemoveStyleNodeModifier(std::shared_ptr<Rosen::RSCanvasNode> s
void DragDrawing::UpdateAnimationProtocol(Rosen::RSAnimationTimingProtocol protocol)
{
FI_HILOGD("enter");
startNum_ = START_TIME;
g_drawingInfo.startNum = START_TIME;
interruptNum_ = START_TIME * INTERRUPT_SCALE;
hasRunningAnimation_ = true;
bool stopSignal = true;
CHKPV(rsUiDirector_);
while (hasRunningAnimation_) {
hasRunningAnimation_ = rsUiDirector_->FlushAnimation(startNum_);
hasRunningAnimation_ = rsUiDirector_->FlushAnimation(g_drawingInfo.startNum);
rsUiDirector_->FlushModifier();
rsUiDirector_->SendMessages();
if ((startNum_ >= interruptNum_) && stopSignal) {
if ((g_drawingInfo.startNum >= interruptNum_) && stopSignal) {
protocol.SetDuration(TIME_STOP);
stopSignal = false;
}
startNum_ += INTERVAL_TIME;
g_drawingInfo.startNum += INTERVAL_TIME;
usleep(TIME_SLEEP);
}
FI_HILOGD("leave");
@ -688,6 +697,10 @@ 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));
@ -705,6 +718,10 @@ 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_);
@ -740,8 +757,6 @@ void DragDrawing::OnStopAnimationSuccess()
}
CHKPV(g_drawingInfo.rootNode);
hasRunningStopAnimation_ = true;
startNum_ = START_TIME;
needDestroyDragWindow_ = true;
if (drawDragStopModifier_ != nullptr) {
g_drawingInfo.rootNode->RemoveModifier(drawDragStopModifier_);
drawDragStopModifier_ = nullptr;
@ -768,7 +783,7 @@ void DragDrawing::OnStopAnimationSuccess()
drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE);
});
});
StartVsync();
DoEndAnimation();
FI_HILOGI("leave");
}
@ -782,6 +797,10 @@ 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);
@ -817,8 +836,6 @@ void DragDrawing::OnStopAnimationFail()
}
drawDragStopModifier_ = std::make_shared<DrawDragStopModifier>();
hasRunningStopAnimation_ = true;
startNum_ = START_TIME;
needDestroyDragWindow_ = true;
g_drawingInfo.rootNode->AddModifier(drawDragStopModifier_);
drawDragStopModifier_->SetAlpha(BEGIN_ALPHA);
drawDragStopModifier_->SetScale(BEGIN_SCALE);
@ -834,7 +851,7 @@ void DragDrawing::OnStopAnimationFail()
drawDragStopModifier_->SetStyleScale(START_STYLE_SCALE);
drawDragStopModifier_->SetStyleAlpha(END_STYLE_ALPHA);
});
StartVsync();
DoEndAnimation();
FI_HILOGI("leave");
}
@ -848,6 +865,10 @@ 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);
@ -870,6 +891,10 @@ 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;
@ -950,12 +975,10 @@ int32_t DragDrawing::InitVSync(float endAlpha, float endScale)
drawDynamicEffectModifier_->SetAlpha(endAlpha);
drawDynamicEffectModifier_->SetScale(endScale);
});
CHKPR(g_drawingInfo.parentNode, RET_ERR);
Rosen::RSTransaction::FlushImplicitTransaction();
startNum_ = START_TIME;
needDestroyDragWindow_ = true;
DoEndAnimation();
FI_HILOGD("leave");
return StartVsync();
return RET_OK;
}
int32_t DragDrawing::StartVsync()
@ -979,7 +1002,7 @@ int32_t DragDrawing::StartVsync()
if (ret != RET_OK) {
FI_HILOGE("Request next vsync failed");
}
FI_HILOGI("enter");
FI_HILOGI("leave");
return ret;
}
@ -987,19 +1010,14 @@ void DragDrawing::OnVsync()
{
FI_HILOGD("enter");
CHKPV(rsUiDirector_);
bool hasRunningAnimation = rsUiDirector_->FlushAnimation(startNum_);
bool hasRunningAnimation = rsUiDirector_->FlushAnimation(g_drawingInfo.startNum);
rsUiDirector_->FlushModifier();
rsUiDirector_->SendMessages();
if (!hasRunningAnimation) {
FI_HILOGD("Stop runner, hasRunningAnimation:%{public}d", hasRunningAnimation);
if (needDestroyDragWindow_) {
CHKPV(g_drawingInfo.rootNode);
if (drawDynamicEffectModifier_ != nullptr) {
g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_);
drawDynamicEffectModifier_ = nullptr;
}
DestroyDragWindow();
g_drawingInfo.isRunning = false;
ResetAnimationParameter();
FI_HILOGI("Stop runner, hasRunningAnimation:%{public}d, needDestroyDragWindow:%{public}d",
hasRunningAnimation, g_drawingInfo.needDestroyDragWindow.load());
if (g_drawingInfo.needDestroyDragWindow) {
ResetAnimationFlag();
}
return;
}
@ -1012,7 +1030,7 @@ void DragDrawing::OnVsync()
FI_HILOGE("Request next vsync failed");
}
rsUiDirector_->SendMessages();
startNum_ += INTERVAL_TIME;
g_drawingInfo.startNum += INTERVAL_TIME;
FI_HILOGD("leave");
}
@ -1474,10 +1492,94 @@ void DragDrawing::SetDecodeOptions(Media::DecodeOptions &decodeOpts)
FI_HILOGD("leave");
}
void DragDrawing::ParserDragShadowInfo(const std::string &filterInfoStr, FilterInfo &filterInfo)
{
JsonParser filterInfoParser;
filterInfoParser.json = cJSON_Parse(filterInfoStr.c_str());
if (!cJSON_IsObject(filterInfoParser.json)) {
FI_HILOGE("FilterInfo is not json object");
return;
}
cJSON *offsetX = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_shadow_offsetX");
if (cJSON_IsNumber(offsetX)) {
filterInfo.offsetX = static_cast<float>(offsetX->valuedouble);
}
cJSON *offsetY = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_shadow_offsetY");
if (cJSON_IsNumber(offsetY)) {
filterInfo.offsetY = static_cast<float>(offsetY->valuedouble);
}
cJSON *argb = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_shadow_argb");
if (cJSON_IsNumber(argb)) {
filterInfo.argb = static_cast<uint32_t>(argb->valueint);
}
cJSON *shadowIsFilled = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_is_filled");
if (cJSON_IsBool(shadowIsFilled)) {
filterInfo.shadowIsFilled = cJSON_IsTrue(shadowIsFilled);
}
cJSON *shadowMask = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_mask");
if (cJSON_IsBool(shadowMask)) {
filterInfo.shadowMask = cJSON_IsTrue(shadowMask);
}
cJSON *shadowColorStrategy = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_color_strategy");
if (cJSON_IsNumber(shadowColorStrategy)) {
filterInfo.shadowColorStrategy = shadowColorStrategy->valueint;
}
cJSON *isHardwareAcceleration = cJSON_GetObjectItemCaseSensitive(
filterInfoParser.json, "shadow_is_hardwareacceleration");
if (cJSON_IsBool(isHardwareAcceleration)) {
filterInfo.isHardwareAcceleration = cJSON_IsTrue(isHardwareAcceleration);
}
if (filterInfo.isHardwareAcceleration) {
cJSON *elevation = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_elevation");
if (cJSON_IsNumber(elevation)) {
filterInfo.elevation = static_cast<float>(elevation->valuedouble);
}
} else {
cJSON *shadowCorner = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_corner");
if (cJSON_IsNumber(shadowCorner)) {
filterInfo.shadowCorner = static_cast<float>(shadowCorner->valuedouble);
}
}
cJSON_Delete(filterInfoParser.json);
}
void DragDrawing::ParserTextDragShadowInfo(const std::string &filterInfoStr, FilterInfo &filterInfo)
{
JsonParser filterInfoParser;
filterInfoParser.json = cJSON_Parse(filterInfoStr.c_str());
if (!cJSON_IsObject(filterInfoParser.json)) {
FI_HILOGE("FilterInfo is not json object");
return;
}
cJSON *path = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_shadow_path");
if (cJSON_IsString(path)) {
filterInfo.path = path->valuestring;
}
cJSON_Delete(filterInfoParser.json);
}
void DragDrawing::PrintDragShadowInfo()
{
FilterInfo filterInfo = g_drawingInfo.filterInfo;
if (!filterInfo.shadowEnable) {
FI_HILOGI("Not supported shadow");
return;
}
FI_HILOGI("dragType:%{public}s, shadowIsFilled:%{public}s, shadowMask:%{public}s, shadowColorStrategy :%{public}d, "
"shadowCorner:%{public}f, offsetX:%{public}f, offsetY:%{public}f, argb:%{public}u, elevation:%{public}f, "
"isHardwareAcceleration:%{public}s", filterInfo.dragType.c_str(),
filterInfo.shadowIsFilled ? "true" : "false", filterInfo.shadowMask ? "true" : "false",
filterInfo.shadowColorStrategy, filterInfo.shadowCorner, filterInfo.offsetX, filterInfo.offsetY,
filterInfo.argb, filterInfo.elevation, filterInfo.isHardwareAcceleration ? "true" : "false");
if (!filterInfo.path.empty()) {
FI_HILOGI("%{public}s", filterInfo.path.c_str());
}
}
bool DragDrawing::ParserFilterInfo(const std::string &filterInfoStr, FilterInfo &filterInfo)
{
FI_HILOGD("FilterInfo size:%{public}zu, filterInfo:%{public}s",
filterInfoStr.size(), filterInfoStr.c_str());
FI_HILOGD("FilterInfo size:%{public}zu, filterInfo:%{public}s", filterInfoStr.size(), filterInfoStr.c_str());
if (filterInfoStr.empty()) {
FI_HILOGD("FilterInfo is empty");
return false;
@ -1496,6 +1598,21 @@ bool DragDrawing::ParserFilterInfo(const std::string &filterInfoStr, FilterInfo
if (cJSON_IsNumber(cornerRadius)) {
filterInfo.cornerRadius = static_cast<float>(cornerRadius->valuedouble);
}
cJSON *dragType = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "drag_type");
if (cJSON_IsString(dragType)) {
filterInfo.dragType = dragType->valuestring;
}
cJSON *shadowEnable = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "shadow_enable");
if (cJSON_IsBool(shadowEnable)) {
filterInfo.shadowEnable = cJSON_IsTrue(shadowEnable);
}
if (filterInfo.shadowEnable) {
ParserDragShadowInfo(filterInfoStr, filterInfo);
if (filterInfo.dragType == "text") {
ParserTextDragShadowInfo(filterInfoStr, filterInfo);
}
PrintDragShadowInfo();
}
cJSON *opacity = cJSON_GetObjectItemCaseSensitive(filterInfoParser.json, "dip_opacity");
if (cJSON_IsNumber(opacity)) {
if ((opacity->valuedouble) > MAX_OPACITY || (opacity->valuedouble) <= MIN_OPACITY) {
@ -1504,6 +1621,7 @@ bool DragDrawing::ParserFilterInfo(const std::string &filterInfoStr, FilterInfo
filterInfo.opacity = static_cast<float>(opacity->valuedouble);
}
}
cJSON_Delete(filterInfoParser.json);
return true;
}
@ -1537,6 +1655,7 @@ bool DragDrawing::ParserExtraInfo(const std::string &extraInfoStr, ExtraInfo &ex
if (cJSON_IsBool(allowDistributed)) {
extraInfo.allowDistributed = cJSON_IsTrue(allowDistributed) ? true : false;
}
cJSON_Delete(extraInfoParser.json);
return true;
}
@ -1636,8 +1755,8 @@ int32_t DragDrawing::SetNodesLocation(int32_t positionX, int32_t positionY)
g_drawingInfo.parentNode->SetFrame(positionX, positionY, g_drawingInfo.pixelMap->GetWidth() + adjustSize,
g_drawingInfo.pixelMap->GetHeight() + adjustSize);
});
startNum_ = START_TIME;
needDestroyDragWindow_ = false;
g_drawingInfo.startNum = START_TIME;
g_drawingInfo.needDestroyDragWindow = false;
StartVsync();
FI_HILOGD("leave");
return RET_OK;
@ -2049,13 +2168,49 @@ void DragDrawing::ResetAnimationParameter()
handler_ = nullptr;
CHKPV(receiver_);
receiver_ = nullptr;
FI_HILOGI("leave");
}
void DragDrawing::ResetAnimationFlag(bool isForce)
{
FI_HILOGI("enter");
if (!isForce && (g_drawingInfo.context != nullptr) && (g_drawingInfo.timerId >= 0)) {
g_drawingInfo.context->GetTimerManager().RemoveTimer(g_drawingInfo.timerId);
g_drawingInfo.timerId = -1;
}
if (drawDynamicEffectModifier_ != nullptr) {
CHKPV(g_drawingInfo.rootNode);
g_drawingInfo.rootNode->RemoveModifier(drawDynamicEffectModifier_);
drawDynamicEffectModifier_ = nullptr;
}
DestroyDragWindow();
g_drawingInfo.isRunning = false;
g_drawingInfo.timerId = -1;
ResetAnimationParameter();
FI_HILOGI("leave");
}
void DragDrawing::DoEndAnimation()
{
FI_HILOGI("enter");
g_drawingInfo.startNum = START_TIME;
g_drawingInfo.needDestroyDragWindow = true;
if (g_drawingInfo.context != nullptr) {
int32_t repeatCount = 1;
g_drawingInfo.timerId = g_drawingInfo.context->GetTimerManager().AddTimer(TIMEOUT_MS, repeatCount, [this]() {
FI_HILOGW("Timeout, automatically reset animation flag");
ResetAnimationFlag(true);
});
}
StartVsync();
FI_HILOGI("leave");
}
void DragDrawing::ResetParameter()
{
FI_HILOGI("enter");
startNum_ = START_TIME;
needDestroyDragWindow_ = false;
g_drawingInfo.startNum = START_TIME;
g_drawingInfo.needDestroyDragWindow = false;
needRotatePixelMapXY_ = false;
hasRunningStopAnimation_ = false;
g_drawingInfo.sourceType = -1;
@ -2178,6 +2333,46 @@ void DrawSVGModifier::Draw(Rosen::RSDrawingContext& context) const
FI_HILOGD("leave");
}
Rosen::SHADOW_COLOR_STRATEGY DrawPixelMapModifier::ConvertShadowColorStrategy(int32_t shadowColorStrategy) const
{
if (shadowColorStrategy == static_cast<int32_t>(Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE)) {
return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ;
} else if (shadowColorStrategy == static_cast<int32_t>(Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_AVERAGE)) {
return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_AVERAGE ;
} else if (shadowColorStrategy == static_cast<int32_t>(Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_MAIN)) {
return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_MAIN ;
} else {
return Rosen::SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE;
}
}
void DrawPixelMapModifier::SetTextDragShadow(std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode) const
{
if (!g_drawingInfo.filterInfo.path.empty()) {
FI_HILOGD("path:%{public}s", g_drawingInfo.filterInfo.path.c_str());
pixelMapNode->SetShadowPath(Rosen::RSPath::CreateRSPath(g_drawingInfo.filterInfo.path));
} else {
FI_HILOGW("path is empty");
}
}
void DrawPixelMapModifier::SetDragShadow(std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode) const
{
pixelMapNode->SetShadowOffset(g_drawingInfo.filterInfo.offsetX, g_drawingInfo.filterInfo.offsetY);
pixelMapNode->SetShadowColor(g_drawingInfo.filterInfo.argb);
pixelMapNode->SetShadowMask(g_drawingInfo.filterInfo.shadowMask);
pixelMapNode->SetShadowIsFilled(g_drawingInfo.filterInfo.shadowIsFilled);
pixelMapNode->SetShadowColorStrategy(ConvertShadowColorStrategy(g_drawingInfo.filterInfo.shadowColorStrategy));
if (g_drawingInfo.filterInfo.isHardwareAcceleration) {
pixelMapNode->SetShadowElevation(g_drawingInfo.filterInfo.elevation);
} else {
pixelMapNode->SetShadowRadius(g_drawingInfo.filterInfo.shadowCorner);
}
if (g_drawingInfo.filterInfo.dragType == "text") {
SetTextDragShadow(pixelMapNode);
}
}
void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
{
FI_HILOGD("enter");
@ -2190,6 +2385,9 @@ void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
}
std::shared_ptr<Rosen::RSCanvasNode> pixelMapNode = g_drawingInfo.nodes[PIXEL_MAP_INDEX];
CHKPV(pixelMapNode);
if (g_drawingInfo.filterInfo.shadowEnable) {
SetDragShadow(pixelMapNode);
}
int32_t adjustSize = TWELVE_SIZE * GetScaling();
pixelMapNode->SetBounds(DEFAULT_POSITION_X, adjustSize, pixelMapWidth, pixelMapHeight);
pixelMapNode->SetFrame(DEFAULT_POSITION_X, adjustSize, pixelMapWidth, pixelMapHeight);
@ -2199,8 +2397,18 @@ void DrawPixelMapModifier::Draw(Rosen::RSDrawingContext &context) const
pixelMapNode->SetBgImagePositionY(0);
Rosen::Drawing::AdaptiveImageInfo rsImageInfo = { 1, 0, {}, 1, 0, pixelMapWidth, pixelMapHeight };
auto cvs = pixelMapNode->BeginRecording(pixelMapWidth, pixelMapHeight);
cvs->DrawPixelMapWithParm(g_drawingInfo.pixelMap, rsImageInfo, Rosen::Drawing::SamplingOptions());
CHKPV(cvs);
FilterInfo filterInfo = g_drawingInfo.filterInfo;
if (g_drawingInfo.filterInfo.shadowEnable && !filterInfo.path.empty() &&
g_drawingInfo.filterInfo.dragType == "text") {
auto rsPath = Rosen::RSPath::CreateRSPath(filterInfo.path);
cvs->Save();
cvs->ClipPath(rsPath->GetDrawingPath(), Rosen::Drawing::ClipOp::INTERSECT, true);
cvs->DrawPixelMapWithParm(g_drawingInfo.pixelMap, rsImageInfo, Rosen::Drawing::SamplingOptions());
cvs->Restore();
} else {
cvs->DrawPixelMapWithParm(g_drawingInfo.pixelMap, rsImageInfo, Rosen::Drawing::SamplingOptions());
}
pixelMapNode->SetCornerRadius(filterInfo.cornerRadius * filterInfo.dipScale);
pixelMapNode->SetAlpha(filterInfo.opacity);
pixelMapNode->FinishRecording();

View File

@ -262,11 +262,13 @@ int32_t DragManager::StartDrag(const DragData &dragData, SessionPtr sess)
int32_t DragManager::StopDrag(const DragDropResult &dropResult, const std::string &packageName)
{
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
std::string dragOutPkgName =
(dragOutSession_ == nullptr) ? "Cross-device drag" : dragOutSession_->GetProgramName();
FI_HILOGI("mainWindow:%{public}d, dragResult:%{public}d, drop packageName:%{public}s,"
"drag Out packageName:%{public}s", dropResult.mainWindow, dropResult.result, packageName.c_str(),
dragOutPkgName.c_str());
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
if (dragState_ == DragState::STOP) {
FI_HILOGE("No drag instance running, can not stop drag");
return RET_ERR;
@ -900,7 +902,10 @@ void DragManager::RegisterNotifyPullUp(std::function<void(bool)> callback)
void DragManager::StateChangedNotify(DragState state)
{
FI_HILOGD("enter");
if ((stateChangedCallback_ != nullptr) && (dragState_ != DragState::MOTION_DRAGGING)) {
CHKPV(stateChangedCallback_);
if (state == DragState::STOP) {
stateChangedCallback_(state);
} else if (dragState_ != DragState::MOTION_DRAGGING) {
stateChangedCallback_(state);
}
FI_HILOGD("leave");
@ -957,7 +962,7 @@ int32_t DragManager::HandleDragResult(DragResult result, bool hasCustomAnimation
switch (result) {
case DragResult::DRAG_SUCCESS: {
if (!hasCustomAnimation) {
dragDrawing_.OnDragSuccess();
dragDrawing_.OnDragSuccess(context_);
} else {
dragDrawing_.DestroyDragWindow();
dragDrawing_.UpdateDrawingState();
@ -967,7 +972,7 @@ int32_t DragManager::HandleDragResult(DragResult result, bool hasCustomAnimation
case DragResult::DRAG_FAIL:
case DragResult::DRAG_CANCEL: {
if (!hasCustomAnimation) {
dragDrawing_.OnDragFail();
dragDrawing_.OnDragFail(context_);
} else {
dragDrawing_.DestroyDragWindow();
dragDrawing_.UpdateDrawingState();

View File

@ -353,7 +353,7 @@ std::string DeviceStatusDumper::GetPackageName(Security::AccessToken::AccessToke
}
case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: {
Security::AccessToken::HapTokenInfo hapInfo;
if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) != 0) {
if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) != RET_OK) {
FI_HILOGE("Get hap token info fail");
return packageName;
}

View File

@ -102,6 +102,7 @@ ohos_unittest("DragDataManagerTest") {
]
deps = [
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
"${device_status_service_path}/interaction/drag:interaction_drag",
"${device_status_utils_path}:devicestatus_util",
"//third_party/googletest:gtest_main",

View File

@ -47,7 +47,6 @@ constexpr bool HAS_CANCELED_ANIMATION { true };
constexpr bool DRAG_WINDOW_VISIBLE { true };
constexpr int32_t INT32_BYTE { 4 };
constexpr uint32_t DEFAULT_ICON_COLOR { 0xFF };
constexpr int64_t START_TIME { 181154000809 };
const std::string UD_KEY { "Unified data key" };
}
void DragDataManagerTest::SetUpTestCase() {}
@ -267,7 +266,6 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest007, TestSize.Level0)
ret = dragDrawing.Init(dragData.value());
EXPECT_EQ(ret, INIT_FAIL);
dragDrawing.DestroyDragWindow();
EXPECT_EQ(dragDrawing.startNum_, START_TIME);
dragDrawing.UpdateDragWindowState(!DRAG_WINDOW_VISIBLE);
}
@ -287,7 +285,6 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest008, TestSize.Level0)
int32_t ret = dragDrawing.Init(dragData.value());
EXPECT_EQ(ret, INIT_FAIL);
dragDrawing.DestroyDragWindow();
EXPECT_EQ(dragDrawing.startNum_, START_TIME);
dragDrawing.UpdateDragWindowState(!DRAG_WINDOW_VISIBLE);
}
@ -307,7 +304,6 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest009, TestSize.Level0)
dragDrawing.UpdateDragWindowState(DRAG_WINDOW_VISIBLE);
EXPECT_EQ(ret, INIT_SUCCESS);
dragDrawing.DestroyDragWindow();
EXPECT_EQ(dragDrawing.startNum_, START_TIME);
dragDrawing.EraseMouseIcon();
dragDrawing.UpdateDragWindowState(!DRAG_WINDOW_VISIBLE);
}
@ -328,7 +324,6 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest010, TestSize.Level0)
dragDrawing.UpdateDragWindowState(DRAG_WINDOW_VISIBLE);
EXPECT_EQ(ret, INIT_CANCEL);
dragDrawing.DestroyDragWindow();
EXPECT_EQ(dragDrawing.startNum_, START_TIME);
dragDrawing.UpdateDragWindowState(!DRAG_WINDOW_VISIBLE);
}
@ -351,7 +346,6 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest011, TestSize.Level0)
DragDrawing dragDrawing;
dragDrawing.Draw(pointerEvent->GetTargetDisplayId(), pointerItem.GetDisplayX(), pointerItem.GetDisplayY());
dragDrawing.DestroyDragWindow();
EXPECT_EQ(dragDrawing.startNum_, START_TIME);
}
} // namespace
} // namespace DeviceStatus

View File

@ -39,7 +39,9 @@ ohos_unittest("DragManagerTest") {
deps = [
"${device_status_interfaces_path}/innerkits:devicestatus_client",
"${device_status_root_path}/intention/cooperate/client:intention_cooperate_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/ipc/socket:intention_socket_connection",
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_client",
"${device_status_root_path}/intention/prototype:intention_prototype",

View File

@ -16,8 +16,10 @@
#include <future>
#include "pointer_event.h"
#include "securec.h"
#include "message_parcel.h"
#include "drag_manager_test.h"
#include "drag_params.h"
#include "devicestatus_errors.h"
#include "interaction_manager.h"
@ -1197,6 +1199,235 @@ HWTEST_F(DragManagerTest, DragManagerTest39, TestSize.Level0)
ret = InteractionManager::GetInstance()->UpdatePreviewStyleWithAnimation(previewStyleOut, animationOut);
ASSERT_EQ(ret, RET_ERR);
}
/**
* @tc.name: DragManagerTest40
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest40, TestSize.Level0)
{
CALL_TEST_DEBUG;
int32_t ret = InteractionManager::GetInstance()->EnterTextEditorArea(true);
ASSERT_EQ(ret, RET_ERR);
ret = InteractionManager::GetInstance()->EnterTextEditorArea(false);
ASSERT_EQ(ret, RET_ERR);
}
/**
* @tc.name: DragManagerTest41
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest41, TestSize.Level0)
{
CALL_TEST_DEBUG;
DragAction dragAction { DragAction::INVALID };
int32_t ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
ASSERT_EQ(ret, RET_ERR);
}
/**
* @tc.name: DragManagerTest42
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest42, TestSize.Level0)
{
CALL_TEST_DEBUG;
std::string extraInfo;
int32_t ret = InteractionManager::GetInstance()->GetExtraInfo(extraInfo);
ASSERT_EQ(ret, RET_ERR);
}
/**
* @tc.name: DragManagerTest43
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest43, TestSize.Level0)
{
CALL_TEST_DEBUG;
int32_t ret = InteractionManager::GetInstance()->AddPrivilege();
ASSERT_EQ(ret, RET_ERR);
}
/**
* @tc.name: DragManagerTest44
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest44, TestSize.Level0)
{
CALL_TEST_DEBUG;
MessageParcel data;
StopDragParam param {};
bool ret = param.Unmarshalling(data);
ASSERT_EQ(ret, false);
}
/**
* @tc.name: DragManagerTest45
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest45, TestSize.Level0)
{
CALL_TEST_DEBUG;
MessageParcel data;
SetDragWindowVisibleParam param {};
bool ret = param.Unmarshalling(data);
ASSERT_EQ(ret, false);
}
/**
* @tc.name: DragManagerTest46
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest46, TestSize.Level0)
{
CALL_TEST_DEBUG;
int32_t pid = InteractionManager::GetInstance()->GetDragTargetPid();
MessageParcel data;
GetDragTargetPidReply targetPidReply { pid };
bool ret = targetPidReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest47
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest47, TestSize.Level0)
{
CALL_TEST_DEBUG;
int32_t pid = InteractionManager::GetInstance()->GetDragTargetPid();
MessageParcel data;
GetDragTargetPidReply targetPidReply { pid };
bool ret = targetPidReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest48
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest48, TestSize.Level0)
{
CALL_TEST_DEBUG;
std::string udKey;
MessageParcel data;
GetUdKeyReply udKeyReply { std::move(udKey) };
bool ret = udKeyReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest49
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest49, TestSize.Level0)
{
CALL_TEST_DEBUG;
ShadowOffset shadowOffset {};
MessageParcel data;
GetShadowOffsetReply shadowOffsetReply { shadowOffset };
bool ret = shadowOffsetReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest50
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest50, TestSize.Level0)
{
CALL_TEST_DEBUG;
UpdatePreviewAnimationParam param {};
MessageParcel data;
bool ret = param.Unmarshalling(data);
ASSERT_EQ(ret, false);
}
/**
* @tc.name: DragManagerTest51
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest51, TestSize.Level0)
{
CALL_TEST_DEBUG;
std::map<std::string, int64_t> summaries;
GetDragSummaryReply summaryReply { std::move(summaries) };
MessageParcel data;
bool ret = summaryReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest52
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest52, TestSize.Level0)
{
CALL_TEST_DEBUG;
DragState dragState {};
GetDragStateReply dragStateReply { dragState };
MessageParcel data;
bool ret = dragStateReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest53
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest53, TestSize.Level0)
{
CALL_TEST_DEBUG;
DragAction dragAction {};
GetDragActionReply dragActionReply { dragAction };
MessageParcel data;
bool ret = dragActionReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
/**
* @tc.name: DragManagerTest54
* @tc.desc: Drag Drawing
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DragManagerTest, DragManagerTest54, TestSize.Level0)
{
CALL_TEST_DEBUG;
std::string extraInfo;
GetExtraInfoReply extraInfoReply { std::move(extraInfo) };
MessageParcel data;
bool ret = extraInfoReply.Marshalling(data);
ASSERT_EQ(ret, true);
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -35,6 +35,7 @@
"OHOS::Msdp::DeviceStatus::Utility::GetFileSize(char const*)";
"OHOS::Msdp::DeviceStatus::Utility::GetFileSize(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
"OHOS::Msdp::DeviceStatus::Utility::RemoveSpace(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>&)";
"OHOS::Msdp::DeviceStatus::Utility::CopyNulstr(char*, unsigned long, char const*)";
"OHOS::Msdp::DeviceStatus::Utility::CopyNulstr(char*, unsigned int, char const*)";
"OHOS::Msdp::DeviceStatus::Utility::StartWith(char const*, char const*)";
"OHOS::Msdp::DeviceStatus::Utility::StartWith(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";