• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #include "napi_hiappevent_processor.h"
16 
17 #include <cinttypes>
18 #include <map>
19 #include <string>
20 #include <unordered_set>
21 
22 #include "app_event_observer_mgr.h"
23 #include "hiappevent_base.h"
24 #include "hiappevent_verify.h"
25 #include "hilog/log.h"
26 #include "napi_error.h"
27 #include "napi_util.h"
28 #include "processor_config_loader.h"
29 
30 #undef LOG_DOMAIN
31 #define LOG_DOMAIN 0xD002D07
32 
33 #undef LOG_TAG
34 #define LOG_TAG "NapiProcessor"
35 
36 namespace OHOS {
37 namespace HiviewDFX {
38 namespace NapiHiAppEventProcessor {
39 namespace {
40 constexpr int ERR_CODE_SUCC = 0;
41 constexpr int ERR_CODE_PARAM_FORMAT = -1;
42 constexpr int ERR_CODE_PARAM_INVALID = -2;
43 
44 const std::string PROCESSOR_NAME = "name";
45 const std::string DEBUG_MODE = "debugMode";
46 const std::string ROUTE_INFO = "routeInfo";
47 const std::string APP_ID = "appId";
48 const std::string START_REPORT = "onStartReport";
49 const std::string BACKGROUND_REPORT = "onBackgroundReport";
50 const std::string PERIOD_REPORT = "periodReport";
51 const std::string BATCH_REPORT = "batchReport";
52 const std::string USER_IDS = "userIds";
53 const std::string USER_PROPERTIES = "userProperties";
54 const std::string EVENT_CONFIGS = "eventConfigs";
55 const std::string EVENT_CONFIG_DOMAIN = "domain";
56 const std::string EVENT_CONFIG_NAME = "name";
57 const std::string EVENT_CONFIG_REALTIME = "isRealTime";
58 const std::string CONFIG_ID = "configId";
59 const std::string CUSTOM_CONFIG = "customConfigs";
60 const std::string CONFIG_NAME = "configName";
61 
62 const std::string CONFIG_PROP_TYPE_STR = "string";
63 const std::string CONFIG_PROP_TYPE_STR_ARRAY = "string array";
64 const std::string CONFIG_PROP_TYPE_BOOL = "boolean";
65 const std::string CONFIG_PROP_TYPE_NUM = "number";
66 const std::string CONFIG_PROP_TYPE_EVENT_CONFIG = "AppEventReportConfig array";
67 const std::string CONFIG_PROP_TYPE_RECORD_STRING = "Record string";
68 }
69 
GenConfigStrProp(const napi_env env,const napi_value config,const std::string & key,std::string & out,const bool optional=true)70 bool GenConfigStrProp(const napi_env env, const napi_value config, const std::string& key, std::string& out,
71     const bool optional = true)
72 {
73     if (!NapiUtil::HasProperty(env, config, key)) {
74         return optional;
75     }
76     napi_value value = NapiUtil::GetProperty(env, config, key);
77     if (value == nullptr || !NapiUtil::IsString(env, value)) {
78         return false;
79     }
80     out = NapiUtil::GetString(env, value);
81     return true;
82 }
83 
GenConfigStrsProp(const napi_env env,const napi_value config,const std::string & key,std::unordered_set<std::string> & out)84 bool GenConfigStrsProp(const napi_env env, const napi_value config, const std::string& key,
85     std::unordered_set<std::string>& out)
86 {
87     if (NapiUtil::HasProperty(env, config, key)) {
88         napi_value value = NapiUtil::GetProperty(env, config, key);
89         if (value == nullptr || !NapiUtil::IsArray(env, value) || !NapiUtil::IsArrayType(env, value, napi_string)) {
90             return false;
91         }
92         NapiUtil::GetStringsToSet(env, value, out);
93     }
94     return true;
95 }
96 
GenConfigBoolProp(const napi_env env,const napi_value config,const std::string & key,bool & out)97 bool GenConfigBoolProp(const napi_env env, const napi_value config, const std::string& key, bool& out)
98 {
99     if (NapiUtil::HasProperty(env, config, key)) {
100         napi_value value = NapiUtil::GetProperty(env, config, key);
101         if (value == nullptr || !NapiUtil::IsBoolean(env, value)) {
102             return false;
103         }
104         out = NapiUtil::GetBoolean(env, value);
105     }
106     return true;
107 }
108 
GenConfigIntProp(const napi_env env,const napi_value config,const std::string & key,int32_t & out)109 bool GenConfigIntProp(const napi_env env, const napi_value config, const std::string& key, int32_t& out)
110 {
111     if (NapiUtil::HasProperty(env, config, key)) {
112         napi_value value = NapiUtil::GetProperty(env, config, key);
113         if (value == nullptr || !NapiUtil::IsNumber(env, value)) {
114             return false;
115         }
116         out = NapiUtil::GetInt32(env, value);
117     }
118     return true;
119 }
120 
GenProcessorNameProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)121 int GenProcessorNameProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
122 {
123     std::string name;
124     if (!GenConfigStrProp(env, config, key, name, false)) {
125         NapiUtil::ThrowError(env, NapiError::ERR_PARAM, NapiUtil::CreateErrMsg(key, CONFIG_PROP_TYPE_STR));
126         return ERR_CODE_PARAM_FORMAT;
127     }
128     if (!IsValidProcessorName(name)) {
129         NapiUtil::ThrowError(env, NapiError::ERR_PARAM, "Invalid processor name.");
130         return ERR_CODE_PARAM_FORMAT;
131     }
132     out.name = name;
133     return ERR_CODE_SUCC;
134 }
135 
GenConfigNameProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)136 int GenConfigNameProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
137 {
138     std::string configName;
139     if (!GenConfigStrProp(env, config, key, configName)) {
140         return ERR_CODE_PARAM_INVALID;
141     }
142     if (!IsValidProcessorName(configName)) {
143         return ERR_CODE_PARAM_INVALID;
144     }
145     out.configName = configName;
146     return ERR_CODE_SUCC;
147 }
148 
GenConfigRouteInfoProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)149 int GenConfigRouteInfoProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
150 {
151     std::string routeInfo;
152     if (!GenConfigStrProp(env, config, key, routeInfo) || !IsValidRouteInfo(routeInfo)) {
153         return ERR_CODE_PARAM_INVALID;
154     }
155     out.routeInfo = routeInfo;
156     return ERR_CODE_SUCC;
157 }
158 
GenConfigAppIdProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)159 int GenConfigAppIdProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
160 {
161     std::string appId;
162     if (!GenConfigStrProp(env, config, key, appId) || !IsValidAppId(appId)) {
163         return ERR_CODE_PARAM_INVALID;
164     }
165     out.appId = appId;
166     return ERR_CODE_SUCC;
167 }
168 
GenConfigUserIdsProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)169 int GenConfigUserIdsProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
170 {
171     std::unordered_set<std::string> userIdNames;
172     if (!GenConfigStrsProp(env, config, key, userIdNames)) {
173         return ERR_CODE_PARAM_INVALID;
174     }
175     for (auto userId : userIdNames) {
176         if (!IsValidUserIdName(userId)) {
177             return ERR_CODE_PARAM_INVALID;
178         }
179     }
180     out.userIdNames = userIdNames;
181     return ERR_CODE_SUCC;
182 }
183 
GenConfigUserPropertiesProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)184 int GenConfigUserPropertiesProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
185 {
186     std::unordered_set<std::string> userPropertyNames;
187     if (!GenConfigStrsProp(env, config, key, userPropertyNames)) {
188         return ERR_CODE_PARAM_INVALID;
189     }
190     for (auto userProperty : userPropertyNames) {
191         if (!IsValidUserPropName(userProperty)) {
192             return ERR_CODE_PARAM_INVALID;
193         }
194     }
195     out.userPropertyNames = userPropertyNames;
196     return ERR_CODE_SUCC;
197 }
198 
GenConfigDebugModeProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)199 int GenConfigDebugModeProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
200 {
201     return GenConfigBoolProp(env, config, key, out.debugMode) ? ERR_CODE_SUCC : ERR_CODE_PARAM_INVALID;
202 }
203 
GenConfigStartReportProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)204 int GenConfigStartReportProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
205 {
206     return GenConfigBoolProp(env, config, key, out.triggerCond.onStartup) ? ERR_CODE_SUCC : ERR_CODE_PARAM_INVALID;
207 }
208 
GenConfigBackgroundReportProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)209 int GenConfigBackgroundReportProp(const napi_env env, const napi_value config, const std::string& key,
210     ReportConfig& out)
211 {
212     return GenConfigBoolProp(env, config, key, out.triggerCond.onBackground) ? ERR_CODE_SUCC : ERR_CODE_PARAM_INVALID;
213 }
214 
GenConfigPeriodReportProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)215 int GenConfigPeriodReportProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
216 {
217     int timeout = 0;
218     if (!GenConfigIntProp(env, config, key, timeout) || !IsValidPeriodReport(timeout)) {
219         return ERR_CODE_PARAM_INVALID;
220     }
221     out.triggerCond.timeout = timeout;
222     return ERR_CODE_SUCC;
223 }
224 
GenConfigBatchReportProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)225 int GenConfigBatchReportProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
226 {
227     int row = 0;
228     if (!GenConfigIntProp(env, config, key, row) || !IsValidBatchReport(row)) {
229         return ERR_CODE_PARAM_INVALID;
230     }
231     out.triggerCond.row = row;
232     return ERR_CODE_SUCC;
233 }
234 
GenConfigReportProp(const napi_env env,const napi_value config,HiAppEvent::EventConfig & out)235 int GenConfigReportProp(const napi_env env, const napi_value config, HiAppEvent::EventConfig& out)
236 {
237     HiAppEvent::EventConfig reportConf;
238     if (!GenConfigStrProp(env, config, EVENT_CONFIG_DOMAIN, reportConf.domain)) {
239         HILOG_WARN(LOG_CORE, "Parameter error. The event domain parameter is invalid.");
240         return ERR_CODE_PARAM_INVALID;
241     }
242     if (!GenConfigStrProp(env, config, EVENT_CONFIG_NAME, reportConf.name)) {
243         HILOG_WARN(LOG_CORE, "Parameter error. The event name parameter is invalid.");
244         return ERR_CODE_PARAM_INVALID;
245     }
246     if (!GenConfigBoolProp(env, config, EVENT_CONFIG_REALTIME, reportConf.isRealTime)) {
247         HILOG_WARN(LOG_CORE, "Parameter error. The event isRealTime parameter is invalid.");
248         return ERR_CODE_PARAM_INVALID;
249     }
250     if (!IsValidEventConfig(reportConf)) {
251         HILOG_WARN(LOG_CORE, "Parameter error. The event config is invalid, domain=%{public}s, name=%{public}s.",
252             reportConf.domain.c_str(), reportConf.name.c_str());
253         return ERR_CODE_PARAM_INVALID;
254     }
255     out = reportConf;
256     return ERR_CODE_SUCC;
257 }
258 
GenConfigEventConfigsProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)259 int GenConfigEventConfigsProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
260 {
261     if (NapiUtil::HasProperty(env, config, key)) {
262         napi_value napiArr = NapiUtil::GetProperty(env, config, key);
263         if (!NapiUtil::IsArray(env, napiArr)) {
264             return ERR_CODE_PARAM_INVALID;
265         }
266         std::vector<HiAppEvent::EventConfig> eventConfigs;
267         uint32_t length = NapiUtil::GetArrayLength(env, napiArr);
268         for (uint32_t i = 0; i < length; i++) {
269             napi_value element = NapiUtil::GetElement(env, napiArr, i);
270             HiAppEvent::EventConfig reportConf;
271             int ret = GenConfigReportProp(env, element, reportConf);
272             if (ret != ERR_CODE_SUCC) {
273                 return ret;
274             }
275             eventConfigs.push_back(reportConf);
276         }
277         out.eventConfigs = eventConfigs;
278     }
279     return ERR_CODE_SUCC;
280 }
281 
GenConfigIdProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)282 int GenConfigIdProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
283 {
284     int configId = 0;
285     if (!GenConfigIntProp(env, config, key, configId) || !IsValidConfigId(configId)) {
286         HILOG_WARN(LOG_CORE, "invalid configId");
287         return ERR_CODE_PARAM_INVALID;
288     }
289     out.configId = configId;
290     return ERR_CODE_SUCC;
291 }
292 
GenConfigCustomConfigsProp(const napi_env env,const napi_value config,const std::string & key,ReportConfig & out)293 int GenConfigCustomConfigsProp(const napi_env env, const napi_value config, const std::string& key, ReportConfig& out)
294 {
295     if (!NapiUtil::HasProperty(env, config, key)) {
296         return ERR_CODE_SUCC;
297     }
298     napi_value napiObject = NapiUtil::GetProperty(env, config, key);
299     if (napiObject == nullptr || !NapiUtil::IsObject(env, napiObject)) {
300         HILOG_WARN(LOG_CORE, "invalid customConfigs");
301         return ERR_CODE_PARAM_INVALID;
302     }
303     std::vector<std::string> keys;
304     NapiUtil::GetPropertyNames(env, napiObject, keys);
305     if (!IsValidCustomConfigsNum(keys.size())) {
306         HILOG_WARN(LOG_CORE, "invalid keys size=%{public}zu", keys.size());
307         return ERR_CODE_PARAM_INVALID;
308     }
309     std::unordered_map<std::string, std::string> customConfigs;
310     for (const auto& localKey : keys) {
311         std::string value;
312         if (!GenConfigStrProp(env, napiObject, localKey, value) || !IsValidCustomConfig(localKey, value)) {
313             HILOG_WARN(LOG_CORE, "invalid key");
314             return ERR_CODE_PARAM_INVALID;
315         }
316         customConfigs.insert(std::pair<std::string, std::string>(localKey, value));
317     }
318     out.customConfigs = customConfigs;
319     return ERR_CODE_SUCC;
320 }
321 
322 typedef struct ConfigProp {
323     std::string type;
324     std::string key;
325     int (*func)(const napi_env, const napi_value, const std::string&, ReportConfig&);
326 } ConfigProp;
327 
328 const ConfigProp CONFIG_PROPS[] = {
329     {
330         .type = CONFIG_PROP_TYPE_STR,
331         .key = PROCESSOR_NAME,
332         .func = GenProcessorNameProp
333     },
334     {
335         .type = CONFIG_PROP_TYPE_STR,
336         .key = ROUTE_INFO,
337         .func = GenConfigRouteInfoProp
338     },
339     {
340         .type = CONFIG_PROP_TYPE_STR,
341         .key = APP_ID,
342         .func = GenConfigAppIdProp
343     },
344     {
345         .type = CONFIG_PROP_TYPE_STR,
346         .key = CONFIG_NAME,
347         .func = GenConfigNameProp
348     },
349     {
350         .type = CONFIG_PROP_TYPE_STR_ARRAY,
351         .key = USER_IDS,
352         .func = GenConfigUserIdsProp
353     },
354     {
355         .type = CONFIG_PROP_TYPE_STR_ARRAY,
356         .key = USER_PROPERTIES,
357         .func = GenConfigUserPropertiesProp
358     },
359     {
360         .type = CONFIG_PROP_TYPE_BOOL,
361         .key = DEBUG_MODE,
362         .func = GenConfigDebugModeProp
363     },
364     {
365         .type = CONFIG_PROP_TYPE_BOOL,
366         .key = START_REPORT,
367         .func = GenConfigStartReportProp
368     },
369     {
370         .type = CONFIG_PROP_TYPE_BOOL,
371         .key = BACKGROUND_REPORT,
372         .func = GenConfigBackgroundReportProp
373     },
374     {
375         .type = CONFIG_PROP_TYPE_NUM,
376         .key = PERIOD_REPORT,
377         .func = GenConfigPeriodReportProp
378     },
379     {
380         .type = CONFIG_PROP_TYPE_NUM,
381         .key = BATCH_REPORT,
382         .func = GenConfigBatchReportProp
383     },
384     {
385         .type = CONFIG_PROP_TYPE_EVENT_CONFIG,
386         .key = EVENT_CONFIGS,
387         .func = GenConfigEventConfigsProp
388     },
389     {
390         .type = CONFIG_PROP_TYPE_NUM,
391         .key = CONFIG_ID,
392         .func = GenConfigIdProp
393     },
394     {
395         .type = CONFIG_PROP_TYPE_RECORD_STRING,
396         .key = CUSTOM_CONFIG,
397         .func = GenConfigCustomConfigsProp
398     }
399 };
400 
TransConfig(const napi_env env,const napi_value config,ReportConfig & out)401 int TransConfig(const napi_env env, const napi_value config, ReportConfig& out)
402 {
403     if (!NapiUtil::IsObject(env, config)) {
404         HILOG_ERROR(LOG_CORE, "failed to add processor, params format error");
405         NapiUtil::ThrowError(env, NapiError::ERR_PARAM, NapiUtil::CreateErrMsg("config", "Processor"));
406         return -1;
407     }
408     for (auto prop : CONFIG_PROPS) {
409         int ret = (prop.func)(env, config, prop.key, out);
410         if (ret == ERR_CODE_PARAM_FORMAT) {
411             HILOG_ERROR(LOG_CORE, "failed to add processor, params format error");
412             return -1;
413         } else if (ret == ERR_CODE_PARAM_INVALID) {
414             HILOG_WARN(LOG_CORE, "Parameter error. The %{public}s parameter is invalid.", prop.key.c_str());
415         }
416     }
417     return 0;
418 }
419 
AddProcessorAsync(const std::string & processorName,const std::string & configName)420 int64_t AddProcessorAsync(const std::string& processorName, const std::string& configName)
421 {
422     if (!IsValidProcessorName(processorName)) {
423         HILOG_ERROR(LOG_CORE, "Invalid processor name.");
424         return ERR_CODE_PARAM_INVALID;
425     }
426     if (!IsValidProcessorName(configName)) {
427         HILOG_ERROR(LOG_CORE, "Invalid configName name.");
428         return ERR_CODE_PARAM_INVALID;
429     }
430 
431     if (AppEventObserverMgr::GetInstance().Load(processorName) != 0) {
432         HILOG_ERROR(LOG_CORE, "failed to add processor=%{public}s, name not found", processorName.c_str());
433         return ERR_CODE_PARAM_INVALID;
434     }
435 
436     HiAppEvent::ProcessorConfigLoader loader;
437     if (!loader.LoadProcessorConfig(processorName, configName)) {
438         HILOG_ERROR(LOG_CORE, "failed to load config content, configName:%{public}s", configName.c_str());
439         return ERR_CODE_PARAM_INVALID;
440     }
441 
442     ReportConfig conf = loader.GetReportConfig();
443     int64_t processorId = AppEventObserverMgr::GetInstance().AddProcessor(processorName, conf);
444     if (processorId <= 0) {
445         HILOG_ERROR(LOG_CORE, "failed to add processor=%{public}s, register processor error", processorName.c_str());
446         return ERR_CODE_PARAM_INVALID;
447     }
448     return processorId;
449 }
450 
AddProcessor(const napi_env env,const napi_value config,napi_value & out)451 bool AddProcessor(const napi_env env, const napi_value config, napi_value& out)
452 {
453     ReportConfig conf;
454     int ret = TransConfig(env, config, conf);
455     if (ret != 0) {
456         out = NapiUtil::CreateInt64(env, -1);
457         return false;
458     }
459     std::string name = conf.name;
460     if (name.empty()) {
461         HILOG_ERROR(LOG_CORE, "processor name can not be empty.");
462         out = NapiUtil::CreateInt64(env, -1);
463         return false;
464     }
465     if (AppEventObserverMgr::GetInstance().Load(name) != 0) {
466         HILOG_WARN(LOG_CORE, "failed to add processor=%{public}s, name no found", name.c_str());
467         out = NapiUtil::CreateInt64(env, -1);
468         return true;
469     }
470     if (!conf.configName.empty()) {
471         HiAppEvent::ProcessorConfigLoader loader;
472         if (loader.LoadProcessorConfig(conf.name, conf.configName)) {
473             conf = loader.GetReportConfig();
474         } else {
475             HILOG_WARN(LOG_CORE, "failed to load config content, configName:%{public}s", conf.configName.c_str());
476         }
477     }
478     int64_t processorId = AppEventObserverMgr::GetInstance().AddProcessor(name, conf);
479     if (processorId <= 0) {
480         HILOG_WARN(LOG_CORE, "failed to add processor=%{public}s, register processor error", name.c_str());
481         out = NapiUtil::CreateInt64(env, -1);
482         return false;
483     }
484     out = NapiUtil::CreateInt64(env, processorId);
485     return true;
486 }
487 
AddProcessorFromConfig(const napi_env env,AddProcessorFromConfigAsyncContext * asyncContext)488 void AddProcessorFromConfig(const napi_env env, AddProcessorFromConfigAsyncContext* asyncContext)
489 {
490     napi_value resource = NapiUtil::CreateString(env, "NapiHiAppEventAddProcessorFromConfig");
491     napi_create_async_work(env, nullptr, resource,
492         [](napi_env env, void* data) {
493             AddProcessorFromConfigAsyncContext* asyncContext = (AddProcessorFromConfigAsyncContext*)data;
494             asyncContext->result = AddProcessorAsync(asyncContext->processorName, asyncContext->configName);
495         },
496         [](napi_env env, napi_status status, void* data) {
497             AddProcessorFromConfigAsyncContext* asyncContext = (AddProcessorFromConfigAsyncContext*)data;
498             napi_value result = nullptr;
499             if (asyncContext != nullptr && asyncContext->deferred != nullptr) { // promise
500                 if (asyncContext->result > 0) {
501                     result = NapiUtil::CreateInt64(env, asyncContext->result);
502                     napi_resolve_deferred(env, asyncContext->deferred, result);
503                 } else {
504                     std::string ErrMsg = "Invalid param value for add processor from config.";
505                     result = NapiUtil::CreateError(env, NapiError::ERR_INVALID_PARAM_VALUE, ErrMsg);
506                     napi_reject_deferred(env, asyncContext->deferred, result);
507                 }
508             }
509             napi_delete_async_work(env, asyncContext->asyncWork);
510             delete asyncContext;
511         },
512         (void*)asyncContext, &asyncContext->asyncWork);
513     napi_queue_async_work_with_qos(env, asyncContext->asyncWork, napi_qos_default);
514 }
515 
RemoveProcessor(const napi_env env,const napi_value id)516 bool RemoveProcessor(const napi_env env, const napi_value id)
517 {
518     if (!NapiUtil::IsNumber(env, id)) {
519         HILOG_WARN(LOG_CORE, "failed to remove processor, params format error");
520         NapiUtil::ThrowError(env, NapiError::ERR_PARAM, NapiUtil::CreateErrMsg("id", "number"));
521         return false;
522     }
523     int64_t processorId = NapiUtil::GetInt64(env, id);
524     if (processorId <= 0) {
525         HILOG_ERROR(LOG_CORE, "failed to remove processor id=%{public}" PRId64, processorId);
526         return true;
527     }
528     if (AppEventObserverMgr::GetInstance().RemoveObserver(processorId) != 0) {
529         HILOG_WARN(LOG_CORE, "failed to remove processor id=%{public}" PRId64, processorId);
530         return false;
531     }
532     return true;
533 }
534 } // namespace NapiHiAppEventProcessor
535 } // namespace HiviewDFX
536 } // namespace OHOS
537