1 /*
2 * Copyright (c) 2024 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 <cinttypes>
17
18 #include "ndk_app_event_processor.h"
19
20 #include "app_event_observer_mgr.h"
21 #include "hiappevent_verify.h"
22 #include "hilog/log.h"
23
24 #undef LOG_DOMAIN
25 #define LOG_DOMAIN 0xD002D07
26
27 #undef LOG_TAG
28 #define LOG_TAG "NdkProcessor"
29
30 namespace OHOS {
31 namespace HiviewDFX {
32 namespace {
33 constexpr int CODE_SUCC = 0;
34 constexpr int CODE_FAILED = -1;
35 }
36
NdkAppEventProcessor(const std::string & name)37 NdkAppEventProcessor::NdkAppEventProcessor(const std::string &name)
38 {
39 config_.name = name;
40 }
41
SetReportRoute(const char * appId,const char * routeInfo)42 int NdkAppEventProcessor::SetReportRoute(const char* appId, const char* routeInfo)
43 {
44 config_.appId = appId;
45 config_.routeInfo = routeInfo;
46 return CODE_SUCC;
47 }
48
SetReportPolicy(int periodReport,int batchReport,bool onStartReport,bool onBackgroundReport)49 int NdkAppEventProcessor::SetReportPolicy(int periodReport, int batchReport, bool onStartReport,
50 bool onBackgroundReport)
51 {
52 config_.triggerCond.timeout = periodReport;
53 config_.triggerCond.row = batchReport;
54 config_.triggerCond.onStartup = onStartReport;
55 config_.triggerCond.onBackground = onBackgroundReport;
56 return CODE_SUCC;
57 }
58
SetReportEvent(const char * domain,const char * name,bool isRealTime)59 int NdkAppEventProcessor::SetReportEvent(const char* domain, const char* name, bool isRealTime)
60 {
61 EventConfig event;
62 event.domain = domain;
63 event.name = name;
64 event.isRealTime = isRealTime;
65 config_.eventConfigs.emplace_back(event);
66 return CODE_SUCC;
67 }
68
SetCustomConfig(const char * key,const char * value)69 int NdkAppEventProcessor::SetCustomConfig(const char* key, const char* value)
70 {
71 auto it = config_.customConfigs.find(key);
72 if (it != config_.customConfigs.end()) {
73 config_.customConfigs.erase(it);
74 }
75 config_.customConfigs.insert(std::pair<std::string, std::string>(key, value));
76 return CODE_SUCC;
77 }
78
SetConfigId(int configId)79 int NdkAppEventProcessor::SetConfigId(int configId)
80 {
81 config_.configId = configId;
82 return CODE_SUCC;
83 }
84
SetReportUserId(const char * const * userIdNames,int size)85 int NdkAppEventProcessor::SetReportUserId(const char* const * userIdNames, int size)
86 {
87 for (int i = 0; i < size; ++i) {
88 config_.userIdNames.emplace(userIdNames[i]);
89 }
90 return CODE_SUCC;
91 }
92
SetReportUserProperty(const char * const * userPropertyNames,int size)93 int NdkAppEventProcessor::SetReportUserProperty(const char* const * userPropertyNames, int size)
94 {
95 for (int i = 0; i < size; ++i) {
96 config_.userPropertyNames.emplace(userPropertyNames[i]);
97 }
98 return CODE_SUCC;
99 }
100
GetConfig()101 HiAppEvent::ReportConfig NdkAppEventProcessor::GetConfig()
102 {
103 return config_;
104 }
105 }
106 }