• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hardkey_input.h"
17 #include "input_manager.h"
18 #include "multimode_manager.h"
19 #include "wukong_define.h"
20 #include "report.h"
21 
22 namespace OHOS {
23 namespace WuKong {
24 namespace {
25 const int HARDKEY_COUNT = 2;
26 const int DOWN_TIME = 10;
27 bool g_shouldWakeup = true;
28 }  // namespace
HardkeyInput()29 HardkeyInput::HardkeyInput() : InputAction()
30 {
31     std::shared_ptr<MultimodeInputMsg> multimodeInputMsg = std::make_shared<MultimodeInputMsg>();
32     multimodeInputMsg->inputType_ = INPUTTYPE_HARDKEYINPUT;
33     inputedMsgObject_ = multimodeInputMsg;
34 }
35 
~HardkeyInput()36 HardkeyInput::~HardkeyInput() {}
37 
OrderInput(const std::shared_ptr<SpcialTestObject> & specialTestObject)38 ErrCode HardkeyInput::OrderInput(const std::shared_ptr<SpcialTestObject>& specialTestObject)
39 {
40     auto util = WuKongUtil::GetInstance();
41     if (g_shouldWakeup) {
42         std::string hCmdw = "power-shell wakeup";
43         util->runProcess(hCmdw);
44     } else {
45         std::string hCmds = "power-shell suspend";
46         util->runProcess(hCmds);
47     }
48     g_shouldWakeup = !g_shouldWakeup;
49     return OHOS::ERR_OK;
50 }
51 
RandomInput()52 ErrCode HardkeyInput::RandomInput()
53 {
54     int keycode = MMI::KeyEvent::KEYCODE_VOLUME_UP + rand() % HARDKEY_COUNT;
55     ErrCode result = MultimodeManager::GetInstance()->SingleKeyCodeInput(keycode, DOWN_TIME);
56     Report::GetInstance()->SyncInputInfo(inputedMsgObject_);
57     return result;
58 }
59 
GetInputInfo()60 ErrCode HardkeyInput::GetInputInfo()
61 {
62     return OHOS::ERR_OK;
63 }
64 }  // namespace WuKong
65 }  // namespace OHOS
66