1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include <cstring> 17eace7efcSopenharmony_ci#include <unistd.h> 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include "ability_command.h" 20eace7efcSopenharmony_ci#include "ability_tool_command.h" 21eace7efcSopenharmony_ci#include "xcollie/xcollie.h" 22eace7efcSopenharmony_ci#include "xcollie/xcollie_define.h" 23eace7efcSopenharmony_ci#ifdef A11Y_ENABLE 24eace7efcSopenharmony_ci#include "accessibility_ability_command.h" 25eace7efcSopenharmony_ci#endif // A11Y_ENABLE 26eace7efcSopenharmony_ci 27eace7efcSopenharmony_ciusing namespace OHOS; 28eace7efcSopenharmony_ciconstexpr uint32_t COMMAND_TIME_OUT = 60; 29eace7efcSopenharmony_ci 30eace7efcSopenharmony_ciclass CommandTimer { 31eace7efcSopenharmony_cipublic: 32eace7efcSopenharmony_ci CommandTimer(const std::string &timerName, uint32_t timeout, const std::string &operation) 33eace7efcSopenharmony_ci { 34eace7efcSopenharmony_ci if (operation != "test") { 35eace7efcSopenharmony_ci setTimer_ = true; 36eace7efcSopenharmony_ci timerId_ = HiviewDFX::XCollie::GetInstance().SetTimer("ability::aa_command", timeout, 37eace7efcSopenharmony_ci nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG | HiviewDFX::XCOLLIE_FLAG_RECOVERY); 38eace7efcSopenharmony_ci } 39eace7efcSopenharmony_ci } 40eace7efcSopenharmony_ci ~CommandTimer() 41eace7efcSopenharmony_ci { 42eace7efcSopenharmony_ci if (setTimer_) { 43eace7efcSopenharmony_ci HiviewDFX::XCollie::GetInstance().CancelTimer(timerId_); 44eace7efcSopenharmony_ci } 45eace7efcSopenharmony_ci } 46eace7efcSopenharmony_ciprivate: 47eace7efcSopenharmony_ci bool setTimer_ = false; 48eace7efcSopenharmony_ci int32_t timerId_ = 0; 49eace7efcSopenharmony_ci}; 50eace7efcSopenharmony_ci 51eace7efcSopenharmony_ciint main(int argc, char* argv[]) 52eace7efcSopenharmony_ci{ 53eace7efcSopenharmony_ci std::string operation; 54eace7efcSopenharmony_ci if (argc > 1) { 55eace7efcSopenharmony_ci operation = argv[1]; 56eace7efcSopenharmony_ci } 57eace7efcSopenharmony_ci 58eace7efcSopenharmony_ci if (strstr(argv[0], "aa") != nullptr) { 59eace7efcSopenharmony_ci CommandTimer commandTimer("ability::aa_command", COMMAND_TIME_OUT, operation); 60eace7efcSopenharmony_ci OHOS::AAFwk::AbilityManagerShellCommand cmd(argc, argv); 61eace7efcSopenharmony_ci std::cout << cmd.ExecCommand(); 62eace7efcSopenharmony_ci } else if (strstr(argv[0], "ability_tool") != nullptr) { 63eace7efcSopenharmony_ci OHOS::AAFwk::AbilityToolCommand cmd(argc, argv); 64eace7efcSopenharmony_ci std::cout << cmd.ExecCommand(); 65eace7efcSopenharmony_ci } else { 66eace7efcSopenharmony_ci#ifdef A11Y_ENABLE 67eace7efcSopenharmony_ci if (strstr(argv[0], "accessibility") != nullptr) { 68eace7efcSopenharmony_ci OHOS::AAFwk::AccessibilityAbilityShellCommand cmd(argc, argv); 69eace7efcSopenharmony_ci std::cout << cmd.ExecCommand(); 70eace7efcSopenharmony_ci } 71eace7efcSopenharmony_ci#endif // A11Y_ENABLE 72eace7efcSopenharmony_ci } 73eace7efcSopenharmony_ci fflush(stdout); 74eace7efcSopenharmony_ci _exit(0); 75eace7efcSopenharmony_ci} 76