• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H
17 #define SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "schedule/system_ability_state_scheduler.h"
23 #include "system_ability_manager.h"
24 
25 namespace OHOS {
26 enum {
27     IPC_STAT_PREFIX_INDEX = 0,
28     IPC_STAT_PROCESS_INDEX = 1,
29     IPC_STAT_CMD_INDEX = 2
30 };
31 
32 constexpr int32_t IPC_STAT_CMD_LEN = 3;
33 
34 class SystemAbilityManagerDumper {
35 public:
36     static bool Dump(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
37         const std::vector<std::string>& args, std::string& result);
38     static bool IpcDumpCmdParser(int32_t& cmd, const std::vector<std::string>& args);
39     static bool IpcDumpIsAllProcess(const std::string& processName);
40     static bool IpcDumpIsSamgr(const std::string& processName);
41     static bool StartSamgrIpcStatistics(std::string& result);
42     static bool StopSamgrIpcStatistics(std::string& result);
43     static bool GetSamgrIpcStatistics(std::string& result);
44     static bool FfrtDumpParser(std::vector<int32_t>& processIds, const std::string& processIdsStr);
45     static int32_t FfrtDumpProc(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
46         int32_t fd, const std::vector<std::string>& args);
47     static bool GetFfrtDumpInfoProc(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
48         const std::vector<std::string>& args, std::string& result);
49     static int32_t ListenerDumpProc(std::map<int32_t, std::list<SAListener>>& listeners,
50         int32_t fd, const std::vector<std::string>& args);
51 
52 private:
53     SystemAbilityManagerDumper() = default;
54     ~SystemAbilityManagerDumper() = default;
55     static bool CanDump();
56     static void ShowHelp(std::string& result);
57     static void ShowAllSystemAbilityInfo(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
58         std::string& result);
59     static void ShowSystemAbilityInfo(int32_t said,
60         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, std::string& result);
61     static void ShowProcessInfo(const std::string& processName,
62         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, std::string& result);
63     static void ShowAllSystemAbilityInfoInState(const std::string& state,
64         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, std::string& result);
65     static void IllegalInput(std::string& result);
66     static void DumpFfrtInfoByProcName(int32_t processId, const std::u16string processName, std::string& result);
67     static int32_t SaveDumpResultToFd(int32_t fd, const std::string& result);
68     static void GetSAMgrFfrtInfo(std::string& result);
69     static void GetListenerDumpProc(std::map<int32_t, std::list<SAListener>>& listeners,
70         const std::vector<std::string>& args, std::string& result);
71     static void ShowAllBySA(std::map<int32_t, std::list<SAListener>>& listeners, std::string& result);
72     static void ShowAllByCallingPid(std::map<int32_t, std::list<SAListener>>& listeners,
73         std::string& result);
74     static void ShowCallingPidBySA(std::map<int32_t, std::list<SAListener>>& listeners,
75         int32_t said, std::string& result);
76     static void ShowSAByCallingPid(std::map<int32_t, std::list<SAListener>>& listeners,
77         int32_t pid, std::string& result);
78     static void ShowListenerHelp(std::string& result);
79 };
80 } // namespace OHOS
81 #endif // SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H