1 /*
2  * Copyright (c) 2022-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 #include "dfx/dms_hisysevent_report.h"
17 
18 #include <string>
19 
20 #include "dtbschedmgr_log.h"
21 #include "hilog/log_cpp.h"
22 #include "hisysevent.h"
23 #include "ipc_skeleton.h"
24 
25 namespace OHOS {
26 namespace DistributedSchedule {
27 using namespace OHOS::HiviewDFX;
28 namespace {
29 const std::string TAG = "DmsHiSysEventReport";
30 constexpr const char*  DOMAIN_NAME = HiSysEvent::Domain::DISTRIBUTED_SCHEDULE;
31 
32 constexpr const char*  KEY_CALLING_APP_UID = "CALLING_APP_UID";
33 constexpr const char*  KEY_CALLING_PID = "CALLING_PID";
34 constexpr const char*  KEY_CALLING_TYPE = "CALLING_TYPE";
35 constexpr const char*  KEY_CALLING_UID = "CALLING_UID";
36 constexpr const char*  KEY_ERROR_TYPE = "ERROR_TYPE";
37 
38 constexpr const char*  KEY_RESULT = "RESULT";
39 constexpr const char*  KEY_CALLEE_ABILITY = "CALLEE_ABILITY";
40 constexpr const char*  KEY_CALLEE_BUNDLE = "CALLEE_BUNDLE";
41 constexpr const char*  KEY_CALLER_BUNDLE = "CALLER_BUNDLE";
42 constexpr const char*  KEY_VERSION = "VERSION";
43 }
44 
ReportBehaviorEvent(const BehaviorEventParam & param)45 int DmsHiSysEventReport::ReportBehaviorEvent(const BehaviorEventParam& param)
46 {
47     int result = HiSysEventWrite(DOMAIN_NAME, param.eventName, HiSysEvent::EventType::BEHAVIOR,
48         KEY_CALLING_TYPE, param.callingType,
49         KEY_CALLING_UID, IPCSkeleton::GetCallingUid(),
50         KEY_CALLING_PID, IPCSkeleton::GetCallingRealPid(),
51         KEY_CALLING_APP_UID, param.callingAppUid,
52         KEY_CALLEE_BUNDLE, param.bundleName,
53         KEY_CALLEE_ABILITY, param.abilityName,
54         KEY_RESULT, param.eventResult,
55         KEY_CALLER_BUNDLE, param.srcBundleName,
56         KEY_VERSION, param.version);
57     if (result != 0) {
58         HILOGE("hisysevent report failed! ret %{public}d.", result);
59     }
60     return result;
61 }
62 
ReportFaultEvent(const std::string & eventName,const std::string & errorType)63 int DmsHiSysEventReport::ReportFaultEvent(const std::string& eventName, const std::string& errorType)
64 {
65     int result = HiSysEventWrite(DOMAIN_NAME, eventName, HiSysEvent::EventType::FAULT,
66         KEY_ERROR_TYPE, errorType);
67     if (result != 0) {
68         HILOGE("hisysevent report failed! ret %{public}d.", result);
69     }
70     return result;
71 }
72 }
73 }