1 /*
2  * Copyright (C) 2024 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 IPC_STAT_DUMPER_H
16 #define IPC_STAT_DUMPER_H
17 
18 #include "hidumper_executor.h"
19 #include "raw_param.h"
20 #include <iservice_registry.h>
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 class IPCStatDumper : public HidumperExecutor {
25 public:
26     IPCStatDumper();
27     ~IPCStatDumper();
28     DumpStatus PreExecute(const std::shared_ptr<DumperParameter> &parameter, StringMatrix dumpDatas) override;
29     DumpStatus Execute() override;
30     DumpStatus AfterExecute() override;
31     using U16StringVector = std::vector<std::u16string>;
32 
33 private:
34     StringMatrix result_;
35     int pid_ = 0;
36     bool isDumpIpc_ = false;
37     bool isDumpAllIpc_ = false;
38     bool isDumpIpcStartStat_ = false;
39     bool isDumpIpcStopStat_ = false;
40     bool isDumpIpcStat_ = false;
41     std::shared_ptr<RawParam> ptrReqCtl_;
42 
43     U16StringVector ipcDumpCmd_;
44     std::mutex mutex_;
45 
46     void SendErrorMessage(const std::string &errorStr);
47     DumpStatus SetIpcStatCmd(const sptr<ISystemAbilityManager> &sam, sptr<IRemoteObject> &sa);
48     DumpStatus DumpIpcStat(const sptr<ISystemAbilityManager> &sam, sptr<IRemoteObject> &sa);
49     DumpStatus DoDumpIpcStat(sptr<IRemoteObject> &sa);
50     bool CheckPidIsSa(const sptr<ISystemAbilityManager> &sam, std::vector<std::string> &args,
51                       sptr<IRemoteObject> &sa);
52     bool CheckPidIsApp(const sptr<ISystemAbilityManager> &sam, std::vector<std::string> &args,
53                        sptr<IRemoteObject> &sa);
54 };
55 }  // namespace HiviewDFX
56 }  // namespace OHOS
57 #endif  // IPC_STAT_DUMPER_H
58