From 7d3e85a8f093ae0b220d835b45e07abd1e1169d7 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Thu, 30 Sep 2021 14:29:40 +0800 Subject: [PATCH] fix wangagent cancel interface bug Signed-off-by: zhaoyuan17 --- .../ans_innerkits_module_publish_test.cpp | 10 +-- interfaces/kits/js/@ohos.notification.d.ts | 1 + interfaces/kits/js/@ohos.wantAgent.d.ts | 80 ++++++++++++++++- .../js/notification/notificationContent.d.ts | 21 ++++- .../js/notification/notificationRequest.d.ts | 3 + .../js/notification/notificationSorting.d.ts | 1 + .../notification/notificationSortingMap.d.ts | 1 + .../notification/notificationSubscribeInfo.ts | 1 + interfaces/kits/js/wantAgent/triggerInfo.d.ts | 3 +- .../kits/js/wantAgent/wantAgentInfo.d.ts | 5 +- interfaces/kits/napi/ans/src/cancel.cpp | 4 +- .../kits/napi/ans/src/display_badge.cpp | 4 +- interfaces/kits/napi/ans/src/disturb_mode.cpp | 2 +- .../kits/napi/ans/src/enable_notification.cpp | 4 +- interfaces/kits/napi/ans/src/get_active.cpp | 6 +- interfaces/kits/napi/ans/src/publish.cpp | 2 +- interfaces/kits/napi/ans/src/remove.cpp | 4 +- interfaces/kits/napi/ans/src/slot.cpp | 18 ++-- interfaces/kits/napi/ans/src/subscribe.cpp | 2 +- interfaces/kits/napi/ans/src/unsubscribe.cpp | 2 +- .../kits/napi/wantagent/napi_want_agent.cpp | 8 +- .../kits/napi/wantagent/napi_want_agent.h | 16 +++- .../ans/src/notification_preferences_info.cpp | 1 + services/test/moduletest/ans_module_test.cpp | 85 ++++++++++--------- 24 files changed, 202 insertions(+), 82 deletions(-) diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index e82c4e47e..a1ba734cd 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -58,8 +58,8 @@ const int32_t CASE_FIFTEEN = 15; const int32_t CASE_SIXTEEN = 16; const int32_t CALLING_UID = 9999; -const int32_t PIXEL_MAP_TEST_WIDTH = 1024; -const int32_t PIXEL_MAP_TEST_HEIGHT = 1024; +const int32_t PIXEL_MAP_TEST_WIDTH = 32; +const int32_t PIXEL_MAP_TEST_HEIGHT = 32; std::mutex g_subscribe_mtx; std::mutex g_consumed_mtx; @@ -190,9 +190,9 @@ private: EXPECT_EQ(outImageInfo.pixelFormat, Media::PixelFormat::ALPHA_8); EXPECT_EQ(outImageInfo.colorSpace, Media::ColorSpace::SRGB); - EXPECT_EQ(nullptr, notificationRequest.GetBigIcon()); - EXPECT_EQ(nullptr, notificationRequest.GetLittleIcon()); - EXPECT_EQ(nullptr, notificationRequest.GetLittleIcon()); + EXPECT_NE(nullptr, notificationRequest.GetBigIcon()); + EXPECT_NE(nullptr, notificationRequest.GetLittleIcon()); + EXPECT_NE(nullptr, notificationRequest.GetLittleIcon()); std::vector> messageUser = notificationRequest.GetMessageUsers(); for (auto user : messageUser) { if (user != nullptr) { diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index ef467ad88..869beba60 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -181,6 +181,7 @@ declare namespace notification { NOTIFICATION_CONTENT_BASIC_TEXT, NOTIFICATION_CONTENT_LONG_TEXT, NOTIFICATION_CONTENT_PICTURE, + NOTIFICATION_CONTENT_CONVERSATION, NOTIFICATION_CONTENT_MULTILINE, } diff --git a/interfaces/kits/js/@ohos.wantAgent.d.ts b/interfaces/kits/js/@ohos.wantAgent.d.ts index 2bdd0a1f0..f7eab8a04 100644 --- a/interfaces/kits/js/@ohos.wantAgent.d.ts +++ b/interfaces/kits/js/@ohos.wantAgent.d.ts @@ -16,6 +16,7 @@ import { AsyncCallback , Callback} from './basic'; import { Want } from './ability/want'; import { WantAgentInfo } from './wantAgent/wantAgentInfo'; +import { TriggerInfo } from './wantAgent/triggerInfo'; /** * Provide the method obtain trigger, cancel, and compare and to obtain @@ -23,17 +24,78 @@ import { WantAgentInfo } from './wantAgent/wantAgentInfo'; * * @name wantAgent * @since 7 - * @devices phone, tablet + * @devices phone, tablet, tv, wearable, car + * @import wantAgent from '@ohos.wantAgent'; * @permission N/A */ declare namespace wantAgent { + /** + * Obtains the bundle name of an {@link WantAgent}. + * + * @param agent Indicates the {@link WantAgent} whose bundle name is to be obtained. + * @return Returns the bundle name of the {@link WantAgent} if any. + * @since 7 + */ + function getBundleName(agent: WantAgent, callback: AsyncCallback): void; + function getBundleName(agent: WantAgent): Promise; + + /** + * Obtains the bundle name of an {@link WantAgent}. + * + * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. + * @return Returns the UID of the {@link WantAgent} if any; returns {@code -1} otherwise. + * @since 7 + */ + function getUid(agent: WantAgent, callback: AsyncCallback): void; + function getUid(agent: WantAgent): Promise; + + /** + * Obtains the {@link Want} of an {@link WantAgent}. + * + * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. + * @return Returns the {@link Want} of the {@link WantAgent}. + * @systemapi Hide this for inner system use. + * @since 7 + */ + function getWant(agent: WantAgent, callback: AsyncCallback): void; + function getWant(agent: WantAgent): Promise; + + /** + * Cancels an {@link WantAgent}. Only the application that creates the {@link IntentAgent} can cancel it. + * + * @param agent Indicates the {@link WantAgent} to cancel. + * @since 7 + */ + function cancel(agent: WantAgent, callback: AsyncCallback): void; + function cancel(agent: WantAgent): Promise; + + /** + * Obtains the bundle name of an {@link WantAgent}. + * + * @param agent Indicates the {@link WantAgent} whose bundle name is to be obtained. + * @param triggerInfo Indicates the {@link TriggerInfo} object that contains triggering parameters. + * @param callback Indicates the callback method to be called after the {@link WantAgent} is triggered. + * @since 7 + */ + function trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback): void; + + /** + * Checks whether two {@link WantAgent} objects are the same. + * + * @param agent Indicates one of the {@link WantAgent} object to compare. + * @param otherAgent Indicates the other {@link WantAgent} object to compare. + * @return Returns {@code true} If the two objects are the same; returns {@code false} otherwise. + * @since 7 + */ + function equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback): void; + function equal(agent: WantAgent, otherAgent: WantAgent): Promise; + /** * Obtains an {@link WantAgent} object. * * @param info Indicates the {@link WantAgentInfo} object that contains parameters of the * {@link WantAgent} object to create. * @return Returns the created {@link WantAgent} object. - * * @since 7 */ function getWantAgent(info: WantAgentInfo, callback: AsyncCallback): void; @@ -69,6 +131,20 @@ declare namespace wantAgent { START_SERVICE, SEND_COMMON_EVENT } + + /** + * A callback for the {@link trigger()} method. After the method execution is complete, + * the callback process will start. + * + * @since 7 + */ + export interface CompleteData { + info: WantAgent; + want: Want; + finalCode: number; + finalData: string; + extraInfo?: {[key: string]: any}; + } } export type WantAgent = object; diff --git a/interfaces/kits/js/notification/notificationContent.d.ts b/interfaces/kits/js/notification/notificationContent.d.ts index 134218f5e..7624cd304 100644 --- a/interfaces/kits/js/notification/notificationContent.d.ts +++ b/interfaces/kits/js/notification/notificationContent.d.ts @@ -14,6 +14,7 @@ */ import notification from '../@ohos.notification'; +import image from './@ohos.multimedia.image'; /** * Constructs basic notifications. @@ -61,9 +62,24 @@ export interface NotificationMultiLineContent extends NotificationBasicContent { } /** - * Constructs a notification that includes multiple lines of text. + * Constructs a notification that includes a picture. * - * @name NotificationMultiLineContent + * @name NotificationPictureContent + * @since 7 + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car + * @permission N/A + */ +export interface NotificationPictureContent extends NotificationBasicContent { + briefText: string; + expandedTitle: string; + picture: image.PixelMap; +} + +/** + * Constructs a notification. + * + * @name NotificationContent * @since 7 * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car @@ -74,4 +90,5 @@ export interface NotificationContent { normal?: NotificationBasicContent; longText?: NotificationLongTextContent; multiLine?: NotificationMultiLineContent; + picture?: NotificationPictureContent; } diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index 0914b648d..f3e2657fe 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -14,6 +14,7 @@ */ import notification from '../@ohos.notification'; +import image from '../@ohos.multimedia.image'; import { WantAgent } from '../@ohos.wantAgent'; import { NotificationContent } from './notificationContent'; import { NotificationActionButton } from './notificationActionButton'; @@ -48,6 +49,8 @@ export interface NotificationRequest { badgeIconStyle?: number; showDeliveryTime?: boolean; actionButtons?: Array; + smallIcon?: image.PixelMap; + largeIcon?: image.PixelMap; readonly creatorBundleName?: string; readonly creatorUid?: number; readonly creatorPid?: number; diff --git a/interfaces/kits/js/notification/notificationSorting.d.ts b/interfaces/kits/js/notification/notificationSorting.d.ts index 1a34e32fa..a4d917145 100644 --- a/interfaces/kits/js/notification/notificationSorting.d.ts +++ b/interfaces/kits/js/notification/notificationSorting.d.ts @@ -22,6 +22,7 @@ import { NotificationSlot } from './notificationSlot'; * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car * @permission N/A + * @systemapi Hide this for inner system use. * @since 7 */ export interface NotificationSorting { diff --git a/interfaces/kits/js/notification/notificationSortingMap.d.ts b/interfaces/kits/js/notification/notificationSortingMap.d.ts index 829ddaf15..2b2a73b4e 100644 --- a/interfaces/kits/js/notification/notificationSortingMap.d.ts +++ b/interfaces/kits/js/notification/notificationSortingMap.d.ts @@ -23,6 +23,7 @@ import { NotificationSorting } from './notificationSorting'; * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car * @permission N/A + * @systemapi Hide this for inner system use. */ interface NotificationSortingMap { readonly sortings: {[key: string]: NotificationSorting}; diff --git a/interfaces/kits/js/notification/notificationSubscribeInfo.ts b/interfaces/kits/js/notification/notificationSubscribeInfo.ts index ea1f69fc2..d7ee89bd9 100644 --- a/interfaces/kits/js/notification/notificationSubscribeInfo.ts +++ b/interfaces/kits/js/notification/notificationSubscribeInfo.ts @@ -21,6 +21,7 @@ * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car * @permission N/A + * @systemapi Hide this for inner system use. */ export interface NotificationSubscribeInfo { bundleNames?: Array; diff --git a/interfaces/kits/js/wantAgent/triggerInfo.d.ts b/interfaces/kits/js/wantAgent/triggerInfo.d.ts index f12ac8ebe..20dfdeab1 100644 --- a/interfaces/kits/js/wantAgent/triggerInfo.d.ts +++ b/interfaces/kits/js/wantAgent/triggerInfo.d.ts @@ -20,8 +20,7 @@ import { Want } from '../ability/want'; * * @name TriggerInfo * @since 7 - * @sysCap ans - * @devices phone, tablet + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface TriggerInfo { diff --git a/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts b/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts index 675ba97d1..d4d1c8705 100644 --- a/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts +++ b/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts @@ -21,14 +21,13 @@ import wantAgent from '../@ohos.wantAgent' * * @name WantAgentInfo * @since 7 - * @sysCap ans - * @devices phone, tablet + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface WantAgentInfo { wants: Array; operationType: wantAgent.OperationType; requestCode: number; - wantAgentFlags?: Array; + wantAgentFlags?: Array; extraInfo?: {[key: string]: any}; } \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/cancel.cpp b/interfaces/kits/napi/ans/src/cancel.cpp index 7bc7871ff..71ea420be 100644 --- a/interfaces/kits/napi/ans/src/cancel.cpp +++ b/interfaces/kits/napi/ans/src/cancel.cpp @@ -102,7 +102,7 @@ napi_value Cancel(napi_env env, napi_callback_info info) ParametersInfoCancel paras; if (ParseParameters(env, info, paras) == nullptr) { - return Common::JSParaError(env, paras.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoCancel *asynccallbackinfo = new (std::nothrow) @@ -160,7 +160,7 @@ napi_value CancelAll(napi_env env, napi_callback_info info) napi_ref callback = nullptr; if (ParseParametersByCancelAll(env, info, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoCancel *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index ea42c40b0..889fd7842 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -129,7 +129,7 @@ napi_value DisplayBadge(napi_env env, napi_callback_info info) EnableBadgeParams params {}; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoEnableBadge *asynccallbackinfo = @@ -194,7 +194,7 @@ napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) IsDisplayBadgeParams params {}; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index d2b88c530..5bb64c12c 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -70,7 +70,7 @@ napi_value SetDoNotDisturbMode(napi_env env, napi_callback_info info) DisturbModeParams params {}; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoDisturbMode *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index aa8c2cdcd..b350df6c0 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -129,7 +129,7 @@ napi_value EnableNotification(napi_env env, napi_callback_info info) EnableParams params {}; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoEnable *asynccallbackinfo = @@ -191,7 +191,7 @@ napi_value IsNotificationEnabled(napi_env env, napi_callback_info info) IsEnableParams params {}; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoIsEnable *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/get_active.cpp b/interfaces/kits/napi/ans/src/get_active.cpp index 0d6ba8c42..788fdd2f2 100644 --- a/interfaces/kits/napi/ans/src/get_active.cpp +++ b/interfaces/kits/napi/ans/src/get_active.cpp @@ -73,7 +73,7 @@ napi_value GetAllActiveNotifications(napi_env env, napi_callback_info info) napi_ref callback = nullptr; if (ParseParametersByAllActive(env, info, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoActive *asynccallbackinfo = @@ -159,7 +159,7 @@ napi_value GetActiveNotifications(napi_env env, napi_callback_info info) napi_ref callback = nullptr; if (ParseParametersByGetActive(env, info, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoActive *asynccallbackinfo = @@ -245,7 +245,7 @@ napi_value GetActiveNotificationCount(napi_env env, napi_callback_info info) napi_ref callback = nullptr; if (ParseParametersByGetActive(env, info, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoActive *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/publish.cpp b/interfaces/kits/napi/ans/src/publish.cpp index 3c860cab9..7bcaf88c2 100644 --- a/interfaces/kits/napi/ans/src/publish.cpp +++ b/interfaces/kits/napi/ans/src/publish.cpp @@ -83,7 +83,7 @@ napi_value Publish(napi_env env, napi_callback_info info) ParametersInfoPublish params; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } napi_value promise = nullptr; diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index 59b9a3dae..90c71f2f2 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -151,7 +151,7 @@ napi_value Remove(napi_env env, napi_callback_info info) RemoveParams params {}; if (ParseParameters(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoRemove *asynccallbackinfo = @@ -217,7 +217,7 @@ napi_value RemoveAll(napi_env env, napi_callback_info info) RemoveParams params {}; if (ParseParametersByRemoveAll(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoRemove *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/slot.cpp b/interfaces/kits/napi/ans/src/slot.cpp index 3764f5380..c5ba3fe79 100644 --- a/interfaces/kits/napi/ans/src/slot.cpp +++ b/interfaces/kits/napi/ans/src/slot.cpp @@ -418,7 +418,7 @@ napi_value AddSlot(napi_env env, napi_callback_info info) ParametersInfoAddSlot paras; if (ParseParametersByAddSlot(env, info, paras) == nullptr) { - return Common::JSParaError(env, paras.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoAddSlot *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoAddSlot { @@ -483,7 +483,7 @@ napi_value AddSlots(napi_env env, napi_callback_info info) ParametersInfoAddSlots paras; if (ParseParametersByAddSlots(env, info, paras) == nullptr) { - return Common::JSParaError(env, paras.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoAddSlots *asynccallbackinfo = @@ -539,7 +539,7 @@ napi_value SetSlotByBundle(napi_env env, napi_callback_info info) ParametersInfoSetSlotByBundle params {}; if (ParseParametersSetSlotByBundle(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = @@ -600,7 +600,7 @@ napi_value GetSlot(napi_env env, napi_callback_info info) ParametersInfoGetSlot paras; if (ParseParametersByGetSlot(env, info, paras) == nullptr) { - return Common::JSParaError(env, paras.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoGetSlot *asynccallbackinfo = @@ -672,7 +672,7 @@ napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info) ParametersInfoGetSlotNumByBundle params {}; if (ParseParametersGetSlotNumByBundle(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = @@ -734,7 +734,7 @@ napi_value GetSlots(napi_env env, napi_callback_info info) napi_ref callback = nullptr; if (ParseParametersByGetSlots(env, info, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoGetSlots *asynccallbackinfo = @@ -819,7 +819,7 @@ napi_value GetSlotsByBundle(napi_env env, napi_callback_info info) ParametersInfoGetSlotsByBundle params {}; if (ParseParametersGetSlotsByBundle(env, info, params) == nullptr) { - return Common::JSParaError(env, params.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoGetSlotsByBundle *asynccallbackinfo = @@ -908,7 +908,7 @@ napi_value RemoveSlot(napi_env env, napi_callback_info info) ParametersInfoRemoveSlot paras; if (ParseParametersByRemoveSlot(env, info, paras) == nullptr) { - return Common::JSParaError(env, paras.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoRemoveSlot *asynccallbackinfo = @@ -964,7 +964,7 @@ napi_value RemoveAllSlots(napi_env env, napi_callback_info info) napi_ref callback = nullptr; if (ParseParametersByRemoveAllSlots(env, info, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoRemoveAllSlots *asynccallbackinfo = diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index 74d6671e8..4edb90d99 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -927,7 +927,7 @@ napi_value Subscribe(napi_env env, napi_callback_info info) SubscriberInstance *objectInfo = nullptr; NotificationSubscribeInfo subscriberInfo; if (ParseParameters(env, info, subscriberInfo, objectInfo, callback) == nullptr) { - return Common::JSParaError(env, callback); + return Common::NapiGetUndefined(env); } ANS_LOGI("Subscribe objectInfo = %{public}p", objectInfo); diff --git a/interfaces/kits/napi/ans/src/unsubscribe.cpp b/interfaces/kits/napi/ans/src/unsubscribe.cpp index 7e2b9bc38..f50a80441 100644 --- a/interfaces/kits/napi/ans/src/unsubscribe.cpp +++ b/interfaces/kits/napi/ans/src/unsubscribe.cpp @@ -69,7 +69,7 @@ napi_value Unsubscribe(napi_env env, napi_callback_info info) ParametersInfoUnsubscribe paras; if (ParseParameters(env, info, paras) == nullptr) { - return Common::JSParaError(env, paras.callback); + return Common::NapiGetUndefined(env); } AsyncCallbackInfoUnsubscribe *asynccallbackinfo = new (std::nothrow) diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.cpp b/interfaces/kits/napi/wantagent/napi_want_agent.cpp index aeb4f5fc1..bce26d682 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.cpp +++ b/interfaces/kits/napi/wantagent/napi_want_agent.cpp @@ -592,11 +592,11 @@ napi_value NAPI_GetWant(napi_env env, napi_callback_info info) void DeleteRecordByCode(const int32_t code) { std::lock_guard guard(g_mutex); - for (const auto &item : g_WantAgentMap) { + for (const auto &item : *g_WantAgentMap) { auto code_ = item.second; auto record = item.first; if (code_ == code) { - g_WantAgentMap.erase(record); + g_WantAgentMap->erase(record); if (record != nullptr) { delete record; record = nullptr; @@ -608,9 +608,7 @@ void DeleteRecordByCode(const int32_t code) auto NAPI_CancelWrapExecuteCallBack = [](napi_env env, void *data) { HILOG_INFO("Cancel called(CallBack Mode)..."); AsyncCancelCallbackInfo *asyncCallbackInfo = static_cast(data); - int32_t code = WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); WantAgentHelper::Cancel(asyncCallbackInfo->wantAgent); - DeleteRecordByCode(code); }; auto NAPI_CancelWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { @@ -1033,7 +1031,7 @@ auto NAPI_GetWantAgentWrapExecuteCallBack = [](napi_env env, void *data) { } int32_t code = Notification::WantAgent::WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); std::lock_guard guard(g_mutex); - g_WantAgentMap.emplace(asyncCallbackInfo, code); + g_WantAgentMap->emplace(asyncCallbackInfo, code); }; auto NAPI_GetWantAgentWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.h b/interfaces/kits/napi/wantagent/napi_want_agent.h index 9b92bc02b..e79f2e93d 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.h +++ b/interfaces/kits/napi/wantagent/napi_want_agent.h @@ -179,7 +179,21 @@ napi_value GetCallbackErrorResult(napi_env env, int errCode); napi_value NapiGetNull(napi_env env); void DeleteRecordByCode(const int32_t code); -static std::map g_WantAgentMap; +static std::unique_ptr, + std::function *)>> + g_WantAgentMap(new std::map, + [](std::map *map) { + if (map == nullptr) { + return; + } + for (auto &item : *map) { + if (item.first != nullptr) { + delete item.first; + } + } + map->clear(); + delete map; + }); static std::recursive_mutex g_mutex; } // namespace OHOS #endif // NAPI_WANT_AGENT_H diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index b77906aaa..9e58416e9 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -100,6 +100,7 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) { + slots.clear(); std::for_each(slots_.begin(), slots_.end(), [&slots](std::map>::reference iter) { diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 3ad7baf33..52d333eb0 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -96,7 +96,7 @@ void AnsModuleTest::SetUpTestCase() void AnsModuleTest::TearDownTestCase() { passed = false; - g_advancedNotificationService = new AdvancedNotificationService(); + g_advancedNotificationService = nullptr; NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); } @@ -109,7 +109,7 @@ void AnsModuleTest::SetUp() void AnsModuleTest::TearDown() { - sptr g_advancedNotificationService = nullptr; + g_advancedNotificationService = nullptr; NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); passed = false; } @@ -746,14 +746,14 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0033, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } /** * @tc.number : AnsModuleTest_0034 * @tc.name : AMS_ANS_GetActiveNotifications_03400 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. + * @tc.desc : Test publish notification when slot type is SOCIAL_COMMUNICATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0034, Function | SmallTest | Level1) { @@ -773,6 +773,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0034, Function | SmallTest | Level1) std::vector> slots; sptr slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); slot->SetEnableVibration(true); + slot->SetSound(Uri("/sound/test.mp3")); slots.push_back(slot); g_advancedNotificationService->AddSlots(slots); @@ -1116,14 +1117,14 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0051, Function | SmallTest | Level1) std::vector> slotsRef{}; g_advancedNotificationService->GetSlots(slotsRef); - EXPECT_EQ(5, static_cast(slotsRef.size())); + EXPECT_EQ(1, static_cast(slotsRef.size())); std::vector slotsId{}; for (const auto &i : slotsRef) { slotsId.push_back(i->GetId()); } g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); g_advancedNotificationService->GetSlots(slotsRef); - EXPECT_EQ(9, static_cast(slotsRef.size())); + EXPECT_EQ(0, static_cast(slotsRef.size())); } /** @@ -1148,7 +1149,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0052, Function | SmallTest | Level1) g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); g_advancedNotificationService->GetSlots(slotsRef); - EXPECT_EQ(9, static_cast(slotsRef.size())); + EXPECT_EQ(0, static_cast(slotsRef.size())); } /** @@ -1258,8 +1259,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0058, Function | SmallTest | Level1) req->SetBadgeNumber(1); // SetShowBadgeEnabledForBundle true - sptr bundleOption; - bundleOption->SetBundleName("bundleName"); + sptr bundleOption = new NotificationBundleOption("bundleName", 0); g_advancedNotificationService->SetShowBadgeEnabledForBundle(bundleOption, true); g_advancedNotificationService->Publish(label, req); @@ -1288,7 +1288,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0060, Function | SmallTest | Level1) sptr slot = new NotificationSlot(); slot->EnableBadge(true); slots.push_back(slot); - EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0); + EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), ERR_OK); // create request std::string label = "testLabel"; @@ -1297,15 +1297,20 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0060, Function | SmallTest | Level1) req->SetStatusBarText("text"); req->SetBadgeNumber(1); + sptr bundleOption = new NotificationBundleOption("bundleName", 1); + ASSERT_NE(bundleOption, nullptr); + // not allow publish notification - g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", false); + g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, false); g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); + EXPECT_FALSE(passed); + passed = false; // allow publish - g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", true); + g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, true); g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(true, passed); + EXPECT_TRUE(passed); + g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1339,16 +1344,20 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0061, Function | SmallTest | Level1) req->SetStatusBarText("text"); req->SetBadgeNumber(1); + sptr bundleOption = new NotificationBundleOption("bundleName", 1); + ASSERT_NE(bundleOption, nullptr); + // allow publish notification - g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", true); + g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, true); g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(true, passed); + EXPECT_TRUE(passed); // not allow publish passed = false; - g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", false); + g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, false); g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); + EXPECT_FALSE(passed); + g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1395,7 +1404,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0062, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Publish(label, req1); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1440,7 +1449,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0063, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Publish(label, req1); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } @@ -1500,7 +1509,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0066, Function | SmallTest | Level1) // remove request g_advancedNotificationService->Delete("1_testLabel_0"); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } @@ -1543,7 +1552,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(passed, false); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1574,7 +1583,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0101, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(passed, false); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1605,7 +1614,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0102, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(passed, false); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1731,7 +1740,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0106, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(passed, false); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1977,7 +1986,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0113, Function | SmallTest | Level1) g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Publish(label, req1); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); } /** @@ -2036,7 +2045,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0114, Function | SmallTest | Level1) g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Publish(label, req1); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); } /** @@ -2095,7 +2104,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0116, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Publish(label, req1); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } @@ -2155,7 +2164,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0117, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Publish(label, req1); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } @@ -2357,18 +2366,18 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) req4->SetSlotType(NotificationConstant::SlotType::CUSTOM); g_advancedNotificationService->Publish("testLabel", req); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 1); g_advancedNotificationService->Publish("testLabel", req1); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 2); g_advancedNotificationService->Publish("testLabel", req2); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 3); g_advancedNotificationService->Publish("testLabel", req3); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 4); g_advancedNotificationService->Publish("testLabel", req4); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 5); g_advancedNotificationService->DeleteAll(); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); } /** @@ -2406,7 +2415,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0124, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); } /** @@ -2439,7 +2448,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0125, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); } /** @@ -2477,7 +2486,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0126, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); - EXPECT_FALSE(passed); + EXPECT_TRUE(passed); } /** -- Gitee