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
22namespace OHOS {
23namespace WuKong {
24namespace {
25const int HARDKEY_COUNT = 2;
26const int DOWN_TIME = 10;
27bool g_shouldWakeup = true;
28}  // namespace
29HardkeyInput::HardkeyInput() : InputAction()
30{
31    std::shared_ptr<MultimodeInputMsg> multimodeInputMsg = std::make_shared<MultimodeInputMsg>();
32    multimodeInputMsg->inputType_ = INPUTTYPE_HARDKEYINPUT;
33    inputedMsgObject_ = multimodeInputMsg;
34}
35
36HardkeyInput::~HardkeyInput() {}
37
38ErrCode 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
52ErrCode 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
60InputType HardkeyInput::GetInputInfo()
61{
62    return INPUTTYPE_HARDKEYINPUT;
63}
64}  // namespace WuKong
65}  // namespace OHOS
66