1 /*
2  * Copyright (c) 2022 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 HIVIEWDFX_FREEZE_COMMON_H
17 #define HIVIEWDFX_FREEZE_COMMON_H
18 
19 #include <list>
20 #include <memory>
21 #include <set>
22 #include <vector>
23 
24 #include "rule_cluster.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 const std::string FREEZE_DETECTOR_PLUGIN_NAME = "FreezeDetector";
29 const std::string FREEZE_DETECTOR_PLUGIN_VERSION = "1.0";
30 class FreezeCommon {
31 public:
32     static constexpr const char* const EVENT_PID = "PID";
33     static constexpr const char* const EVENT_UID = "UID";
34     static constexpr const char* const EVENT_PACKAGE_NAME = "PACKAGE_NAME";
35     static constexpr const char* const EVENT_PROCESS_NAME = "PROCESS_NAME";
36     static constexpr const char* const HIREACE_TIME = "HITRACE_TIME";
37     static constexpr const char* const SYSRQ_TIME = "SYSRQ_TIME";
38 
39     FreezeCommon();
40     ~FreezeCommon();
41 
42     bool Init();
43     bool IsFreezeEvent(const std::string& domain, const std::string& stringId) const;
44     bool IsApplicationEvent(const std::string& domain, const std::string& stringId) const;
45     bool IsBetaVersion() const;
46     bool IsSystemEvent(const std::string& domain, const std::string& stringId) const;
47     bool IsSysWarningEvent(const std::string& domain, const std::string& stringId) const;
48     bool IsSystemResult(const FreezeResult& result) const;
49     bool IsSysWarningResult(const FreezeResult& result) const;
50     bool IsApplicationResult(const FreezeResult& result) const;
51     std::set<std::string> GetPrincipalStringIds() const;
52     std::shared_ptr<FreezeRuleCluster> GetFreezeRuleCluster() const;
53 
54 private:
55     std::shared_ptr<FreezeRuleCluster> freezeRuleCluster_;
56     bool IsAssignedEvent(const std::string& domain, const std::string& stringId, int freezeId) const;
57 };
58 }  // namespace HiviewDFX
59 }  // namespace OHOS
60 #endif // HIVIEWDFX_FREEZE_COMMON_H