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 #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_TARGET_ABILITY = "TARGET_ABILITY";
40 constexpr const char* KEY_TARGET_BUNDLE = "TARGET_BUNDLE";
41 }
42
ReportBehaviorEvent(const BehaviorEventParam & param)43 int DmsHiSysEventReport::ReportBehaviorEvent(const BehaviorEventParam& param)
44 {
45 int result = HiSysEvent::Write(DOMAIN_NAME, param.eventName, HiSysEvent::EventType::BEHAVIOR,
46 KEY_CALLING_TYPE, param.callingType,
47 KEY_CALLING_UID, IPCSkeleton::GetCallingUid(),
48 KEY_CALLING_PID, IPCSkeleton::GetCallingPid(),
49 KEY_CALLING_APP_UID, param.callingAppUid,
50 KEY_TARGET_BUNDLE, param.bundleName,
51 KEY_TARGET_ABILITY, param.abilityName,
52 KEY_RESULT, param.eventResult);
53 if (result != 0) {
54 HILOGE("hisysevent report failed! ret %{public}d.", result);
55 }
56 return result;
57 }
58
ReportFaultEvent(const std::string & eventName,const std::string & errorType)59 int DmsHiSysEventReport::ReportFaultEvent(const std::string& eventName, const std::string& errorType)
60 {
61 int result = HiSysEvent::Write(DOMAIN_NAME, eventName, HiSysEvent::EventType::FAULT,
62 KEY_ERROR_TYPE, errorType);
63 if (result != 0) {
64 HILOGE("hisysevent report failed! ret %{public}d.", result);
65 }
66 return result;
67 }
68 }
69 }