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 #include "hisysevent_adapter.h"
16
17 #include <string>
18
19 #include "def.h"
20 #include "hisysevent.h"
21 #include "sam_log.h"
22
23 namespace OHOS {
24 using namespace OHOS::HiviewDFX;
25 namespace {
26 const std::string ADD_SYSTEMABILITY_FAIL = "ADD_SYSTEMABILITY_FAIL";
27 const std::string CALLER_UID = "CALLER_UID";
28 const std::string SAID = "SAID";
29 const std::string COUNT = "COUNT";
30 const std::string FILE_NAME = "FILE_NAME";
31 const std::string GETSA__TAG = "GETSA_FREQUENCY";
32
33 const std::string REASON = "REASON";
34 const std::string ONDEMAND_SA_LOAD_FAIL = "ONDEMAND_SA_LOAD_FAIL";
35 const std::string ONDEMAND_SA_LOAD = "ONDEMAND_SA_LOAD";
36 const std::string EVENT = "EVENT";
37 const std::string ONDEMAND_SA_UNLOAD = "ONDEMAND_SA_UNLOAD";
38 }
39
ReportSamgrSaLoadFail(int32_t said,const std::string & reason)40 void ReportSamgrSaLoadFail(int32_t said, const std::string& reason)
41 {
42 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
43 ONDEMAND_SA_LOAD_FAIL,
44 HiSysEvent::EventType::FAULT,
45 SAID, said,
46 REASON, reason);
47 if (ret != 0) {
48 HILOGE("hisysevent report samgr sa load fail event failed! ret %{public}d.", ret);
49 }
50 }
51
ReportSamgrSaLoad(int32_t said,int32_t eventId)52 void ReportSamgrSaLoad(int32_t said, int32_t eventId)
53 {
54 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
55 ONDEMAND_SA_LOAD,
56 HiSysEvent::EventType::BEHAVIOR,
57 SAID, said,
58 EVENT, eventId);
59 if (ret != 0) {
60 HILOGE("hisysevent report samgr sa load event failed! ret %{public}d.", ret);
61 }
62 }
63
ReportSamgrSaUnload(int32_t said,int32_t eventId)64 void ReportSamgrSaUnload(int32_t said, int32_t eventId)
65 {
66 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
67 ONDEMAND_SA_UNLOAD,
68 HiSysEvent::EventType::BEHAVIOR,
69 SAID, said,
70 EVENT, eventId);
71 if (ret != 0) {
72 HILOGE("hisysevent report samgr sa unload event failed! ret %{public}d.", ret);
73 }
74 }
75
ReportAddSystemAbilityFailed(int32_t said,const std::string & filaName)76 void ReportAddSystemAbilityFailed(int32_t said, const std::string& filaName)
77 {
78 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
79 ADD_SYSTEMABILITY_FAIL,
80 HiSysEvent::EventType::FAULT,
81 SAID, said,
82 FILE_NAME, filaName);
83 if (ret != 0) {
84 HILOGE("hisysevent report add system ability event failed! ret %{public}d.", ret);
85 }
86 }
87
ReportGetSAFrequency(uint32_t callerUid,uint32_t said,int32_t count)88 void ReportGetSAFrequency(uint32_t callerUid, uint32_t said, int32_t count)
89 {
90 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
91 GETSA__TAG,
92 HiSysEvent::EventType::STATISTIC,
93 CALLER_UID, callerUid,
94 SAID, said,
95 COUNT, count);
96 if (ret != 0) {
97 HILOGE("hisysevent report get sa frequency failed! ret %{public}d.", ret);
98 }
99 }
100
WatchDogSendEvent(int32_t pid,uint32_t uid,const std::string & sendMsg,const std::string & eventName)101 void WatchDogSendEvent(int32_t pid, uint32_t uid, const std::string& sendMsg,
102 const std::string& eventName)
103 {
104 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
105 eventName,
106 HiSysEvent::EventType::FAULT,
107 "PID", pid,
108 "UID", uid,
109 "MSG", sendMsg);
110 if (ret != 0) {
111 HILOGE("hisysevent report watchdog failed! ret %{public}d.", ret);
112 }
113 }
114 } // OHOS
115