• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "form_event_hiappevent.h"
17 #include "form_ecological_rule_interface.h"
18 #ifdef NO_RUNTIME_EMULATOR
19 #include "app_event.h"
20 #include "app_event_processor_mgr.h"
21 #endif
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 #ifdef NO_RUNTIME_EMULATOR
26 using namespace OHOS::HiviewDFX;
27 #endif
28 namespace {
29 constexpr int32_t TRIGGER_COND_TIMEOUT = 90;
30 constexpr int32_t TRIGGER_COND_ROW = 30;
31 constexpr int32_t EVENT_RESULT_SUCCESS = 0;
32 constexpr int32_t EVENT_RESULT_FAIL = 1;
33 const std::string SDK_NAME = "FormKit";
34 }
35 
AddProcessor()36 int64_t FormEventHiAppEvent::AddProcessor()
37 {
38 #ifdef NO_RUNTIME_EMULATOR
39     HiAppEvent::ReportConfig config;
40     config.name = "ha_app_event";
41     config.appId = "com_hmos_sdk_ocg";
42     config.routeInfo = "AUTO";
43     config.triggerCond.timeout = TRIGGER_COND_TIMEOUT;
44     config.triggerCond.row = TRIGGER_COND_ROW;
45     config.eventConfigs.clear();
46     {
47         HiAppEvent::EventConfig event1;
48         event1.domain = "api_diagnostic";
49         event1.name = "api_exec_end";
50         event1.isRealTime = false;
51         config.eventConfigs.push_back(event1);
52     }
53     {
54         HiAppEvent::EventConfig event2;
55         event2.domain = "api_diagnostic";
56         event2.name = "api_called_stat";
57         event2.isRealTime = true;
58         config.eventConfigs.push_back(event2);
59     }
60     {
61         HiAppEvent::EventConfig event3;
62         event3.domain = "api_diagnostic";
63         event3.name = "api_called_stat_cnt";
64         event3.isRealTime = true;
65         config.eventConfigs.push_back(event3);
66     }
67     return HiAppEvent::AppEventProcessorMgr::AddProcessor(config);
68 #else
69     return 0;
70 #endif
71 }
72 
WriteAppFormEndEvent(const int errCode,const time_t beginTime,const std::string & apiName,const PublishFormData & publishFormData,const int64_t processorId)73 void FormEventHiAppEvent::WriteAppFormEndEvent(const int errCode, const time_t beginTime,
74     const std::string &apiName, const PublishFormData &publishFormData, const int64_t processorId)
75 {
76 #ifdef NO_RUNTIME_EMULATOR
77     if (processorId <= 0) {
78         HILOG_ERROR("Not an APP process.");
79         return;
80     }
81     std::string transId = "traceId_" + std::to_string(std::rand());
82     HiAppEvent::Event event("api_diagnostic", "api_exec_end", HiAppEvent::BEHAVIOR);
83     int32_t result = (errCode == ERR_OK) ? EVENT_RESULT_SUCCESS : EVENT_RESULT_FAIL;
84     event.AddParam("trans_id", transId);
85     event.AddParam("result", result);
86     event.AddParam("error_code", errCode);
87     event.AddParam("api_name", apiName);
88     event.AddParam("sdk_name", SDK_NAME);
89     event.AddParam("begin_time", beginTime);
90     event.AddParam("end_time", time(nullptr));
91     event.AddParam("bundle_name", publishFormData.bundleName);
92     event.AddParam("ability_name", publishFormData.abilityName);
93     event.AddParam("form_dimension", publishFormData.formDimension);
94     event.AddParam("module_name", publishFormData.moduleName);
95     event.AddParam("form_name", publishFormData.formName);
96     Write(event);
97 #endif
98 }
99 } // namespace AppExecFwk
100 } // namespace OHOS