1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "touch_input.h"
17
18 #include "input_manager.h"
19 #include "multimode_manager.h"
20 #include "wukong_define.h"
21 #include "report.h"
22 namespace OHOS {
23 namespace WuKong {
TouchInput()24 TouchInput::TouchInput() : InputAction()
25 {
26 std::shared_ptr<MultimodeInputMsg> multimodeInputMsg = std::make_shared<MultimodeInputMsg>();
27 multimodeInputMsg->inputType_ = INPUTTYPE_TOUCHINPUT;
28 inputedMsgObject_ = multimodeInputMsg;
29 }
30
~TouchInput()31 TouchInput::~TouchInput()
32 {
33 }
34
OrderInput(const std::shared_ptr<SpcialTestObject> & specialTestObject)35 ErrCode TouchInput::OrderInput(const std::shared_ptr<SpcialTestObject>& specialTestObject)
36 {
37 TouchParam* touchPtr = static_cast<TouchParam*>(specialTestObject.get());
38 if (touchPtr == nullptr) {
39 return OHOS::ERR_INVALID_VALUE;
40 }
41 int touchX = touchPtr->x_;
42 int touchY = touchPtr->y_;
43 auto multiinput = MultimodeManager::GetInstance();
44 ErrCode result = multiinput->PointerInput(touchX, touchY, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN,
45 MMI::PointerEvent::POINTER_ACTION_DOWN);
46 if (result != OHOS::ERR_OK) {
47 return result;
48 }
49 result = multiinput->PointerInput(touchX, touchY, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN,
50 MMI::PointerEvent::POINTER_ACTION_UP);
51 INFO_LOG_STR("Touch: (%d, %d)", touchX, touchY);
52 return result;
53 }
54
RandomInput()55 ErrCode TouchInput::RandomInput()
56 {
57 int32_t screenWidth = -1;
58 int32_t screenHeight = -1;
59 ErrCode result = WuKongUtil::GetInstance()->GetScreenSize(screenWidth, screenHeight);
60 if (result != OHOS::ERR_OK) {
61 return result;
62 }
63 int touchX = rand() % screenWidth;
64 int touchY = rand() % screenHeight;
65 auto multiinput = MultimodeManager::GetInstance();
66 result = multiinput->PointerInput(touchX, touchY, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN,
67 MMI::PointerEvent::POINTER_ACTION_DOWN);
68 if (result != OHOS::ERR_OK) {
69 return result;
70 }
71 result = multiinput->PointerInput(touchX, touchY, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN,
72 MMI::PointerEvent::POINTER_ACTION_UP);
73 if (result != OHOS::ERR_OK) {
74 return result;
75 }
76 Report::GetInstance()->SyncInputInfo(inputedMsgObject_);
77 INFO_LOG_STR("Touch: (%d, %d)", touchX, touchY);
78 return result;
79 }
80
GetInputInfo()81 ErrCode TouchInput::GetInputInfo()
82 {
83 return OHOS::ERR_OK;
84 }
85 } // namespace WuKong
86 } // namespace OHOS
87