From acb2e32201df6f9488bc77c0c8187188cdf455ed Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 10 Mar 2022 15:26:50 +0800 Subject: [PATCH] liu Signed-off-by: liuyanzhi Change-Id: Ia802d610b02b1f5aa4f9ce90fadb3a0f25b1b61a --- frameworks/ans/core/src/ans_manager_proxy.cpp | 6 +- .../ans/core/src/ans_subscriber_proxy.cpp | 4 +- interfaces/kits/napi/ans/src/ans_template.cpp | 27 ++- interfaces/kits/napi/ans/src/cancel.cpp | 60 +++-- .../kits/napi/ans/src/display_badge.cpp | 72 +++--- interfaces/kits/napi/ans/src/distributed.cpp | 134 +++++------ interfaces/kits/napi/ans/src/disturb_mode.cpp | 59 ++--- .../kits/napi/ans/src/reminder/publish.cpp | 69 +++--- interfaces/kits/napi/ans/src/remove.cpp | 41 ++-- interfaces/kits/napi/ans/src/slot.cpp | 213 ++++++++---------- interfaces/kits/napi/ans/src/unsubscribe.cpp | 15 +- .../src/distributed_database_callback.cpp | 1 - .../src/distributed_screen_status_manager.cpp | 5 +- 13 files changed, 327 insertions(+), 379 deletions(-) diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index 1199f44fd..8e13b01e2 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -2334,7 +2334,7 @@ ErrCode AnsManagerProxy::ReadReminders( ANSR_LOGD("[GetValidReminders] calendar"); reminder = reply.ReadParcelable(); } else { - ANSR_LOGW("[GetValidReminders] type=%{public}d", typeInfo); + ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo); return ERR_ANS_INVALID_PARAM; } if (!reminder) { @@ -2350,7 +2350,7 @@ ErrCode AnsManagerProxy::InnerTransact(uint32_t code, MessageOption &flags, Mess { auto remote = Remote(); if (remote == nullptr) { - ANS_LOGW("[InnerTransact] fail: get Remote fail code %{public}d", code); + ANS_LOGW("[InnerTransact] fail: get Remote fail code %{public}u", code); return ERR_DEAD_OBJECT; } int err = remote->SendRequest(code, data, reply, flags); diff --git a/frameworks/ans/core/src/ans_subscriber_proxy.cpp b/frameworks/ans/core/src/ans_subscriber_proxy.cpp index ede35cc11..91210c31b 100644 --- a/frameworks/ans/core/src/ans_subscriber_proxy.cpp +++ b/frameworks/ans/core/src/ans_subscriber_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,7 +33,7 @@ ErrCode AnsSubscriberProxy::InnerTransact( { auto remote = Remote(); if (remote == nullptr) { - ANS_LOGW("[InnerTransact] fail: get Remote fail code %{public}d", code); + ANS_LOGW("[InnerTransact] fail: get Remote fail code %{public}u", code); return ERR_DEAD_OBJECT; } diff --git a/interfaces/kits/napi/ans/src/ans_template.cpp b/interfaces/kits/napi/ans/src/ans_template.cpp index 8c33a73f7..a1816c4df 100644 --- a/interfaces/kits/napi/ans/src/ans_template.cpp +++ b/interfaces/kits/napi/ans/src/ans_template.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -89,23 +89,22 @@ napi_value IsSupportTemplate(napi_env env, napi_callback_info info) ANS_LOGI("IsSupportTemplate napi_create_async_work start"); AsyncCallbackInfoTemplate *asyncCallbackinfo = (AsyncCallbackInfoTemplate *)data; - asyncCallbackinfo->info.errorCode = NotificationHelper::IsSupportTemplate( - asyncCallbackinfo->params.templateName, asyncCallbackinfo->params.support); + if (asyncCallbackinfo) { + asyncCallbackinfo->info.errorCode = NotificationHelper::IsSupportTemplate( + asyncCallbackinfo->params.templateName, asyncCallbackinfo->params.support); + } }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("IsSupportTemplate napi_create_async_work end"); AsyncCallbackInfoTemplate *asyncCallbackinfo = (AsyncCallbackInfoTemplate *)data; - - napi_value result = nullptr; - napi_get_boolean(env, asyncCallbackinfo->params.support, &result); - Common::ReturnCallbackPromise(env, asyncCallbackinfo->info, result); - - if (asyncCallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asyncCallbackinfo->info.callback); - } - - napi_delete_async_work(env, asyncCallbackinfo->asyncWork); - if (asyncCallbackinfo != nullptr) { + if (asyncCallbackinfo) { + napi_value result = nullptr; + napi_get_boolean(env, asyncCallbackinfo->params.support, &result); + Common::ReturnCallbackPromise(env, asyncCallbackinfo->info, result); + if (asyncCallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asyncCallbackinfo->info.callback); + } + napi_delete_async_work(env, asyncCallbackinfo->asyncWork); delete asyncCallbackinfo; asyncCallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/cancel.cpp b/interfaces/kits/napi/ans/src/cancel.cpp index 799bc5cd8..691113cf2 100644 --- a/interfaces/kits/napi/ans/src/cancel.cpp +++ b/interfaces/kits/napi/ans/src/cancel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -145,21 +145,20 @@ napi_value Cancel(napi_env env, napi_callback_info info) ANS_LOGI("Cancel napi_create_async_work start"); AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data; - asynccallbackinfo->info.errorCode = - NotificationHelper::CancelNotification(asynccallbackinfo->label, asynccallbackinfo->id); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = + NotificationHelper::CancelNotification(asynccallbackinfo->label, asynccallbackinfo->id); + } }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("Cancel napi_create_async_work end"); AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -202,20 +201,19 @@ napi_value CancelAll(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("CancelAll napi_create_async_work start"); AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data; - asynccallbackinfo->info.errorCode = NotificationHelper::CancelAllNotifications(); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::CancelAllNotifications(); + } }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("CancelAll napi_create_async_work end"); AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -258,22 +256,22 @@ napi_value CancelGroup(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("CancelGroup napi_create_async_work start"); AsyncCallbackInfoCancelGroup *asynccallbackinfo = (AsyncCallbackInfoCancelGroup *)data; - ANS_LOGI("asynccallbackinfo->params.groupName = %{public}s", asynccallbackinfo->params.groupName.c_str()); - asynccallbackinfo->info.errorCode = - NotificationHelper::CancelGroup(asynccallbackinfo->params.groupName); + if (asynccallbackinfo) { + ANS_LOGI("asynccallbackinfo->params.groupName = %{public}s", + asynccallbackinfo->params.groupName.c_str()); + asynccallbackinfo->info.errorCode = + NotificationHelper::CancelGroup(asynccallbackinfo->params.groupName); + } }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("CancelGroup napi_create_async_work end"); AsyncCallbackInfoCancelGroup *asynccallbackinfo = (AsyncCallbackInfoCancelGroup *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 71da17f3c..392f02df3 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -170,26 +170,25 @@ napi_value DisplayBadge(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("DisplayBadge napi_create_async_work start"); AsyncCallbackInfoEnableBadge *asynccallbackinfo = (AsyncCallbackInfoEnableBadge *)data; - ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d enable = %{public}d", - asynccallbackinfo->params.option.GetBundleName().c_str(), - asynccallbackinfo->params.option.GetUid(), - asynccallbackinfo->params.enable); - asynccallbackinfo->info.errorCode = NotificationHelper::SetShowBadgeEnabledForBundle( - asynccallbackinfo->params.option, asynccallbackinfo->params.enable); - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); + if (asynccallbackinfo) { + ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d enable = %{public}d", + asynccallbackinfo->params.option.GetBundleName().c_str(), + asynccallbackinfo->params.option.GetUid(), + asynccallbackinfo->params.enable); + asynccallbackinfo->info.errorCode = NotificationHelper::SetShowBadgeEnabledForBundle( + asynccallbackinfo->params.option, asynccallbackinfo->params.enable); + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); + } }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("DisplayBadge napi_create_async_work end"); AsyncCallbackInfoEnableBadge *asynccallbackinfo = (AsyncCallbackInfoEnableBadge *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -214,17 +213,14 @@ void AsyncCompleteCallbackIsBadgeDisplayed(napi_env env, napi_status status, voi return; } AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = (AsyncCallbackInfoIsDisplayBadge *)data; - - napi_value result = nullptr; - napi_get_boolean(env, asynccallbackinfo->enabled, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + napi_value result = nullptr; + napi_get_boolean(env, asynccallbackinfo->enabled, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -257,18 +253,20 @@ napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("IsBadgeDisplayed napi_create_async_work start"); AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = (AsyncCallbackInfoIsDisplayBadge *)data; - - if (asynccallbackinfo->params.hasBundleOption) { - ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d", - asynccallbackinfo->params.option.GetBundleName().c_str(), - asynccallbackinfo->params.option.GetUid()); - asynccallbackinfo->info.errorCode = NotificationHelper::GetShowBadgeEnabledForBundle( - asynccallbackinfo->params.option, asynccallbackinfo->enabled); - } else { - asynccallbackinfo->info.errorCode = NotificationHelper::GetShowBadgeEnabled(asynccallbackinfo->enabled); + if (asynccallbackinfo) { + if (asynccallbackinfo->params.hasBundleOption) { + ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d", + asynccallbackinfo->params.option.GetBundleName().c_str(), + asynccallbackinfo->params.option.GetUid()); + asynccallbackinfo->info.errorCode = NotificationHelper::GetShowBadgeEnabledForBundle( + asynccallbackinfo->params.option, asynccallbackinfo->enabled); + } else { + asynccallbackinfo->info.errorCode = NotificationHelper::GetShowBadgeEnabled( + asynccallbackinfo->enabled); + } + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, enabled = %{public}d", + asynccallbackinfo->info.errorCode, asynccallbackinfo->enabled); } - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, enabled = %{public}d", - asynccallbackinfo->info.errorCode, asynccallbackinfo->enabled); }, AsyncCompleteCallbackIsBadgeDisplayed, (void *)asynccallbackinfo, diff --git a/interfaces/kits/napi/ans/src/distributed.cpp b/interfaces/kits/napi/ans/src/distributed.cpp index 01e1e541d..06eb1ab31 100644 --- a/interfaces/kits/napi/ans/src/distributed.cpp +++ b/interfaces/kits/napi/ans/src/distributed.cpp @@ -178,21 +178,18 @@ void AsyncCompleteCallbackIsDistributedEnabled(napi_env env, napi_status status, } ANS_LOGI("IsDistributedEnabled napi_create_async_work end"); AsyncCallbackInfoIsEnabled *asynccallbackinfo = (AsyncCallbackInfoIsEnabled *)data; - napi_value result = nullptr; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - napi_get_boolean(env, asynccallbackinfo->enable, &result); - } - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + napi_value result = nullptr; + if (asynccallbackinfo->info.errorCode != ERR_OK) { + result = Common::NapiGetNull(env); + } else { + napi_get_boolean(env, asynccallbackinfo->enable, &result); + } + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -226,9 +223,11 @@ napi_value IsDistributedEnabled(napi_env env, napi_callback_info info) ANS_LOGI("IsDistributedEnabled napi_create_async_work start"); AsyncCallbackInfoIsEnabled *asynccallbackinfo = (AsyncCallbackInfoIsEnabled *)data; - asynccallbackinfo->info.errorCode = - NotificationHelper::IsDistributedEnabled(asynccallbackinfo->enable); - ANS_LOGI("IsDistributedEnabled enable = %{public}d", asynccallbackinfo->enable); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = + NotificationHelper::IsDistributedEnabled(asynccallbackinfo->enable); + ANS_LOGI("IsDistributedEnabled enable = %{public}d", asynccallbackinfo->enable); + } }, AsyncCompleteCallbackIsDistributedEnabled, (void *)asynccallbackinfo, @@ -271,21 +270,20 @@ napi_value EnableDistributed(napi_env env, napi_callback_info info) ANS_LOGI("EnableDistributed napi_create_async_work start"); AsyncCallbackInfoEnabled *asynccallbackinfo = (AsyncCallbackInfoEnabled *)data; - asynccallbackinfo->info.errorCode = - NotificationHelper::EnableDistributed(asynccallbackinfo->params.enable); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = + NotificationHelper::EnableDistributed(asynccallbackinfo->params.enable); + } }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("EnableDistributed napi_create_async_work end"); AsyncCallbackInfoEnabled *asynccallbackinfo = (AsyncCallbackInfoEnabled *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -336,15 +334,12 @@ napi_value EnableDistributedByBundle(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("EnableDistributedByBundle napi_create_async_work end"); AsyncCallbackInfoEnabledByBundle *asynccallbackinfo = (AsyncCallbackInfoEnabledByBundle *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -396,15 +391,12 @@ napi_value EnableDistributedSelf(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("EnableDistributedSelf napi_create_async_work end"); AsyncCallbackInfoEnabled *asynccallbackinfo = (AsyncCallbackInfoEnabled *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -430,20 +422,18 @@ void AsyncCompleteCallbackIsDistributedEnableByBundle(napi_env env, napi_status } ANS_LOGI("IsDistributedEnableByBundle napi_create_async_work end"); AsyncCallbackInfoIsEnabledByBundle *asynccallbackinfo = (AsyncCallbackInfoIsEnabledByBundle *)data; - napi_value result = nullptr; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - napi_get_boolean(env, asynccallbackinfo->enable, &result); - } - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + napi_value result = nullptr; + if (asynccallbackinfo->info.errorCode != ERR_OK) { + result = Common::NapiGetNull(env); + } else { + napi_get_boolean(env, asynccallbackinfo->enable, &result); + } + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -502,25 +492,23 @@ void AsyncCompleteCallbackGetDeviceRemindType(napi_env env, napi_status status, } ANS_LOGI("GetDeviceRemindType napi_create_async_work end"); AsyncCallbackInfoGetRemindType *asynccallbackinfo = (AsyncCallbackInfoGetRemindType *)data; - napi_value result = nullptr; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - DeviceRemindType outType = DeviceRemindType::IDLE_DONOT_REMIND; - if (!Common::DeviceRemindTypeCToJS(asynccallbackinfo->remindType, outType)) { - asynccallbackinfo->info.errorCode = ERROR; + if (asynccallbackinfo) { + napi_value result = nullptr; + if (asynccallbackinfo->info.errorCode != ERR_OK) { result = Common::NapiGetNull(env); + } else { + DeviceRemindType outType = DeviceRemindType::IDLE_DONOT_REMIND; + if (!Common::DeviceRemindTypeCToJS(asynccallbackinfo->remindType, outType)) { + asynccallbackinfo->info.errorCode = ERROR; + result = Common::NapiGetNull(env); + } + napi_create_int32(env, (int32_t)outType, &result); } - napi_create_int32(env, (int32_t)outType, &result); - } - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index dd0291acd..1f6d0bf66 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -213,15 +213,12 @@ napi_value SetDoNotDisturbDate(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("SetDoNotDisturbDate napi_create_async_work end"); AsyncCallbackInfoSetDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoSetDoNotDisturb *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -245,22 +242,19 @@ void AsyncCompleteCallbackGetDoNotDisturbDate(napi_env env, napi_status status, return; } AsyncCallbackInfoGetDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoGetDoNotDisturb *)data; - napi_value result = Common::NapiGetNull(env); - if (asynccallbackinfo->info.errorCode == ERR_OK) { - napi_create_object(env, &result); - if (!Common::SetDoNotDisturbDate(env, asynccallbackinfo->date, result)) { - asynccallbackinfo->info.errorCode = ERROR; - } - } - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + napi_value result = Common::NapiGetNull(env); + if (asynccallbackinfo->info.errorCode == ERR_OK) { + napi_create_object(env, &result); + if (!Common::SetDoNotDisturbDate(env, asynccallbackinfo->date, result)) { + asynccallbackinfo->info.errorCode = ERROR; + } + } + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -390,17 +384,14 @@ napi_value SupportDoNotDisturbMode(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("SupportDoNotDisturbMode napi_create_async_work end"); AsyncCallbackInfoSupportDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoSupportDoNotDisturb *)data; - - napi_value result = nullptr; - napi_get_boolean(env, asynccallbackinfo->isSupported, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + napi_value result = nullptr; + napi_get_boolean(env, asynccallbackinfo->isSupported, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/reminder/publish.cpp b/interfaces/kits/napi/ans/src/reminder/publish.cpp index 911791e66..e49b96786 100644 --- a/interfaces/kits/napi/ans/src/reminder/publish.cpp +++ b/interfaces/kits/napi/ans/src/reminder/publish.cpp @@ -546,25 +546,30 @@ napi_value GetValidReminders(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANSR_LOGI("GetValid reminders napi_create_async_work start"); AsyncCallbackInfo *asynccallbackinfo = (AsyncCallbackInfo *)data; - asynccallbackinfo->info.errorCode = ReminderHelper::GetValidReminders(asynccallbackinfo->validReminders); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = ReminderHelper::GetValidReminders( + asynccallbackinfo->validReminders); + } }, [](napi_env env, napi_status status, void *data) { AsyncCallbackInfo *asynccallbackinfo = (AsyncCallbackInfo *)data; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - asynccallbackinfo->result = NotificationNapi::Common::NapiGetNull(env); - } else { - GetValidRemindersInner(env, asynccallbackinfo->validReminders, asynccallbackinfo->result); + if (asynccallbackinfo) { + if (asynccallbackinfo->info.errorCode != ERR_OK) { + asynccallbackinfo->result = NotificationNapi::Common::NapiGetNull(env); + } else { + GetValidRemindersInner(env, asynccallbackinfo->validReminders, asynccallbackinfo->result); + } + + NotificationNapi::Common::ReturnCallbackPromise( + env, asynccallbackinfo->info, asynccallbackinfo->result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; } - - NotificationNapi::Common::ReturnCallbackPromise( - env, asynccallbackinfo->info, asynccallbackinfo->result); - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - delete asynccallbackinfo; - asynccallbackinfo = nullptr; }, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); @@ -607,29 +612,33 @@ napi_value PublishReminder(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANSR_LOGI("Publish napi_create_async_work start"); AsyncCallbackInfo *asynccallbackinfo = (AsyncCallbackInfo *)data; - asynccallbackinfo->info.errorCode = ReminderHelper::PublishReminder(*(asynccallbackinfo->reminder)); - ANSR_LOGD("Return reminderId=%{public}d", asynccallbackinfo->reminder->GetReminderId()); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = ReminderHelper::PublishReminder(*(asynccallbackinfo->reminder)); + ANSR_LOGD("Return reminderId=%{public}d", asynccallbackinfo->reminder->GetReminderId()); + } }, [](napi_env env, napi_status status, void *data) { ANSR_LOGI("Publish napi_create_async_work complete start"); AsyncCallbackInfo *asynccallbackinfo = (AsyncCallbackInfo *)data; // reminderId - if (asynccallbackinfo->info.errorCode == ERR_OK) { - napi_create_int32(env, asynccallbackinfo->reminder->GetReminderId(), &(asynccallbackinfo->result)); - } else { - napi_create_int32(env, -1, &(asynccallbackinfo->result)); + if (asynccallbackinfo) { + if (asynccallbackinfo->info.errorCode == ERR_OK) { + napi_create_int32(env, asynccallbackinfo->reminder->GetReminderId(), &(asynccallbackinfo->result)); + } else { + napi_create_int32(env, -1, &(asynccallbackinfo->result)); + } + + NotificationNapi::Common::ReturnCallbackPromise( + env, asynccallbackinfo->info, asynccallbackinfo->result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + ANSR_LOGI("Publish napi_create_async_work complete end"); } - - NotificationNapi::Common::ReturnCallbackPromise( - env, asynccallbackinfo->info, asynccallbackinfo->result); - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - ANSR_LOGI("Publish napi_create_async_work complete end"); }, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index 8d44d3219..3206b8732 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -274,15 +274,12 @@ napi_value Remove(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("Remove napi_create_async_work end"); AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -340,15 +337,12 @@ napi_value RemoveAll(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("RemoveAll napi_create_async_work end"); AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -373,15 +367,12 @@ void AsyncCompleteCallbackRemoveGroupByBundle(napi_env env, napi_status status, return; } AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = (AsyncCallbackInfoRemoveGroupByBundle *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/slot.cpp b/interfaces/kits/napi/ans/src/slot.cpp index 7eab91e85..ca4ac4f20 100644 --- a/interfaces/kits/napi/ans/src/slot.cpp +++ b/interfaces/kits/napi/ans/src/slot.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -414,15 +414,12 @@ napi_value AddSlot(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("AddSlot napi_create_async_work end"); auto asynccallbackinfo = (AsyncCallbackInfoAddSlot *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -464,21 +461,18 @@ napi_value AddSlots(napi_env env, napi_callback_info info) resourceName, [](napi_env env, void *data) { ANS_LOGI("AddSlots napi_create_async_work start"); - auto asynccallbackinfo = (AsyncCallbackInfoAddSlots *)data; + auto asynccallbackinfo = static_cast(data); asynccallbackinfo->info.errorCode = NotificationHelper::AddNotificationSlots(asynccallbackinfo->slots); }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("AddSlots napi_create_async_work end"); auto asynccallbackinfo = (AsyncCallbackInfoAddSlots *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -528,15 +522,12 @@ napi_value SetSlotByBundle(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("SetSlotByBundle napi_create_async_work end"); auto asynccallbackinfo = (AsyncCallbackInfoSetSlotByBundle *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -564,6 +555,10 @@ void AsyncCompleteCallbackGetSlot(napi_env env, napi_status status, void *data) } auto asynccallbackinfo = (AsyncCallbackInfoGetSlot *)data; + if (!asynccallbackinfo) { + ANS_LOGE("asynccallbackinfo is nullptr"); + return; + } napi_value result = Common::NapiGetNull(env); if (asynccallbackinfo->info.errorCode == ERR_OK) { if (asynccallbackinfo->slot == nullptr) { @@ -577,16 +572,12 @@ void AsyncCompleteCallbackGetSlot(napi_env env, napi_status status, void *data) } } Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - if (asynccallbackinfo->info.callback != nullptr) { napi_delete_reference(env, asynccallbackinfo->info.callback); } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } + delete asynccallbackinfo; + asynccallbackinfo = nullptr; } napi_value GetSlot(napi_env env, napi_callback_info info) @@ -665,16 +656,14 @@ napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("GetSlotNumByBundle napi_create_async_work end"); auto asynccallbackinfo = (AsyncCallbackInfoGetSlotNumByBundle *)data; - napi_value result = nullptr; - napi_create_int32(env, asynccallbackinfo->num, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + napi_value result = nullptr; + napi_create_int32(env, asynccallbackinfo->num, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -700,40 +689,38 @@ void AsyncCompleteCallbackGetSlots(napi_env env, napi_status status, void *data) } napi_value result = nullptr; auto asynccallbackinfo = (AsyncCallbackInfoGetSlots *)data; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - napi_value arr = nullptr; - napi_create_array(env, &arr); - size_t count = 0; - for (auto vec : asynccallbackinfo->slots) { - if (!vec) { - ANS_LOGW("Invalid NotificationSlot object ptr"); - continue; + if (asynccallbackinfo) { + if (asynccallbackinfo->info.errorCode != ERR_OK) { + result = Common::NapiGetNull(env); + } else { + napi_value arr = nullptr; + napi_create_array(env, &arr); + size_t count = 0; + for (auto vec : asynccallbackinfo->slots) { + if (!vec) { + ANS_LOGW("Invalid NotificationSlot object ptr"); + continue; + } + napi_value nSlot = nullptr; + napi_create_object(env, &nSlot); + if (!Common::SetNotificationSlot(env, *vec, nSlot)) { + continue; + } + napi_set_element(env, arr, count, nSlot); + count++; } - napi_value nSlot = nullptr; - napi_create_object(env, &nSlot); - if (!Common::SetNotificationSlot(env, *vec, nSlot)) { - continue; + ANS_LOGI("getSlots count = %{public}zu", count); + result = arr; + if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { + asynccallbackinfo->info.errorCode = ERROR; + result = Common::NapiGetNull(env); } - napi_set_element(env, arr, count, nSlot); - count++; } - ANS_LOGI("getSlots count = %{public}zu", count); - result = arr; - if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { - asynccallbackinfo->info.errorCode = ERROR; - result = Common::NapiGetNull(env); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); } - } - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -789,40 +776,38 @@ void AsyncCompleteCallbackGetSlotsByBundle(napi_env env, napi_status status, voi } napi_value result = nullptr; auto asynccallbackinfo = (AsyncCallbackInfoGetSlotsByBundle *)data; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - napi_value arr = nullptr; - napi_create_array(env, &arr); - size_t count = 0; - for (auto vec : asynccallbackinfo->slots) { - if (!vec) { - ANS_LOGW("Invalid NotificationSlot object ptr"); - continue; + if (asynccallbackinfo) { + if (asynccallbackinfo->info.errorCode != ERR_OK) { + result = Common::NapiGetNull(env); + } else { + napi_value arr = nullptr; + napi_create_array(env, &arr); + size_t count = 0; + for (auto vec : asynccallbackinfo->slots) { + if (!vec) { + ANS_LOGW("Invalid NotificationSlot object ptr"); + continue; + } + napi_value nSlot = nullptr; + napi_create_object(env, &nSlot); + if (!Common::SetNotificationSlot(env, *vec, nSlot)) { + continue; + } + napi_set_element(env, arr, count, nSlot); + count++; } - napi_value nSlot = nullptr; - napi_create_object(env, &nSlot); - if (!Common::SetNotificationSlot(env, *vec, nSlot)) { - continue; + ANS_LOGI("getSlots count = %{public}zu", count); + result = arr; + if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { + asynccallbackinfo->info.errorCode = ERROR; + result = Common::NapiGetNull(env); } - napi_set_element(env, arr, count, nSlot); - count++; } - ANS_LOGI("getSlots count = %{public}zu", count); - result = arr; - if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { - asynccallbackinfo->info.errorCode = ERROR; - result = Common::NapiGetNull(env); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); } - } - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -902,15 +887,12 @@ napi_value RemoveSlot(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("removeSlot napi_create_async_work end"); auto asynccallbackinfo = (AsyncCallbackInfoRemoveSlot *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -958,15 +940,12 @@ napi_value RemoveAllSlots(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("RemoveAllSlots napi_create_async_work end"); auto asynccallbackinfo = (AsyncCallbackInfoRemoveAllSlots *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/unsubscribe.cpp b/interfaces/kits/napi/ans/src/unsubscribe.cpp index 7ffc15278..0d46462d7 100644 --- a/interfaces/kits/napi/ans/src/unsubscribe.cpp +++ b/interfaces/kits/napi/ans/src/unsubscribe.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -106,15 +106,12 @@ napi_value Unsubscribe(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("Unsubscribe napi_create_async_work end"); AsyncCallbackInfoUnsubscribe *asynccallbackinfo = (AsyncCallbackInfoUnsubscribe *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } diff --git a/services/distributed/src/distributed_database_callback.cpp b/services/distributed/src/distributed_database_callback.cpp index 53bab4807..c797246fa 100644 --- a/services/distributed/src/distributed_database_callback.cpp +++ b/services/distributed/src/distributed_database_callback.cpp @@ -34,7 +34,6 @@ void DistributedDatabaseCallback::OnChange(const DistributedKv::ChangeNotificati void DistributedDatabaseCallback::OnChange(const DistributedKv::ChangeNotification &changeNotification) { ANS_LOGI("%{public}s start", __FUNCTION__); - // const std::vector entryList; if (callback_.OnInsert) { const std::vector &entryList = changeNotification.GetInsertEntries(); diff --git a/services/distributed/src/distributed_screen_status_manager.cpp b/services/distributed/src/distributed_screen_status_manager.cpp index a1dddb7bd..dfd721e41 100644 --- a/services/distributed/src/distributed_screen_status_manager.cpp +++ b/services/distributed/src/distributed_screen_status_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -183,9 +183,8 @@ ErrCode DistributedScreenStatusManager::CheckRemoteDevicesIsUsing(bool &isUsing) for (auto entry : entries) { std::string key = entry.key.ToString(); std::string deviceId = key.substr(0, key.find_first_of(DELIMITER)); - ANS_LOGD("key-deviceId:%{public}s, value:%{public}s", deviceId.c_str(), entry.value.ToString().c_str()); + ANS_LOGD("value:%{public}s", entry.value.ToString().c_str()); for (auto devInfo : devInfoList) { - ANS_LOGD("list-deviceId:%{public}s", devInfo.deviceId.c_str()); if (devInfo.deviceId == deviceId) { isUsing = isUsing || (entry.value.ToString() == SCREEN_STATUS_VALUE_ON); break; -- Gitee