1020a203aSopenharmony_ci/* 2020a203aSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3020a203aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4020a203aSopenharmony_ci * you may not use this file except in compliance with the License. 5020a203aSopenharmony_ci * You may obtain a copy of the License at 6020a203aSopenharmony_ci * 7020a203aSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8020a203aSopenharmony_ci * 9020a203aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10020a203aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11020a203aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12020a203aSopenharmony_ci * See the License for the specific language governing permissions and 13020a203aSopenharmony_ci * limitations under the License. 14020a203aSopenharmony_ci */ 15020a203aSopenharmony_ci#ifndef EVENT_LOGGER_SHELL_CATCHER 16020a203aSopenharmony_ci#define EVENT_LOGGER_SHELL_CATCHER 17020a203aSopenharmony_ci 18020a203aSopenharmony_ci#include <map> 19020a203aSopenharmony_ci#include <string> 20020a203aSopenharmony_ci#include <vector> 21020a203aSopenharmony_ci 22020a203aSopenharmony_ci#include "event_log_catcher.h" 23020a203aSopenharmony_ci#include "sys_event.h" 24020a203aSopenharmony_cinamespace OHOS { 25020a203aSopenharmony_cinamespace HiviewDFX { 26020a203aSopenharmony_ciclass ShellCatcher : public EventLogCatcher { 27020a203aSopenharmony_cipublic: 28020a203aSopenharmony_ci explicit ShellCatcher(); 29020a203aSopenharmony_ci ~ShellCatcher() override {}; 30020a203aSopenharmony_ci bool Initialize(const std::string& cmd, int type, int intParam2) override; 31020a203aSopenharmony_ci void SetCmdArgument(const char* arg[], size_t argSize); 32020a203aSopenharmony_ci int Catch(int fd, int jsonFd) override; 33020a203aSopenharmony_ci void SetEvent(std::shared_ptr<SysEvent> event); 34020a203aSopenharmony_ci void SetFocusWindowId(const std::string& focusWindowId); 35020a203aSopenharmony_ci 36020a203aSopenharmony_ci enum CATCHER_TYPE { 37020a203aSopenharmony_ci CATCHER_UNKNOWN = -1, 38020a203aSopenharmony_ci CATCHER_CPU, 39020a203aSopenharmony_ci CATCHER_WMS, 40020a203aSopenharmony_ci CATCHER_AMS, 41020a203aSopenharmony_ci CATCHER_PMS, 42020a203aSopenharmony_ci CATCHER_DPMS, 43020a203aSopenharmony_ci CATCHER_RS, 44020a203aSopenharmony_ci CATCHER_MMI, 45020a203aSopenharmony_ci CATCHER_DMS, 46020a203aSopenharmony_ci CATCHER_EEC, 47020a203aSopenharmony_ci CATCHER_GEC, 48020a203aSopenharmony_ci CATCHER_UI, 49020a203aSopenharmony_ci CATCHER_SNAPSHOT, 50020a203aSopenharmony_ci CATCHER_HILOG, 51020a203aSopenharmony_ci CATCHER_LIGHT_HILOG, 52020a203aSopenharmony_ci CATCHER_SCBSESSION, 53020a203aSopenharmony_ci CATCHER_SCBVIEWPARAM, 54020a203aSopenharmony_ci CATCHER_SCBWMS, 55020a203aSopenharmony_ci CATCHER_SCBWMSEVT, 56020a203aSopenharmony_ci CATCHER_DAM, 57020a203aSopenharmony_ci CATCHER_INPUT_EVENT_HILOG, 58020a203aSopenharmony_ci CATCHER_INPUT_HILOG, 59020a203aSopenharmony_ci }; 60020a203aSopenharmony_ciprivate: 61020a203aSopenharmony_ci static const inline int32_t DEFAULT_WINDOW_ID = 14; 62020a203aSopenharmony_ci std::string catcherCmd_ = ""; 63020a203aSopenharmony_ci std::string focusWindowId_ = ""; 64020a203aSopenharmony_ci int pid_ = -1; 65020a203aSopenharmony_ci CATCHER_TYPE catcherType_ = CATCHER_TYPE::CATCHER_UNKNOWN; 66020a203aSopenharmony_ci std::shared_ptr<SysEvent> event_ = nullptr; 67020a203aSopenharmony_ci 68020a203aSopenharmony_ci int DoChildProcesscatcher(int writeFd); 69020a203aSopenharmony_ci int CaDoInChildProcesscatcher(int writeFd); 70020a203aSopenharmony_ci void DoChildProcess(int writeFd); 71020a203aSopenharmony_ci bool ReadShellToFile(int fd, const std::string& cmd); 72020a203aSopenharmony_ci}; 73020a203aSopenharmony_ci} // namespace HiviewDFX 74020a203aSopenharmony_ci} // namespace OHOS 75020a203aSopenharmony_ci#endif // EVENT_LOGGER_SHELL_CATCHER 76