• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <cstring>
17 #include <unistd.h>
18 
19 #include "ability_command.h"
20 #include "xcollie/xcollie.h"
21 #include "xcollie/xcollie_define.h"
22 #ifdef A11Y_ENABLE
23 #include "accessibility_ability_command.h"
24 #endif // A11Y_ENABLE
25 
26 using namespace OHOS;
27 constexpr uint32_t COMMAND_TIME_OUT = 60;
28 
29 class CommandTimer {
30 public:
CommandTimer(const std::string & timerName,uint32_t timeout,const std::string & operation)31     CommandTimer(const std::string &timerName, uint32_t timeout, const std::string &operation)
32     {
33         if (operation != "test") {
34             setTimer_ = true;
35             timerId_ = HiviewDFX::XCollie::GetInstance().SetTimer("ability::aa_command", timeout,
36                 nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG |  HiviewDFX::XCOLLIE_FLAG_RECOVERY);
37         }
38     }
~CommandTimer()39     ~CommandTimer()
40     {
41         if (setTimer_) {
42             HiviewDFX::XCollie::GetInstance().CancelTimer(timerId_);
43         }
44     }
45 private:
46     bool setTimer_ = false;
47     int32_t timerId_ = 0;
48 };
49 
main(int argc,char * argv[])50 int main(int argc, char* argv[])
51 {
52     std::string operation;
53     if (argc > 1) {
54         operation = argv[1];
55     }
56 
57     if (strstr(argv[0], "aa") != nullptr) {
58         CommandTimer commandTimer("ability::aa_command", COMMAND_TIME_OUT, operation);
59         OHOS::AAFwk::AbilityManagerShellCommand cmd(argc, argv);
60         std::cout << cmd.ExecCommand();
61     } else {
62 #ifdef A11Y_ENABLE
63         if (strstr(argv[0], "accessibility") != nullptr) {
64             OHOS::AAFwk::AccessibilityAbilityShellCommand cmd(argc, argv);
65             std::cout << cmd.ExecCommand();
66         }
67 #endif // A11Y_ENABLE
68     }
69     fflush(stdout);
70     _exit(0);
71 }
72