diff --git a/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp b/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp index 285c4248377e108f6902887572ac3a78070d8be3..00805bf03fa2adc7285e1cb183d32408cd5587ad 100644 --- a/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp +++ b/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp @@ -57,48 +57,6 @@ void LocalLiveViewSubscriberInstance::OnDisconnected() ANS_LOGD("enter"); } -void UvQueueWorkOnResponse(uv_work_t *work, int status) -{ - ANS_LOGI("OnResponse uv_work_t start"); - - if (work == nullptr) { - ANS_LOGE("work is nullptr"); - return; - } - - auto dataWorkerData = reinterpret_cast(work->data); - if (dataWorkerData == nullptr) { - ANS_LOGD("dataWorkerData is null."); - delete work; - work = nullptr; - return; - } - napi_value buttonOption = nullptr; - napi_value buttonName = nullptr; - napi_handle_scope scope; - napi_value notificationId = nullptr; - napi_open_handle_scope(dataWorkerData->env, &scope); - if (scope == nullptr) { - ANS_LOGE("Scope is null"); - return; - } - - // notificationId: number - napi_create_int32(dataWorkerData->env, dataWorkerData->notificationId, ¬ificationId); - - napi_create_object(dataWorkerData->env, &buttonOption); - napi_create_string_utf8(dataWorkerData->env, dataWorkerData->buttonOption->GetButtonName().c_str(), - NAPI_AUTO_LENGTH, &buttonName); - napi_set_named_property(dataWorkerData->env, buttonOption, "buttonName", buttonName); - - Common::SetCallbackArg2(dataWorkerData->env, dataWorkerData->ref, notificationId, buttonOption); - napi_close_handle_scope(dataWorkerData->env, scope); - - delete dataWorkerData; - dataWorkerData = nullptr; - delete work; -} - void LocalLiveViewSubscriberInstance::OnResponse(int32_t notificationId, sptr buttonOption) { ANS_LOGD("enter"); @@ -116,13 +74,6 @@ void LocalLiveViewSubscriberInstance::OnResponse(int32_t notificationId, sptrGetButtonName().c_str()); - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(responseCallbackInfo_.env, &loop); - if (loop == nullptr) { - ANS_LOGE("loop instance is nullptr"); - return; - } - LocalLiveViewReceiveDataWorker *dataWorker = new (std::nothrow) LocalLiveViewReceiveDataWorker(); if (dataWorker == nullptr) { ANS_LOGE("DataWorker is nullptr."); @@ -134,23 +85,41 @@ void LocalLiveViewSubscriberInstance::OnResponse(int32_t notificationId, sptrenv = responseCallbackInfo_.env; dataWorker->ref = responseCallbackInfo_.ref; - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - ANS_LOGE("new work failed"); - delete dataWorker; - dataWorker = nullptr; - return; - } + auto task = [dataWorker]() { + ANS_LOGI("OnResponse uv_work_t start"); + + auto dataWorkerData = reinterpret_cast(dataWorker); + if (dataWorkerData == nullptr) { + ANS_LOGD("dataWorkerData is null."); + return; + } + napi_value buttonOption = nullptr; + napi_value buttonName = nullptr; + napi_handle_scope scope; + napi_value notificationId = nullptr; + napi_open_handle_scope(dataWorkerData->env, &scope); + if (scope == nullptr) { + ANS_LOGE("Scope is null"); + return; + } + + // notificationId: number + napi_create_int32(dataWorkerData->env, dataWorkerData->notificationId, ¬ificationId); + + napi_create_object(dataWorkerData->env, &buttonOption); + napi_create_string_utf8(dataWorkerData->env, dataWorkerData->buttonOption->GetButtonName().c_str(), + NAPI_AUTO_LENGTH, &buttonName); + napi_set_named_property(dataWorkerData->env, buttonOption, "buttonName", buttonName); - work->data = reinterpret_cast(dataWorker); + Common::SetCallbackArg2(dataWorkerData->env, dataWorkerData->ref, notificationId, buttonOption); + napi_close_handle_scope(dataWorkerData->env, scope); - int ret = uv_queue_work_with_qos(loop, work, [](uv_work_t *work) {}, - UvQueueWorkOnResponse, uv_qos_user_initiated); - if (ret != 0) { + delete dataWorkerData; + dataWorkerData = nullptr; + }; + if (napi_status::napi_ok != napi_send_event(dataWorker->env, task, napi_eprio_immediate)) { delete dataWorker; dataWorker = nullptr; - delete work; - work = nullptr; } } diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 628af5e221259e65f77c590ba3d3e5f822f5b9ef..fe068b353cf3b10aeb33dec52c16ef8c76e9d228 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -2628,8 +2628,6 @@ ErrCode AdvancedNotificationService::SetBadgeNumberByBundle( sptr bundle = bundleOption; ErrCode result = CheckBundleOptionValid(bundle); if (result != ERR_OK) { - message.ErrorCode(result).Append(" Bundle is invalid."); - NotificationAnalyticsUtil::ReportModifyEvent(message); ANS_LOGE("Bundle is invalid."); return result; } diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index ee31da49f2625631d7a6018002d8d819635981c4..6d7f4f64baf8cbc5e7957f509a1b4bef4c5964aa 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1671,11 +1671,12 @@ bool AdvancedNotificationService::GetBundleInfoByNotificationBundleOption( ErrCode AdvancedNotificationService::CheckBundleOptionValid(sptr &bundleOption) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_7, EventBranchId::BRANCH_8); if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { ANS_LOGE("Bundle option is invalid."); return ERR_ANS_INVALID_PARAM; } - + message.Message(bundleOption->GetBundleName() + "_" +std::to_string(bundleOption->GetUid())); int32_t activeUserId = 0; if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(activeUserId) != ERR_OK) { ANS_LOGE("Failed to get active user id."); @@ -1683,11 +1684,15 @@ ErrCode AdvancedNotificationService::CheckBundleOptionValid(sptr bundleManager = BundleManagerHelper::GetInstance(); if (bundleManager == nullptr) { + message.ErrorCode(ERR_ANS_INVALID_BUNDLE).Append("Failed to get bundle manager."); + NotificationAnalyticsUtil::ReportModifyEvent(message); ANS_LOGE("Failed to get bundle manager."); return ERR_ANS_INVALID_BUNDLE; } int32_t uid = bundleManager->GetDefaultUidByBundleName(bundleOption->GetBundleName(), activeUserId); if (uid == -1) { + message.ErrorCode(ERR_ANS_INVALID_BUNDLE).Append("Bundle name was not found."); + NotificationAnalyticsUtil::ReportModifyEvent(message); ANS_LOGE("The specified bundle name was not found."); return ERR_ANS_INVALID_BUNDLE; }