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
ReportAddSystemAbilityFailed(int32_t said,const std::string & filaName)34 void ReportAddSystemAbilityFailed(int32_t said, const std::string& filaName)
35 {
36 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
37 ADD_SYSTEMABILITY_FAIL,
38 HiSysEvent::EventType::FAULT,
39 SAID, said,
40 FILE_NAME, filaName);
41 if (ret != 0) {
42 HILOGE("hisysevent report add system ability event failed! ret %{public}d.", ret);
43 }
44 }
45
ReportGetSAFrequency(uint32_t callerUid,uint32_t said,int32_t count)46 void ReportGetSAFrequency(uint32_t callerUid, uint32_t said, int32_t count)
47 {
48 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
49 GETSA__TAG,
50 HiSysEvent::EventType::STATISTIC,
51 CALLER_UID, callerUid,
52 SAID, said,
53 COUNT, count);
54 if (ret != 0) {
55 HILOGE("hisysevent report get sa frequency failed! ret %{public}d.", ret);
56 }
57 }
58
WatchDogSendEvent(int32_t pid,uint32_t uid,const std::string & sendMsg,const std::string & eventName)59 void WatchDogSendEvent(int32_t pid, uint32_t uid, const std::string& sendMsg,
60 const std::string& eventName)
61 {
62 int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR,
63 eventName,
64 HiSysEvent::EventType::FAULT,
65 "PID", pid,
66 "UID", uid,
67 "MSG", sendMsg);
68 if (ret != 0) {
69 HILOGE("hisysevent report watchdog failed! ret %{public}d.", ret);
70 }
71 }
72 } // OHOS
73