1 /*
2  * Copyright (C) 2023 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 #ifndef EVENT_LOGGER_SHELL_CATCHER
16 #define EVENT_LOGGER_SHELL_CATCHER
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 #include "event_log_catcher.h"
23 #include "sys_event.h"
24 namespace OHOS {
25 namespace HiviewDFX {
26 class ShellCatcher : public EventLogCatcher {
27 public:
28     explicit ShellCatcher();
~ShellCatcher()29     ~ShellCatcher() override {};
30     bool Initialize(const std::string& cmd, int type, int intParam2) override;
31     void SetCmdArgument(const char* arg[], size_t argSize);
32     int Catch(int fd, int jsonFd) override;
33     void SetEvent(std::shared_ptr<SysEvent> event);
34     std::string GetFocusWindowId();
35 
36     enum CATCHER_TYPE {
37         CATCHER_UNKNOWN = -1,
38         CATCHER_CPU,
39         CATCHER_WMS,
40         CATCHER_AMS,
41         CATCHER_PMS,
42         CATCHER_DPMS,
43         CATCHER_RS,
44         CATCHER_MMI,
45         CATCHER_DMS,
46         CATCHER_EEC,
47         CATCHER_GEC,
48         CATCHER_UI,
49         CATCHER_SNAPSHOT,
50         CATCHER_HILOG,
51         CATCHER_TAGHILOG,
52         CATCHER_LIGHT_HILOG,
53         CATCHER_SCBSESSION,
54         CATCHER_SCBVIEWPARAM,
55         CATCHER_SCBWMS,
56         CATCHER_SCBWMSEVT,
57         CATCHER_DAM,
58         CATCHER_INPUT_EVENT_HILOG,
59         CATCHER_INPUT_HILOG,
60     };
61 private:
62     static const inline int32_t DEFAULT_WINDOW_ID = 14;
63     std::string catcherCmd_ = "";
64     std::string focusWindowId_ = "";
65     int pid_ = -1;
66     CATCHER_TYPE catcherType_ = CATCHER_TYPE::CATCHER_UNKNOWN;
67     std::shared_ptr<SysEvent> event_ = nullptr;
68 
69     int DoChildProcesscatcher(int writeFd);
70     int CaDoInChildProcesscatcher(int writeFd);
71     int DoOtherChildProcesscatcher(int writeFd);
72     void DoChildProcess(int writeFd);
73     bool ReadShellToFile(int fd, const std::string& cmd);
74     void ParseFocusWindowId();
75     void GetCpuCoreFreqInfo(int fd) const;
76 };
77 } // namespace HiviewDFX
78 } // namespace OHOS
79 #endif // EVENT_LOGGER_SHELL_CATCHER
80