From 7f6ecb143fd5c22b2ba863a8e2aec61e6b396c62 Mon Sep 17 00:00:00 2001 From: njupthan Date: Thu, 27 Jan 2022 14:02:57 +0000 Subject: [PATCH 01/17] Add dts for Distributed Signed-off-by: njupthan --- interfaces/kits/js/@ohos.notification.d.ts | 80 +++++++++++++++++++ .../js/notification/notificationRequest.d.ts | 51 ++++++++++++ 2 files changed, 131 insertions(+) diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index edbbd33d7..a96782068 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -552,6 +552,58 @@ declare namespace notification { function isSupportTemplate(templateName: string, callback: AsyncCallback): void; function isSupportTemplate(templateName: string): Promise; + /** + * Sets whether the device supports distributed notification. + * + * @since 8 + * @systemapi Hide this for inner system use. + */ + function enableDistributed(enable: boolean, callback: AsyncCallback): void; + function enableDistributed(enable: boolean): Promise; + + /** + * Obtains whether the device supports distributed notification. + * + * @since 8 + */ + function isDistributedEnabled(callback: AsyncCallback): void; + function isDistributedEnabled(): Promise; + + /** + * Sets whether an application supports distributed notification. + * + * @since 8 + * @systemapi Hide this for inner system use. + */ + function enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; + function enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise; + + /** + * Sets whether the application supports distributed notification. + * + * @since 8 + */ + function enableDistributedSelf(enable: boolean, callback: AsyncCallback): void; + function enableDistributedSelf(enable: boolean): Promise; + + /** + * Obtains whether an application supports distributed notification. + * + * @since 8 + * @systemapi Hide this for inner system use. + */ + function isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback): void; + function isDistributedEnabledByBundle(bundle: BundleOption): Promise; + + /** + * Obtains the remind modes of the notification. + * + * @since 8 + * @systemapi Hide this for inner system use. + */ + function getDeviceRemindType(callback: AsyncCallback): void; + function getDeviceRemindType(): Promise; + /** * Describes a BundleOption. */ @@ -725,6 +777,34 @@ declare namespace notification { */ TYPE_TIMER = 0x00000002, } + + /** + * The remind type of the nofication. + * + * @since 8 + * @systemapi Hide this for inner system use. + */ + export enum DeviceRemindType { + /** + * The device is not in use, no reminder + */ + IDLE_DONOT_REMIND = 0, + + /** + * The device is not in use, remind + */ + IDLE_REMIND = 1, + + /** + * The device is in use, no reminder + */ + ACTIVE_DONOT_REMIND = 2, + + /** + * The device is in use, reminder + */ + ACTIVE_REMIND = 3, + } } export default notification; diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index 971ecb0c7..e4dabaca9 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -199,6 +199,21 @@ export interface NotificationRequest { */ template?: NotificationTemplate; + /** + * The options to distributed notification. + * + * @since 8 + */ + distributedOption?: DistributedOptions; + + /** + * The device ID of the notification source. + * + * @since 8 + * @systemapi Hide this for inner system use. + */ + readonly deviceId?: string; + /** * Obtains the set of identifiers for the notification. * @@ -206,3 +221,39 @@ export interface NotificationRequest { */ readonly notificationFlags?: NotificationFlags; } + + +/** + * Describes distributed options. + * + * @name DistributedOptions + * @since 8 + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car + * @permission N/A + */ +export interface DistributedOptions { + /** + * Obtains whether is the distributed notification. + * + * @default true + */ + isDistributed?: boolean; + + /** + * Obtains the types of devices to which the notification can be synchronized. + */ + supportDisplayDevices?: Array; + + /** + * Obtains the devices on which notifications can be open. + */ + supportOperateDevices?: Array; + + /** + * Obtains the remind mode of the notification. enum DeviceRemindType. + + * @systemapi Hide this for inner system use. + */ + readonly remindType?: number; +} \ No newline at end of file -- Gitee From abc322a6dad94c7fa4f2578dee0e3d6dd64da037 Mon Sep 17 00:00:00 2001 From: liqiang Date: Thu, 17 Feb 2022 20:20:33 +0800 Subject: [PATCH 02/17] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4U6XQ Description:fix codecheck bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: I04ed2fb9484e5fb735911d06fb2eb4921513e913 --- frameworks/ans/test/moduletest/ans_fw_module_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index ecbcac893..e7d017b0b 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -181,7 +181,7 @@ private: class OnOnCanceledEvent : public SubscriberEvent { public: - OnOnCanceledEvent(const std::shared_ptr &request) + explicit OnOnCanceledEvent(const std::shared_ptr &request) : SubscriberEvent(SubscriberEventType::ON_CANCELED), request_(request) {} @@ -231,7 +231,7 @@ private: class OnConsumedEvent : public SubscriberEvent { public: - OnConsumedEvent(const std::shared_ptr &request) + explicit OnConsumedEvent(const std::shared_ptr &request) : SubscriberEvent(SubscriberEventType::ON_CONSUMED), request_(request) {} -- Gitee From 3d9ca760edc9e0869bf5d199b3b2d5f7515c7872 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Sat, 19 Feb 2022 12:12:47 +0800 Subject: [PATCH 03/17] fixed 3735253 from https://gitee.com/fangJinliang1/notification_ans_standard/pulls/256 add multi user interface Signed-off-by: fangJinliang1 Change-Id: Ic325c01162ec9ebaec3032215828fdfe8987777c --- interfaces/kits/js/@ohos.notification.d.ts | 50 +++++++++++++++++++ .../js/notification/notificationRequest.d.ts | 5 ++ 2 files changed, 55 insertions(+) diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index 41b9500ee..0a3f1bd33 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -49,6 +49,17 @@ declare namespace notification { function publish(request: NotificationRequest, callback: AsyncCallback): void; function publish(request: NotificationRequest): Promise; + /** + * Publishes a notification to the specified user. + * + * @since 8 + * @param Publishes a notification. + * @param userId of subscriber receiving the notification + * + */ + function publish(request: NotificationRequest, userId: number, callback: AsyncCallback): void; + function publish(request: NotificationRequest, userId: number): Promise; + /** * Cancels a notification with the specified ID. * @@ -332,6 +343,15 @@ declare namespace notification { */ function isNotificationEnabled(callback: AsyncCallback): void; + /** + * Checks whether this application has permission to publish notifications under the user. + * + * since 8 + * @systemapi Hide this for inner system use. + */ + function isNotificationEnabled(userId: number, callback: AsyncCallback): void; + function isNotificationEnabled(userId: number): Promise; + /** * isNotificationEnabled * @@ -461,6 +481,16 @@ declare namespace notification { */ function removeAll(callback: AsyncCallback): void; + /** + * Remove all notifications under the specified user. + * + * @since 8 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function removeAll(userId: number, callback: AsyncCallback): void; + function removeAll(userId: number): Promise; + /** * removeAll * @@ -527,6 +557,16 @@ declare namespace notification { function setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback): void; function setDoNotDisturbDate(date: DoNotDisturbDate): Promise; + /** + * Set the Do Not Disturb date under the specified user. + * + * @since 8 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback): void; + function setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise; + /** * Obtains the Do Not Disturb date. * @@ -537,6 +577,16 @@ declare namespace notification { function getDoNotDisturbDate(callback: AsyncCallback): void; function getDoNotDisturbDate(): Promise; + /** + * Obtains the Do Not Disturb date. + * + * @since 8 + * @systemapi Hide this for inner system use under the specified user. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function getDoNotDisturbDate(userId: number, callback: AsyncCallback): void; + function getDoNotDisturbDate(userId: number): Promise; + /** * Obtains whether to support the Do Not Disturb mode. * diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index f53673de2..90660bfee 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -162,6 +162,11 @@ export interface NotificationRequest { */ readonly creatorPid?: number; + /** + * Read-only UserId of the notification creator. + */ + readonly creatorUserId?: number; + /** * Obtains the classification of this notification. * -- Gitee From 308ed0b4d9882f3e640fdc075038f476ab7c79bc Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Fri, 18 Feb 2022 17:01:11 +0800 Subject: [PATCH 04/17] UT modify Signed-off-by: fangJinliang1 Change-Id: I76d1b161ba948fd681f6f9dcffacf83ddad7b7b3 Signed-off-by: fangJinliang1 --- .../ans/native/src/notification_request.cpp | 15 +++++++-------- .../advanced_notification_service_test.cpp | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index f48ccfb59..beba5fa04 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -1545,15 +1545,14 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const } jsonObject["distributedOptions"] = optObj; - if (!notificationFlags_) { - return false; - } - nlohmann::json flagsObj; - if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { - ANS_LOGE("Cannot convert notificationFlags to JSON"); - return false; + if (notificationFlags_) { + nlohmann::json flagsObj; + if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { + ANS_LOGE("Cannot convert notificationFlags to JSON"); + return false; + } + jsonObject["notificationFlags"] = flagsObj; } - jsonObject["notificationFlags"] = flagsObj; return true; } diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index fc1d0c27c..f58b8f4e7 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1229,6 +1229,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, Function | SmallTest | Level1) { + EXPECT_EQ( + (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); TestAddSlot(NotificationConstant::SlotType::OTHER); bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify( @@ -1243,6 +1245,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09800, Function | SmallTest | Level1) { + EXPECT_EQ( + (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); std::vector> notifications; bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify( -- Gitee From b33e5076ba3849a179a5e44d15298476aeea74f3 Mon Sep 17 00:00:00 2001 From: zhongjianfei Date: Tue, 22 Feb 2022 19:51:53 +0800 Subject: [PATCH 05/17] zhongjianfei@huawei.com Signed-off-by: zhongjianfei Change-Id: Ic6324cc9c35302b29dad1b75aea33b0c49cbff52 --- frameworks/ans/test/moduletest/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index fd56828c2..0b4baefe3 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -136,8 +136,6 @@ ohos_moduletest("ans_innerkits_module_publish_test") { configs = [ "//utils/native/base:utils_config" ] - ldflags = [ "-Wl,-rpath=/system/lib/module/multimedia/" ] - deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", -- Gitee From e3a4214a5d24b33d25f13ab7b2ad80a787860f11 Mon Sep 17 00:00:00 2001 From: njupthan Date: Wed, 23 Feb 2022 17:58:21 +0800 Subject: [PATCH 06/17] updsate d.ts file Signed-off-by: njupthan --- interfaces/kits/js/@ohos.notification.d.ts | 131 +++++++++++++++--- .../notificationActionButton.d.ts | 3 +- .../js/notification/notificationRequest.d.ts | 14 +- .../notification/notificationSubscriber.d.ts | 26 +++- 4 files changed, 141 insertions(+), 33 deletions(-) diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index a96782068..4fd30fa4b 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -32,8 +32,7 @@ import { NotificationRequest } from './notification/notificationRequest'; * * @name notification * @since 7 - * @sysCap SystemCapability.Notification.ANS - * @devices phone, tablet, tv, wearable, car + * @syscap SystemCapability.Notification.Notification * @import import notification from '@ohos.notification'; * @permission N/A */ @@ -44,23 +43,37 @@ declare namespace notification { *

If a notification with the same ID has been published by the current application and has not been deleted, * this method will update the notification. * - * @param Publishes a notification. + * @param request notification request + * @param callback callback function */ function publish(request: NotificationRequest, callback: AsyncCallback): void; function publish(request: NotificationRequest): Promise; + /** + * Publishes a notification to the specified user. + * + * @since 8 + * @param Publishes a notification. + * @param userId of subscriber receiving the notification + * + */ + function publish(request: NotificationRequest, userId: number, callback: AsyncCallback): void; + function publish(request: NotificationRequest, userId: number): Promise; + /** * Cancels a notification with the specified ID. * - * @param ID of the notification to cancel, which must be unique in the application. + * @param id of the notification to cancel, which must be unique in the application. + * @param callback callback function */ function cancel(id: number, callback: AsyncCallback): void; /** * Cancels a notification with the specified label and ID. * - * @param ID of the notification to cancel, which must be unique in the application. - * @param Label of the notification to cancel. + * @param id ID of the notification to cancel, which must be unique in the application. + * @param label Label of the notification to cancel. + * @param callback callback function */ function cancel(id: number, label: string, callback: AsyncCallback): void; function cancel(id: number, label?: string): Promise; @@ -76,8 +89,9 @@ declare namespace notification { * * @param slot Indicates the notification slot to be created, which is set by {@link NotificationSlot}. * This parameter must be specified. - * + * @param callback callback function * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlot(slot: NotificationSlot, callback: AsyncCallback): void; @@ -88,13 +102,15 @@ declare namespace notification { * This parameter must be specified. * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlot(slot: NotificationSlot): Promise; /** * Adds a slot type. * - * @param Slot type to add. + * @param type Slot type to add. + * @param callback callback function */ function addSlot(type: SlotType, callback: AsyncCallback): void; function addSlot(type: SlotType): Promise; @@ -104,8 +120,9 @@ declare namespace notification { * * @param slots Indicates the notification slots to be created, which is set by {@link NotificationSlot}. * This parameter must be specified. - * + * @param callback callback function * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlots(slots: Array, callback: AsyncCallback): void; @@ -116,14 +133,15 @@ declare namespace notification { * This parameter must be specified. * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlots(slots: Array): Promise; /** * Obtains a notification slot of the specified slot type. * - * @param Type of the notification slot to obtain. - * + * @param slotType Type of the notification slot to obtain. + * @param callback callback function * @return Returns the created {@link NotificationSlot}. */ function getSlot(slotType: SlotType, callback: AsyncCallback): void; @@ -140,7 +158,8 @@ declare namespace notification { /** * Removes a NotificationSlot of the specified SlotType created by the current application. * - * @param Type of the NotificationSlot to remove. + * @param slotType Type of the NotificationSlot to remove. + * @param callback callback function */ function removeSlot(slotType: SlotType, callback: AsyncCallback): void; function removeSlot(slotType: SlotType): Promise; @@ -186,8 +205,7 @@ declare namespace notification { * * @name ContentType * @since 7 - * @sysCap SystemCapability.Notification.ANS - * @devices phone, tablet, tv, wearable, car + * @syscap SystemCapability.Notification.Notification * @permission N/A */ export enum ContentType { @@ -311,6 +329,7 @@ declare namespace notification { * isNotificationEnabled * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback): void; @@ -318,6 +337,7 @@ declare namespace notification { * isNotificationEnabled * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(bundle: BundleOption): Promise; @@ -325,6 +345,7 @@ declare namespace notification { * isNotificationEnabled * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(callback: AsyncCallback): void; @@ -332,13 +353,25 @@ declare namespace notification { * isNotificationEnabled * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(): Promise; + /** + * Checks whether this application has permission to publish notifications under the user. + * + * since 8 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function isNotificationEnabled(userId: number, callback: AsyncCallback): void; + function isNotificationEnabled(userId: number): Promise; + /** * displayBadge * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; @@ -346,6 +379,7 @@ declare namespace notification { * displayBadge * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function displayBadge(bundle: BundleOption, enable: boolean): Promise; @@ -353,6 +387,7 @@ declare namespace notification { * isBadgeDisplayed * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback): void; @@ -360,6 +395,7 @@ declare namespace notification { * isBadgeDisplayed * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isBadgeDisplayed(bundle: BundleOption): Promise; @@ -399,6 +435,7 @@ declare namespace notification { * getSlotNumByBundle * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback): void; @@ -406,6 +443,7 @@ declare namespace notification { * getSlotNumByBundle * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getSlotNumByBundle(bundle: BundleOption): Promise; @@ -457,6 +495,16 @@ declare namespace notification { */ function removeAll(callback: AsyncCallback): void; + /** + * Remove all notifications under the specified user. + * + * @since 8 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function removeAll(userId: number, callback: AsyncCallback): void; + function removeAll(userId: number): Promise; + /** * removeAll * @@ -523,6 +571,16 @@ declare namespace notification { function setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback): void; function setDoNotDisturbDate(date: DoNotDisturbDate): Promise; + /** + * Set the Do Not Disturb date under the specified user. + * + * @since 8 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback): void; + function setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise; + /** * Obtains the Do Not Disturb date. * @@ -533,6 +591,16 @@ declare namespace notification { function getDoNotDisturbDate(callback: AsyncCallback): void; function getDoNotDisturbDate(): Promise; + /** + * Obtains the Do Not Disturb date. + * + * @since 8 + * @systemapi Hide this for inner system use under the specified user. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function getDoNotDisturbDate(userId: number, callback: AsyncCallback): void; + function getDoNotDisturbDate(userId: number): Promise; + /** * Obtains whether to support the Do Not Disturb mode. * @@ -548,15 +616,33 @@ declare namespace notification { * * @since 8 * @param templateName Name of template to be Obtained + * @param callback callback function */ function isSupportTemplate(templateName: string, callback: AsyncCallback): void; function isSupportTemplate(templateName: string): Promise; + /** + * Query notification sending permission. + * + * @since 8 + */ + function isNotificationEnabledSelf(callback: AsyncCallback): void; + function isNotificationEnabledSelf(): Promise; + + /** + * Request permission to send notification. + * + * @since 8 + */ + function requestEnableNotification(callback: AsyncCallback): void; + function requestEnableNotification(): Promise; + /** * Sets whether the device supports distributed notification. * * @since 8 * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function enableDistributed(enable: boolean, callback: AsyncCallback): void; function enableDistributed(enable: boolean): Promise; @@ -574,32 +660,35 @@ declare namespace notification { * * @since 8 * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; function enableDistributedByBundle(bundle: BundleOption, enable: boolean): Promise; /** - * Sets whether the application supports distributed notification. + * Obtains whether an application supports distributed notification. * * @since 8 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ - function enableDistributedSelf(enable: boolean, callback: AsyncCallback): void; - function enableDistributedSelf(enable: boolean): Promise; + function isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback): void; + function isDistributedEnabledByBundle(bundle: BundleOption): Promise; /** - * Obtains whether an application supports distributed notification. + * Sets whether the application supports distributed notification. * * @since 8 - * @systemapi Hide this for inner system use. */ - function isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback): void; - function isDistributedEnabledByBundle(bundle: BundleOption): Promise; + function enableDistributedSelf(enable: boolean, callback: AsyncCallback): void; + function enableDistributedSelf(enable: boolean): Promise; /** * Obtains the remind modes of the notification. * * @since 8 * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getDeviceRemindType(callback: AsyncCallback): void; function getDeviceRemindType(): Promise; diff --git a/interfaces/kits/js/notification/notificationActionButton.d.ts b/interfaces/kits/js/notification/notificationActionButton.d.ts index 9428cc4f0..cd67a4452 100644 --- a/interfaces/kits/js/notification/notificationActionButton.d.ts +++ b/interfaces/kits/js/notification/notificationActionButton.d.ts @@ -20,9 +20,8 @@ import { WantAgent } from '../@ohos.wantAgent'; * Describes an action button displayed in a notification. * @name NotificationActionButton * @since 7 - * @devices phone, tablet, tv, wearable, car * @permission N/A - * @sysCap SystemCapability.Notification.ANS + * @syscap SystemCapability.Notification.Notification */ export interface NotificationActionButton { /** diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index e4dabaca9..e68532b8c 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -26,8 +26,7 @@ import { NotificationFlags } from './notificationFlags'; * * @name NotificationRequest * @since 7 - * @sysCap SystemCapability.Notification.ANS - * @devices phone, tablet, tv, wearable, car + * @syscap SystemCapability.Notification.Notification * @permission N/A */ export interface NotificationRequest { @@ -163,6 +162,11 @@ export interface NotificationRequest { */ readonly creatorPid?: number; + /** + * Read-only UserId of the notification creator. + */ + readonly creatorUserId?: number; + /** * Obtains the classification of this notification. * @@ -222,14 +226,12 @@ export interface NotificationRequest { readonly notificationFlags?: NotificationFlags; } - /** * Describes distributed options. * * @name DistributedOptions * @since 8 - * @sysCap SystemCapability.Notification.ANS - * @devices phone, tablet, tv, wearable, car + * @sysCap SystemCapability.Notification.Notification * @permission N/A */ export interface DistributedOptions { @@ -256,4 +258,4 @@ export interface DistributedOptions { * @systemapi Hide this for inner system use. */ readonly remindType?: number; -} \ No newline at end of file +} diff --git a/interfaces/kits/js/notification/notificationSubscriber.d.ts b/interfaces/kits/js/notification/notificationSubscriber.d.ts index 3ae878775..d14e59c08 100644 --- a/interfaces/kits/js/notification/notificationSubscriber.d.ts +++ b/interfaces/kits/js/notification/notificationSubscriber.d.ts @@ -22,8 +22,7 @@ import notification from '../@ohos.notification'; * a notification is canceled. * * @name NotificationSubscriber - * @sysCap SystemCapability.Notification.ANS - * @devices phone, tablet, tv, wearable, car + * @syscap SystemCapability.Notification.Notification * @permission N/A * @systemapi Hide this for inner system use. * @since 7 @@ -42,6 +41,13 @@ export interface NotificationSubscriber { * @since 8 */ onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) => void; + + /** + * Callback when the notificaition permission is changed. + * + * @since 8 + */ + onEnabledNotificationChanged?:(callbackData: EnabledNotificationCallbackData) => void; } /** @@ -49,8 +55,7 @@ export interface NotificationSubscriber { * a notification is canceled. * * @name SubscribeCallbackData - * @sysCap SystemCapability.Notification.ANS - * @devices phone, tablet, tv, wearable, car + * @syscap SystemCapability.Notification.Notification * @permission N/A * @systemapi Hide this for inner system use. * @since 7 @@ -61,4 +66,17 @@ export interface SubscribeCallbackData { readonly reason?: number; readonly sound?: string; readonly vibrationValues?: Array; +} + +/** + * Describes the properties of the application that the permission to send notifications has changed. + * + * @name EnabledNotificationCallbackData + * @systemapi Hide this for inner system use. + * @since 8 + */ +export interface EnabledNotificationCallbackData { + readonly bundle: string; + readonly uid: number; + readonly enable: boolean; } \ No newline at end of file -- Gitee From ba3c634292a44431f105e9c9a1cd563a161fb204 Mon Sep 17 00:00:00 2001 From: njupthan Date: Wed, 23 Feb 2022 18:15:14 +0800 Subject: [PATCH 07/17] update d.ts file Signed-off-by: njupthan --- interfaces/kits/js/@ohos.notification.d.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index 9c6ba7ef5..4fd30fa4b 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -349,15 +349,6 @@ declare namespace notification { */ function isNotificationEnabled(callback: AsyncCallback): void; - /** - * Checks whether this application has permission to publish notifications under the user. - * - * since 8 - * @systemapi Hide this for inner system use. - */ - function isNotificationEnabled(userId: number, callback: AsyncCallback): void; - function isNotificationEnabled(userId: number): Promise; - /** * isNotificationEnabled * -- Gitee From 0b55f6e68fd2b573dcce14c279976bc19e69cc81 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Wed, 23 Feb 2022 12:57:31 +0800 Subject: [PATCH 08/17] Clean up resources when deleting accounts Signed-off-by: fangJinliang1 Change-Id: I708a4c82f4d9e0d8d4d1e6ba3e1d175c615cf092 Signed-off-by: fangJinliang1 --- frameworks/ans/core/src/ans_manager_stub.cpp | 2 +- interfaces/kits/js/@ohos.notification.d.ts | 15 + .../js/notification/notificationRequest.d.ts | 1 + .../include/advanced_notification_service.h | 1 + services/ans/include/interface_system_event.h | 1 + .../ans/include/notification_preferences.h | 1 + .../notification_preferences_database.h | 37 ++- .../include/notification_preferences_info.h | 2 + .../ans/src/advanced_notification_service.cpp | 15 + services/ans/src/notification_preferences.cpp | 20 +- .../src/notification_preferences_database.cpp | 294 +++++++++++------- .../ans/src/notification_preferences_info.cpp | 10 + services/ans/src/system_event_observer.cpp | 5 + 13 files changed, 262 insertions(+), 142 deletions(-) diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 9110ac4a8..98f514cca 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -1608,7 +1608,7 @@ ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParc ErrCode AnsManagerStub::HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply) { int32_t userId = SUBSCRIBE_USER_INIT; - if (data.ReadInt32(userId)) { + if (!data.ReadInt32(userId)) { ANS_LOGW("[HandleIsSpecialUserAllowedNotifyByUser] fail: read userId failed."); return ERR_ANS_PARCELABLE_FAILED; } diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index 0a3f1bd33..ee4a0894f 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -55,6 +55,8 @@ declare namespace notification { * @since 8 * @param Publishes a notification. * @param userId of subscriber receiving the notification + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER * */ function publish(request: NotificationRequest, userId: number, callback: AsyncCallback): void; @@ -92,6 +94,7 @@ declare namespace notification { * * @systemapi Hide this for inner system use. * @param callback callback function + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlot(slot: NotificationSlot, callback: AsyncCallback): void; @@ -102,6 +105,7 @@ declare namespace notification { * This parameter must be specified. * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlot(slot: NotificationSlot): Promise; @@ -121,6 +125,7 @@ declare namespace notification { * This parameter must be specified. * @param callback callback function * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlots(slots: Array, callback: AsyncCallback): void; @@ -131,6 +136,7 @@ declare namespace notification { * This parameter must be specified. * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function addSlots(slots: Array): Promise; @@ -340,6 +346,7 @@ declare namespace notification { * isNotificationEnabled * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(callback: AsyncCallback): void; @@ -348,6 +355,7 @@ declare namespace notification { * * since 8 * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(userId: number, callback: AsyncCallback): void; function isNotificationEnabled(userId: number): Promise; @@ -356,6 +364,7 @@ declare namespace notification { * isNotificationEnabled * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isNotificationEnabled(): Promise; @@ -363,6 +372,7 @@ declare namespace notification { * displayBadge * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; @@ -370,6 +380,7 @@ declare namespace notification { * displayBadge * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function displayBadge(bundle: BundleOption, enable: boolean): Promise; @@ -377,6 +388,7 @@ declare namespace notification { * isBadgeDisplayed * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback): void; @@ -384,6 +396,7 @@ declare namespace notification { * isBadgeDisplayed * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function isBadgeDisplayed(bundle: BundleOption): Promise; @@ -423,6 +436,7 @@ declare namespace notification { * getSlotNumByBundle * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback): void; @@ -430,6 +444,7 @@ declare namespace notification { * getSlotNumByBundle * * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getSlotNumByBundle(bundle: BundleOption): Promise; diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index 90660bfee..f80d32926 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -163,6 +163,7 @@ export interface NotificationRequest { readonly creatorPid?: number; /** + * @since 8 * Read-only UserId of the notification creator. */ readonly creatorUserId?: number; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 539c4360e..fb86fd4e0 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -135,6 +135,7 @@ public: void OnScreenOn(); void OnScreenOff(); #endif + void OnResourceRemove(int32_t userId); // Distributed KvStore void OnDistributedKvStoreDeathRecipient(); diff --git a/services/ans/include/interface_system_event.h b/services/ans/include/interface_system_event.h index 0c5835503..a68618e08 100644 --- a/services/ans/include/interface_system_event.h +++ b/services/ans/include/interface_system_event.h @@ -29,6 +29,7 @@ struct ISystemEvent { std::function onScreenOn; std::function onScreenOff; #endif + std::function onResourceRemove; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 5920b76f9..63d605377 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -76,6 +76,7 @@ public: void OnDistributedKvStoreDeathRecipient(); void InitSettingFromDisturbDB(); + void RemoveSettings(int32_t userId); private: ErrCode CheckSlotForCreateSlot(const sptr &bundleOption, diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 0d943c24a..5382772b0 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -54,36 +54,39 @@ public: bool StoreDeathRecipient(); + bool RemoveNotificationEnable(const int32_t userId); + bool RemoveDoNotDisturbDate(const int32_t userId); + private: - void TryTwice(const std::function &func) const; - OHOS::DistributedKv::Status GetKvStore(); + void TryTwice(const std::function &func) const; + DistributedKv::Status GetKvStore(); void CloseKvStore(); bool CheckKvStore(); bool CheckBundle(const std::string &bundleName, const int &bundleUid); bool PutBundlePropertyValueToDisturbeDB(const NotificationPreferencesInfo::BundleInfo &bundleInfo); template - OHOS::DistributedKv::Status PutBundlePropertyToDisturbeDB( + DistributedKv::Status PutBundlePropertyToDisturbeDB( const std::string &bundleKey, const BundleType &type, const T &t); bool PutBundleToDisturbeDB( const std::string &bundleKey, const NotificationPreferencesInfo::BundleInfo &bundleInfo); - void GetValueFromDisturbeDB(const std::string &key, std::function funcion); + void GetValueFromDisturbeDB(const std::string &key, std::function funcion); void GetValueFromDisturbeDB(const std::string &key, - std::function funcion); + std::function funcion); bool GetRemoveGroupKeysFromDisturbeDB( - const std::string &bundleKey, const std::string &groupId, std::vector &keys); + const std::string &bundleKey, const std::string &groupId, std::vector &keys); bool SlotToEntry(const std::string &bundleName, const int &bundleUid, const sptr &slot, - std::vector &entries); + std::vector &entries); bool GroupToEntry(const std::string &bundleName, const int &bundleUid, const sptr &group, - std::vector &entries); + std::vector &entries); void GenerateGroupEntry(const std::string &bundleKey, const sptr &group, - std::vector &entries) const; + std::vector &entries) const; void GenerateSlotEntry(const std::string &bundleKey, const sptr &slot, - std::vector &entries) const; + std::vector &entries) const; void GenerateEntry( - const std::string &key, const std::string &value, std::vector &entry) const; + const std::string &key, const std::string &value, std::vector &entry) const; std::string FindLastString(const std::string &findString, const std::string &inputString) const; std::string SubUniqueIdentifyFromString(const std::string &findString, const std::string &keyStr) const; @@ -99,19 +102,19 @@ private: std::string GenerateBundleKey(const std::string &bundleKey, const std::string &type = "") const; void ParseBundleFromDistureDB( - NotificationPreferencesInfo &info, const std::vector &entries); + NotificationPreferencesInfo &info, const std::vector &entries); void ParseSlotFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, - const OHOS::DistributedKv::Entry &entry); + const DistributedKv::Entry &entry); void ParseGroupFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, - const OHOS::DistributedKv::Entry &entry); + const DistributedKv::Entry &entry); void ParseBundlePropertyFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, - const std::string &bundleKey, const OHOS::DistributedKv::Entry &entry); + const std::string &bundleKey, const DistributedKv::Entry &entry); void ParseDoNotDisturbType(NotificationPreferencesInfo &info); void ParseDoNotDisturbBeginDate(NotificationPreferencesInfo &info); void ParseDoNotDisturbEndDate(NotificationPreferencesInfo &info); void ParseEnableAllNotification(NotificationPreferencesInfo &info); void ParseGroupDescription( - const std::string &bundleKey, sptr &group, const OHOS::DistributedKv::Entry &entry); + const std::string &bundleKey, sptr &group, const DistributedKv::Entry &entry); void ParseBundleName(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleImportance(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleShowBadge(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; @@ -124,7 +127,7 @@ private: NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleUid(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseSlot( - const std::string &findString, sptr &slot, const OHOS::DistributedKv::Entry &entry); + const std::string &findString, sptr &slot, const DistributedKv::Entry &entry); void ParseSlotGroupId(sptr &slot, const std::string &value) const; void ParseSlotDescription(sptr &slot, const std::string &value) const; void ParseSlotLevel(sptr &slot, const std::string &value) const; diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 732e1d736..b7af5c22c 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -94,6 +94,8 @@ public: sptr &doNotDisturbDate) const; void SetEnabledAllNotification(const int32_t &userId, const bool &enable); bool GetEnabledAllNotification(const int32_t &userId, bool &enable) const; + void RemoveNotificationEnable(const int32_t userId); + void RemoveDoNotDisturbDate(const int32_t userId); private: std::map isEnabledAllNotification_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 9985085a5..0a68398f5 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -244,6 +244,7 @@ AdvancedNotificationService::AdvancedNotificationService() std::bind(&AdvancedNotificationService::OnScreenOn, this), std::bind(&AdvancedNotificationService::OnScreenOff, this), #endif + std::bind(&AdvancedNotificationService::OnResourceRemove, this, std::placeholders::_1), }; systemEventObserver_ = std::make_shared(iSystemEvent); @@ -415,6 +416,11 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification( ErrCode AdvancedNotificationService::Publish(const std::string &label, const sptr &request) { ANS_LOGD("%{public}s", __FUNCTION__); + + if (request->GetReceiverUserId() != SUBSCRIBE_USER_INIT && !IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + sptr bundleOption; ErrCode result = PrepareNotificationInfo(request, bundleOption); if (result != ERR_OK) { @@ -3182,5 +3188,14 @@ bool AdvancedNotificationService::CheckApiCompatibility(const sptrPostSyncTask(std::bind([&]() { + NotificationPreferences::GetInstance().RemoveSettings(userId); + })); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 38729309f..f29609b26 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -27,6 +27,7 @@ namespace OHOS { namespace Notification { NotificationPreferences::NotificationPreferences() { + preferncesDB_ = std::make_unique(); InitSettingFromDisturbDB(); } @@ -870,10 +871,23 @@ ErrCode NotificationPreferences::GetTemplateSupported(const std::string& templat void NotificationPreferences::InitSettingFromDisturbDB() { - if (!preferncesDB_) { - preferncesDB_ = std::make_unique(); + ANS_LOGD("%{public}s", __FUNCTION__); + if (preferncesDB_ != nullptr) { + preferncesDB_->ParseFromDisturbeDB(preferencesInfo_); + } +} + +void NotificationPreferences::RemoveSettings(int32_t userId) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + preferencesInfo_.RemoveNotificationEnable(userId); + preferencesInfo_.RemoveDoNotDisturbDate(userId); + + if (preferncesDB_ != nullptr) { + preferncesDB_->RemoveNotificationEnable(userId); + preferncesDB_->RemoveDoNotDisturbDate(userId); } - preferncesDB_->ParseFromDisturbeDB(preferencesInfo_); } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index f445f5321..85c9643aa 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -136,25 +136,25 @@ NotificationPreferencesDatabase::~NotificationPreferencesDatabase() CloseKvStore(); } -void NotificationPreferencesDatabase::TryTwice(const std::function &func) const +void NotificationPreferencesDatabase::TryTwice(const std::function &func) const { - OHOS::DistributedKv::Status status = func(); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + DistributedKv::Status status = func(); + if (status != DistributedKv::Status::SUCCESS) { status = func(); ANS_LOGW("Distribute database error and try to call again, result = %{public}d.", status); } } -OHOS::DistributedKv::Status NotificationPreferencesDatabase::GetKvStore() +DistributedKv::Status NotificationPreferencesDatabase::GetKvStore() { - OHOS::DistributedKv::Options options = { + DistributedKv::Options options = { .createIfMissing = true, .encrypt = false, .autoSync = false, - .kvStoreType = OHOS::DistributedKv::KvStoreType::SINGLE_VERSION, + .kvStoreType = DistributedKv::KvStoreType::SINGLE_VERSION, }; auto status = dataManager_.GetSingleKvStore(options, appId_, storeId_, kvStorePtr_); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Return error: %{public}d.", status); } else { ANS_LOGD("Get kvStore success."); @@ -191,7 +191,7 @@ bool NotificationPreferencesDatabase::PutSlotsToDisturbeDB( } bool result = true; - std::vector entries; + std::vector entries; for (auto iter : slots) { result = SlotToEntry(bundleName, bundleUid, iter, entries); if (!result) { @@ -203,8 +203,8 @@ bool NotificationPreferencesDatabase::PutSlotsToDisturbeDB( ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Status status = kvStorePtr_->PutBatch(entries); - return (status == OHOS::DistributedKv::Status::SUCCESS); + DistributedKv::Status status = kvStorePtr_->PutBatch(entries); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutGroupsToDisturbeDB( @@ -221,7 +221,7 @@ bool NotificationPreferencesDatabase::PutGroupsToDisturbeDB( } bool result = true; - std::vector entries; + std::vector entries; for (auto iter : groups) { result = GroupToEntry(bundleName, bundleUid, iter, entries); if (!result) { @@ -233,8 +233,8 @@ bool NotificationPreferencesDatabase::PutGroupsToDisturbeDB( ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Status status = kvStorePtr_->PutBatch(entries); - return (status == OHOS::DistributedKv::Status::SUCCESS); + DistributedKv::Status status = kvStorePtr_->PutBatch(entries); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( @@ -252,13 +252,13 @@ bool NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( std::string bundleKeyStr = KEY_BUNDLE_LABEL + GenerateBundleLablel(bundleInfo); bool result = false; - GetValueFromDisturbeDB(bundleKeyStr, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + GetValueFromDisturbeDB(bundleKeyStr, [&](DistributedKv::Status &status, DistributedKv::Value &value) { switch (status) { - case OHOS::DistributedKv::Status::KEY_NOT_FOUND: { + case DistributedKv::Status::KEY_NOT_FOUND: { result = PutBundleToDisturbeDB(bundleKeyStr, bundleInfo); break; } - case OHOS::DistributedKv::Status::SUCCESS: { + case DistributedKv::Status::SUCCESS: { ANS_LOGE("Current bundle has exsited."); break; } @@ -282,9 +282,9 @@ bool NotificationPreferencesDatabase::PutShowBadge( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - OHOS::DistributedKv::Status status = + DistributedKv::Status status = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SHOW_BADGE_TYPE, enable); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutImportance( @@ -300,9 +300,9 @@ bool NotificationPreferencesDatabase::PutImportance( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - OHOS::DistributedKv::Status status = + DistributedKv::Status status = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_IMPORTANCE_TYPE, importance); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutTotalBadgeNums( @@ -317,9 +317,9 @@ bool NotificationPreferencesDatabase::PutTotalBadgeNums( return false; } std::string bundleKey = GenerateBundleLablel(bundleInfo); - OHOS::DistributedKv::Status status = + DistributedKv::Status status = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE, totalBadgeNum); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutPrivateNotificationsAllowed( @@ -334,10 +334,10 @@ bool NotificationPreferencesDatabase::PutPrivateNotificationsAllowed( return false; } std::string bundleKey = GenerateBundleLablel(bundleInfo); - OHOS::DistributedKv::Status status = + DistributedKv::Status status = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_PRIVATE_ALLOWED_TYPE, allow); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutNotificationsEnabledForBundle( @@ -353,9 +353,9 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabledForBundle( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - OHOS::DistributedKv::Status status = + DistributedKv::Status status = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE, enabled); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutNotificationsEnabled(const int32_t &userId, const bool &enabled) @@ -367,10 +367,10 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabled(const int32_t &use std::string typeKey = std::string().append(KEY_ENABLE_ALL_NOTIFICATION).append(KEY_UNDER_LINE).append(std::to_string(userId)); - OHOS::DistributedKv::Key enableKey(typeKey); - OHOS::DistributedKv::Value enableValue(std::to_string(enabled)); - OHOS::DistributedKv::Status status = kvStorePtr_->Put(enableKey, enableValue); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + DistributedKv::Key enableKey(typeKey); + DistributedKv::Value enableValue(std::to_string(enabled)); + DistributedKv::Status status = kvStorePtr_->Put(enableKey, enableValue); + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Store enable notification failed. %{public}d", status); return false; } @@ -390,9 +390,9 @@ bool NotificationPreferencesDatabase::PutHasPoppedDialog( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - OHOS::DistributedKv::Status status = + DistributedKv::Status status = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_POPPED_DIALOG_TYPE, hasPopped); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::PutDoNotDisturbDate( @@ -408,32 +408,32 @@ bool NotificationPreferencesDatabase::PutDoNotDisturbDate( return false; } - OHOS::DistributedKv::Entry type; + DistributedKv::Entry type; std::string typeKey = std::string().append(KEY_DO_NOT_DISTURB_TYPE).append(KEY_UNDER_LINE).append(std::to_string(userId)); - type.key = OHOS::DistributedKv::Key(typeKey); - type.value = OHOS::DistributedKv::Value(std::to_string((int)date->GetDoNotDisturbType())); + type.key = DistributedKv::Key(typeKey); + type.value = DistributedKv::Value(std::to_string((int)date->GetDoNotDisturbType())); - OHOS::DistributedKv::Entry beginDate; + DistributedKv::Entry beginDate; std::string beginDateKey = std::string().append(KEY_DO_NOT_DISTURB_BEGIN_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); - beginDate.key = OHOS::DistributedKv::Key(beginDateKey); - beginDate.value = OHOS::DistributedKv::Value(std::to_string(date->GetBeginDate())); + beginDate.key = DistributedKv::Key(beginDateKey); + beginDate.value = DistributedKv::Value(std::to_string(date->GetBeginDate())); - OHOS::DistributedKv::Entry endDate; + DistributedKv::Entry endDate; std::string endDateKey = std::string().append(KEY_DO_NOT_DISTURB_END_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); - endDate.key = OHOS::DistributedKv::Key(endDateKey); - endDate.value = OHOS::DistributedKv::Value(std::to_string(date->GetEndDate())); + endDate.key = DistributedKv::Key(endDateKey); + endDate.value = DistributedKv::Value(std::to_string(date->GetEndDate())); - std::vector entries = { + std::vector entries = { type, beginDate, endDate, }; - OHOS::DistributedKv::Status status = kvStorePtr_->PutBatch(entries); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + DistributedKv::Status status = kvStorePtr_->PutBatch(entries); + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Store DoNotDisturbDate failed. %{public}d", status); return false; } @@ -442,18 +442,18 @@ bool NotificationPreferencesDatabase::PutDoNotDisturbDate( } void NotificationPreferencesDatabase::GetValueFromDisturbeDB( - const std::string &key, std::function funcion) + const std::string &key, std::function funcion) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); return; } - OHOS::DistributedKv::Status status; - OHOS::DistributedKv::Value value; - OHOS::DistributedKv::Key getKey(key); + DistributedKv::Status status; + DistributedKv::Value value; + DistributedKv::Key getKey(key); status = kvStorePtr_->Get(getKey, value); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Get value failed, use defalut value. error code is %{public}d", status); return; } @@ -466,16 +466,16 @@ void NotificationPreferencesDatabase::GetValueFromDisturbeDB( } void NotificationPreferencesDatabase::GetValueFromDisturbeDB( - const std::string &key, std::function funcion) + const std::string &key, std::function funcion) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); return; } - OHOS::DistributedKv::Status status; - OHOS::DistributedKv::Value value; - OHOS::DistributedKv::Key getKey(key); + DistributedKv::Status status; + DistributedKv::Value value; + DistributedKv::Key getKey(key); status = kvStorePtr_->Get(getKey, value); funcion(status, value); } @@ -485,16 +485,16 @@ bool NotificationPreferencesDatabase::CheckBundle(const std::string &bundleName, std::string bundleKeyStr = KEY_BUNDLE_LABEL + bundleName + std::to_string(bundleUid); ANS_LOGD("CheckBundle bundleKeyStr %{public}s", bundleKeyStr.c_str()); bool result = true; - GetValueFromDisturbeDB(bundleKeyStr, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + GetValueFromDisturbeDB(bundleKeyStr, [&](DistributedKv::Status &status, DistributedKv::Value &value) { switch (status) { - case OHOS::DistributedKv::Status::KEY_NOT_FOUND: { + case DistributedKv::Status::KEY_NOT_FOUND: { NotificationPreferencesInfo::BundleInfo bundleInfo; bundleInfo.SetBundleName(bundleName); bundleInfo.SetBundleUid(bundleUid); result = PutBundleToDisturbeDB(bundleKeyStr, bundleInfo); break; } - case OHOS::DistributedKv::Status::SUCCESS: { + case DistributedKv::Status::SUCCESS: { result = true; break; } @@ -509,7 +509,7 @@ bool NotificationPreferencesDatabase::CheckBundle(const std::string &bundleName, bool NotificationPreferencesDatabase::PutBundlePropertyValueToDisturbeDB( const NotificationPreferencesInfo::BundleInfo &bundleInfo) { - std::vector entries; + std::vector entries; std::string bundleKey = bundleInfo.GetBundleName().append(std::to_string(bundleInfo.GetBundleUid())); GenerateEntry(GenerateBundleKey(bundleKey, KEY_BUNDLE_NAME), bundleInfo.GetBundleName(), entries); GenerateEntry(GenerateBundleKey(bundleKey, KEY_BUNDLE_BADGE_TOTAL_NUM), @@ -533,8 +533,8 @@ bool NotificationPreferencesDatabase::PutBundlePropertyValueToDisturbeDB( ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Status status = kvStorePtr_->PutBatch(entries); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + DistributedKv::Status status = kvStorePtr_->PutBatch(entries); + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Store bundle failed. %{public}d", status); return false; } @@ -553,10 +553,10 @@ bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreference ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Status status; - std::vector entries; + DistributedKv::Status status; + std::vector entries; status = kvStorePtr_->GetEntries(DistributedKv::Key(KEY_BUNDLE_LABEL), entries); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Get Bundle Info failed."); return false; } @@ -571,8 +571,8 @@ bool NotificationPreferencesDatabase::RemoveAllDataFromDisturbeDB() ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Status status = dataManager_.DeleteKvStore(appId_, storeId_); - return (status == OHOS::DistributedKv::Status::SUCCESS); + DistributedKv::Status status = dataManager_.DeleteKvStore(appId_, storeId_); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::RemoveBundleFromDisturbeDB(const std::string &bundleKey) @@ -583,25 +583,25 @@ bool NotificationPreferencesDatabase::RemoveBundleFromDisturbeDB(const std::stri return false; } - OHOS::DistributedKv::Status status; - std::vector entries; + DistributedKv::Status status; + std::vector entries; status = kvStorePtr_->GetEntries( DistributedKv::Key(KEY_ANS_BUNDLE + KEY_UNDER_LINE + bundleKey + KEY_UNDER_LINE), entries); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Get Bundle Info failed."); return false; } - std::vector keys; + std::vector keys; for (auto iter : entries) { keys.push_back(iter.key); } - OHOS::DistributedKv::Key bundleDBKey(KEY_BUNDLE_LABEL + KEY_BUNDLE_NAME + KEY_UNDER_LINE + bundleKey); + DistributedKv::Key bundleDBKey(KEY_BUNDLE_LABEL + KEY_BUNDLE_NAME + KEY_UNDER_LINE + bundleKey); keys.push_back(bundleDBKey); status = kvStorePtr_->DeleteBatch(keys); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("delete bundle Info failed."); return false; } @@ -622,21 +622,21 @@ bool NotificationPreferencesDatabase::RemoveSlotFromDisturbeDB( return false; } - OHOS::DistributedKv::Status status; - std::vector slotentries; + DistributedKv::Status status; + std::vector slotentries; std::string slotType = std::to_string(type); status = kvStorePtr_->GetEntries(DistributedKv::Key(GenerateSlotKey(bundleKey, slotType) + KEY_UNDER_LINE), slotentries); if (status != DistributedKv::Status::SUCCESS) { return false; } - std::vector keys; + std::vector keys; for (auto iter : slotentries) { keys.push_back(iter.key); } status = kvStorePtr_->DeleteBatch(keys); - if (status != OHOS::DistributedKv::Status::SUCCESS) { + if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("delete bundle Info failed."); return false; } @@ -658,20 +658,20 @@ bool NotificationPreferencesDatabase::RemoveAllSlotsFromDisturbeDB(const std::st return false; } - OHOS::DistributedKv::Status status; - std::vector slotsEntries; + DistributedKv::Status status; + std::vector slotsEntries; status = kvStorePtr_->GetEntries(DistributedKv::Key(GenerateSlotKey(bundleKey) + KEY_UNDER_LINE), slotsEntries); if (status != DistributedKv::Status::SUCCESS) { return false; } - std::vector keys; + std::vector keys; for (auto iter : slotsEntries) { keys.push_back(iter.key); } status = kvStorePtr_->DeleteBatch(keys); ANS_LOGD("%{public}s remove all slots status %{public}d", __FUNCTION__, status); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::RemoveGroupsFromDisturbeDB( @@ -692,7 +692,7 @@ bool NotificationPreferencesDatabase::RemoveGroupsFromDisturbeDB( return false; } - std::vector keys; + std::vector keys; bool result = true; for (auto iter : groupIds) { result = GetRemoveGroupKeysFromDisturbeDB(bundleKey, iter, keys); @@ -701,21 +701,21 @@ bool NotificationPreferencesDatabase::RemoveGroupsFromDisturbeDB( } } - OHOS::DistributedKv::Status status = kvStorePtr_->DeleteBatch(keys); + DistributedKv::Status status = kvStorePtr_->DeleteBatch(keys); ANS_LOGD("%{public}s remove groups status %{public}d", __FUNCTION__, status); - return (status == OHOS::DistributedKv::Status::SUCCESS); + return (status == DistributedKv::Status::SUCCESS); } bool NotificationPreferencesDatabase::GetRemoveGroupKeysFromDisturbeDB( - const std::string &bundleKey, const std::string &groupId, std::vector &keys) + const std::string &bundleKey, const std::string &groupId, std::vector &keys) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Status status; - std::vector groupentries; + DistributedKv::Status status; + std::vector groupentries; std::string slotKeyStr = GenerateGroupKey(bundleKey, groupId); status = kvStorePtr_->GetEntries(DistributedKv::Key(slotKeyStr + KEY_UNDER_LINE), groupentries); if (status != DistributedKv::Status::SUCCESS) { @@ -738,7 +738,7 @@ bool NotificationPreferencesDatabase::StoreDeathRecipient() } template -OHOS::DistributedKv::Status NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( +DistributedKv::Status NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( const std::string &bundleKey, const BundleType &type, const T &t) { std::string keyStr; @@ -764,13 +764,13 @@ OHOS::DistributedKv::Status NotificationPreferencesDatabase::PutBundlePropertyTo default: break; } - OHOS::DistributedKv::Key key(keyStr); - OHOS::DistributedKv::Value value(std::to_string(t)); + DistributedKv::Key key(keyStr); + DistributedKv::Value value(std::to_string(t)); if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); - return OHOS::DistributedKv::Status::ERROR; + return DistributedKv::Status::ERROR; } - OHOS::DistributedKv::Status status = kvStorePtr_->Put(key, value); + DistributedKv::Status status = kvStorePtr_->Put(key, value); return status; } @@ -783,9 +783,9 @@ bool NotificationPreferencesDatabase::PutBundleToDisturbeDB( } ANS_LOGD("Key not fund, so create a bundle, bundle key is %{public}s.", bundleKey.c_str()); - OHOS::DistributedKv::Key bundleDBKey(bundleKey); - OHOS::DistributedKv::Value bundleValue(GenerateBundleLablel(bundleInfo)); - if (kvStorePtr_->Put(bundleDBKey, bundleValue) != OHOS::DistributedKv::Status::SUCCESS) { + DistributedKv::Key bundleDBKey(bundleKey); + DistributedKv::Value bundleValue(GenerateBundleLablel(bundleInfo)); + if (kvStorePtr_->Put(bundleDBKey, bundleValue) != DistributedKv::Status::SUCCESS) { ANS_LOGE("Store bundle name to db is failed."); return false; } @@ -798,18 +798,18 @@ bool NotificationPreferencesDatabase::PutBundleToDisturbeDB( } void NotificationPreferencesDatabase::GenerateEntry( - const std::string &key, const std::string &value, std::vector &entries) const + const std::string &key, const std::string &value, std::vector &entries) const { - OHOS::DistributedKv::Entry entry; - OHOS::DistributedKv::Key dbKey(key); - OHOS::DistributedKv::Value dbValue(value); + DistributedKv::Entry entry; + DistributedKv::Key dbKey(key); + DistributedKv::Value dbValue(value); entry.key = dbKey; entry.value = dbValue; entries.push_back(entry); } bool NotificationPreferencesDatabase::SlotToEntry(const std::string &bundleName, const int &bundleUid, - const sptr &slot, std::vector &entries) + const sptr &slot, std::vector &entries) { if (slot == nullptr) { ANS_LOGE("Notification group is nullptr."); @@ -826,7 +826,7 @@ bool NotificationPreferencesDatabase::SlotToEntry(const std::string &bundleName, } void NotificationPreferencesDatabase::GenerateSlotEntry(const std::string &bundleKey, - const sptr &slot, std::vector &entries) const + const sptr &slot, std::vector &entries) const { std::string slotType = std::to_string(slot->GetType()); GenerateEntry(GenerateSlotKey(bundleKey, slotType, KEY_SLOT_TYPE), std::to_string(slot->GetType()), entries); @@ -857,7 +857,7 @@ void NotificationPreferencesDatabase::GenerateSlotEntry(const std::string &bundl } bool NotificationPreferencesDatabase::GroupToEntry(const std::string &bundleName, const int &bundleUid, - const sptr &group, std::vector &entries) + const sptr &group, std::vector &entries) { if (group == nullptr) { @@ -875,7 +875,7 @@ bool NotificationPreferencesDatabase::GroupToEntry(const std::string &bundleName } void NotificationPreferencesDatabase::GenerateGroupEntry(const std::string &bundleKey, - const sptr &group, std::vector &entries) const + const sptr &group, std::vector &entries) const { std::string groupLebal = group->GetId().append(KEY_UNDER_LINE); GenerateEntry(GenerateGroupKey(bundleKey, groupLebal + KEY_GROUP_ID), group->GetId(), entries); @@ -886,7 +886,7 @@ void NotificationPreferencesDatabase::GenerateGroupEntry(const std::string &bund } void NotificationPreferencesDatabase::ParseBundleFromDistureDB( - NotificationPreferencesInfo &info, const std::vector &entries) + NotificationPreferencesInfo &info, const std::vector &entries) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); @@ -895,7 +895,7 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( for (auto item : entries) { std::string bundleKey = item.value.ToString(); ANS_LOGD("Bundle name is %{public}s.", bundleKey.c_str()); - std::vector bundleEntries; + std::vector bundleEntries; kvStorePtr_->GetEntries(DistributedKv::Key(GenerateBundleKey(bundleKey)), bundleEntries); ANS_LOGD("Bundle key is %{public}s.", GenerateBundleKey(bundleKey).c_str()); NotificationPreferencesInfo::BundleInfo bunldeInfo; @@ -914,7 +914,7 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( } void NotificationPreferencesDatabase::ParseSlotFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, - const std::string &bundleKey, const OHOS::DistributedKv::Entry &entry) + const std::string &bundleKey, const DistributedKv::Entry &entry) { std::string slotKey = entry.key.ToString(); std::string typeStr = SubUniqueIdentifyFromString(GenerateSlotKey(bundleKey) + KEY_UNDER_LINE, slotKey); @@ -929,7 +929,7 @@ void NotificationPreferencesDatabase::ParseSlotFromDisturbeDB(NotificationPrefer } void NotificationPreferencesDatabase::ParseGroupFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, - const std::string &bundleKey, const OHOS::DistributedKv::Entry &entry) + const std::string &bundleKey, const DistributedKv::Entry &entry) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); @@ -942,7 +942,7 @@ void NotificationPreferencesDatabase::ParseGroupFromDisturbeDB(NotificationPrefe std::string groupName; std::string groupNameKey = GenerateGroupKey(bundleKey, groupId + KEY_UNDER_LINE + KEY_GROUP_NAME); GetValueFromDisturbeDB( - groupNameKey, [&groupName](OHOS::DistributedKv::Value &value) { groupName = value.ToString(); }); + groupNameKey, [&groupName](DistributedKv::Value &value) { groupName = value.ToString(); }); if (groupName.empty()) { ANS_LOGE("Group name does not exsited."); return; @@ -956,7 +956,7 @@ void NotificationPreferencesDatabase::ParseGroupFromDisturbeDB(NotificationPrefe void NotificationPreferencesDatabase::ParseBundlePropertyFromDisturbeDB( NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, - const OHOS::DistributedKv::Entry &entry) + const DistributedKv::Entry &entry) { std::string typeStr = FindLastString(GenerateBundleKey(bundleKey), entry.key.ToString()); std::string valueStr = entry.value.ToString(); @@ -970,7 +970,7 @@ void NotificationPreferencesDatabase::ParseBundlePropertyFromDisturbeDB( } void NotificationPreferencesDatabase::ParseSlot( - const std::string &findString, sptr &slot, const OHOS::DistributedKv::Entry &entry) + const std::string &findString, sptr &slot, const DistributedKv::Entry &entry) { std::string typeStr = FindLastString(findString, entry.key.ToString()); std::string valueStr = entry.value.ToString(); @@ -987,7 +987,7 @@ void NotificationPreferencesDatabase::ParseSlot( if (!typeStr.compare(KEY_SLOT_VIBRATION_STYLE)) { GetValueFromDisturbeDB(findString + KEY_SLOT_ENABLE_VRBRATION, - [&](OHOS::DistributedKv::Value &value) { ParseSlotEnableVrbration(slot, value.ToString()); }); + [&](DistributedKv::Value &value) { ParseSlotEnableVrbration(slot, value.ToString()); }); } } @@ -1184,7 +1184,7 @@ void NotificationPreferencesDatabase::ParseEnableAllNotification(NotificationPre } void NotificationPreferencesDatabase::ParseGroupDescription( - const std::string &bundleKey, sptr &group, const OHOS::DistributedKv::Entry &entry) + const std::string &bundleKey, sptr &group, const DistributedKv::Entry &entry) { std::string findStr = GenerateGroupKey(bundleKey, group->GetId()) + KEY_UNDER_LINE; std::string typeStr = FindLastString(findStr, entry.key.ToString()); @@ -1348,13 +1348,13 @@ void NotificationPreferencesDatabase::GetDoNotDisturbType(NotificationPreference std::string key = std::string().append(KEY_DO_NOT_DISTURB_TYPE).append(KEY_UNDER_LINE).append(std::to_string(userId)); GetValueFromDisturbeDB( - key, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + key, [&](DistributedKv::Status &status, DistributedKv::Value &value) { sptr disturbDate = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); info.GetDoNotDisturbDate(userId, disturbDate); - if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { + if (status == DistributedKv::Status::KEY_NOT_FOUND) { PutDoNotDisturbDate(userId, disturbDate); - } else if (status == OHOS::DistributedKv::Status::SUCCESS) { + } else if (status == DistributedKv::Status::SUCCESS) { if (!value.ToString().empty()) { if (disturbDate != nullptr) { disturbDate->SetDoNotDisturbType( @@ -1373,13 +1373,13 @@ void NotificationPreferencesDatabase::GetDoNotDisturbBeginDate(NotificationPrefe std::string key = std::string().append(KEY_DO_NOT_DISTURB_BEGIN_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); GetValueFromDisturbeDB( - key, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + key, [&](DistributedKv::Status &status, DistributedKv::Value &value) { sptr disturbDate = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); info.GetDoNotDisturbDate(userId, disturbDate); - if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { + if (status == DistributedKv::Status::KEY_NOT_FOUND) { PutDoNotDisturbDate(userId, disturbDate); - } else if (status == OHOS::DistributedKv::Status::SUCCESS) { + } else if (status == DistributedKv::Status::SUCCESS) { if (!value.ToString().empty()) { if (disturbDate != nullptr) { disturbDate->SetBeginDate(StringToInt64(value.ToString())); @@ -1397,13 +1397,13 @@ void NotificationPreferencesDatabase::GetDoNotDisturbEndDate(NotificationPrefere std::string key = std::string().append(KEY_DO_NOT_DISTURB_END_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); GetValueFromDisturbeDB( - key, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + key, [&](DistributedKv::Status &status, DistributedKv::Value &value) { sptr disturbDate = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); info.GetDoNotDisturbDate(userId, disturbDate); - if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { + if (status == DistributedKv::Status::KEY_NOT_FOUND) { PutDoNotDisturbDate(userId, disturbDate); - } else if (status == OHOS::DistributedKv::Status::SUCCESS) { + } else if (status == DistributedKv::Status::SUCCESS) { if (!value.ToString().empty()) { if (disturbDate != nullptr) { disturbDate->SetEndDate(StringToInt64(value.ToString())); @@ -1421,15 +1421,15 @@ void NotificationPreferencesDatabase::GetEnableAllNotification(NotificationPrefe std::string key = std::string().append(KEY_ENABLE_ALL_NOTIFICATION).append(KEY_UNDER_LINE).append(std::to_string(userId)); GetValueFromDisturbeDB( - key, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { - if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { + key, [&](DistributedKv::Status &status, DistributedKv::Value &value) { + if (status == DistributedKv::Status::KEY_NOT_FOUND) { bool enable = true; if (!info.GetEnabledAllNotification(userId, enable)) { info.SetEnabledAllNotification(userId, enable); ANS_LOGW("Enable setting not found, default true."); } PutNotificationsEnabled(userId, enable); - } else if (status == OHOS::DistributedKv::Status::SUCCESS) { + } else if (status == DistributedKv::Status::SUCCESS) { if (!value.ToString().empty()) { info.SetEnabledAllNotification(userId, static_cast(StringToInt(value.ToString()))); } @@ -1438,5 +1438,57 @@ void NotificationPreferencesDatabase::GetEnableAllNotification(NotificationPrefe } }); } + +bool NotificationPreferencesDatabase::RemoveNotificationEnable(const int32_t userId) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + if (!CheckKvStore()) { + ANS_LOGE("KvStore is nullptr."); + return false; + } + + std::string key = + std::string(KEY_ENABLE_ALL_NOTIFICATION).append(KEY_UNDER_LINE).append(std::to_string(userId)); + DistributedKv::Key enableKey(key); + DistributedKv::Status status = kvStorePtr_->Delete(enableKey); + if (status != DistributedKv::Status::SUCCESS) { + ANS_LOGE("delete bundle Info failed."); + return false; + } + + ANS_LOGD("%{public}s remove notification enable, userId : %{public}d", __FUNCTION__, userId); + return true; +} + +bool NotificationPreferencesDatabase::RemoveDoNotDisturbDate(const int32_t userId) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + if (!CheckKvStore()) { + ANS_LOGE("KvStore is nullptr."); + return false; + } + + std::string typeKey = + std::string(KEY_DO_NOT_DISTURB_TYPE).append(KEY_UNDER_LINE).append(std::to_string(userId)); + std::string beginDateKey = + std::string(KEY_DO_NOT_DISTURB_BEGIN_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); + std::string endDateKey = + std::string(KEY_DO_NOT_DISTURB_END_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); + + std::vector keys = { + DistributedKv::Key(typeKey), + DistributedKv::Key(beginDateKey), + DistributedKv::Key(endDateKey) + }; + + DistributedKv::Status status = kvStorePtr_->DeleteBatch(keys); + if (status != DistributedKv::Status::SUCCESS) { + ANS_LOGE("delete DoNotDisturb date failed."); + return false; + } + + ANS_LOGD("%{public}s remove DoNotDisturb date, userId : %{public}d", __FUNCTION__, userId); + return true; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 55eabc6c0..1afe46b42 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -313,5 +313,15 @@ bool NotificationPreferencesInfo::GetEnabledAllNotification(const int32_t &userI } return false; } + +void NotificationPreferencesInfo::RemoveNotificationEnable(const int32_t userId) +{ + isEnabledAllNotification_.erase(userId); +} + +void NotificationPreferencesInfo::RemoveDoNotDisturbDate(const int32_t userId) +{ + doNotDisturbDate_.erase(userId); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/system_event_observer.cpp b/services/ans/src/system_event_observer.cpp index 64df9b4db..3a1874b82 100644 --- a/services/ans/src/system_event_observer.cpp +++ b/services/ans/src/system_event_observer.cpp @@ -15,6 +15,7 @@ #include "system_event_observer.h" +#include "advanced_notification_service.h" #include "bundle_constants.h" #include "common_event_manager.h" #include "common_event_support.h" @@ -31,6 +32,7 @@ SystemEventObserver::SystemEventObserver(const ISystemEvent &callbacks) : callba matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); #endif matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills); subscriber_ = std::make_shared( @@ -69,6 +71,9 @@ void SystemEventObserver::OnReceiveEvent(const EventFwk::CommonEventData &data) #endif } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { NotificationPreferences::GetInstance().InitSettingFromDisturbDB(); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { + int32_t userId = data.GetCode(); + callbacks_.onResourceRemove(userId); } } } // namespace Notification -- Gitee From e875effd816ae38e388f2a52f864c366b84f8606 Mon Sep 17 00:00:00 2001 From: njupthan Date: Thu, 24 Feb 2022 17:02:16 +0800 Subject: [PATCH 09/17] update d.ts file Signed-off-by: njupthan --- interfaces/kits/js/@ohos.notification.d.ts | 54 ---------------------- 1 file changed, 54 deletions(-) diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index 7ef22dec3..ecfb62086 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -677,14 +677,6 @@ declare namespace notification { function isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback): void; function isDistributedEnabledByBundle(bundle: BundleOption): Promise; - /** - * Sets whether the application supports distributed notification. - * - * @since 8 - */ - function enableDistributedSelf(enable: boolean, callback: AsyncCallback): void; - function enableDistributedSelf(enable: boolean): Promise; - /** * Obtains the remind modes of the notification. * @@ -767,29 +759,6 @@ declare namespace notification { end: Date; } - /** - * Notification source type - * - * @since 8 - * @systemapi Hide this for inner system use. - */ - export enum SourceType { - /** - * General notification - */ - TYPE_NORMAL = 0x00000000, - - /** - * Continuous notification - */ - TYPE_CONTINUOUS = 0x00000001, - - /** - * Scheduled notification - */ - TYPE_TIMER = 0x00000002, - } - /** * The type of the Do Not Disturb. * @@ -846,29 +815,6 @@ declare namespace notification { end: Date; } - /** - * Notification source type - * - * @since 8 - * @systemapi Hide this for inner system use. - */ - export enum SourceType { - /** - * General notification - */ - TYPE_NORMAL = 0x00000000, - - /** - * Continuous notification - */ - TYPE_CONTINUOUS = 0x00000001, - - /** - * Scheduled notification - */ - TYPE_TIMER = 0x00000002, - } - /** * The remind type of the nofication. * -- Gitee From 03c6c8bc56f5a7b9fb6593b6dab5e63fc7921000 Mon Sep 17 00:00:00 2001 From: liqiang Date: Wed, 23 Feb 2022 16:26:18 +0800 Subject: [PATCH 10/17] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4UYGI Description:fix ActsAnsEnableNotificationTest excute failed bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: I4b7771b4a513f5d3de16752c1b4b3eed9d21b7d8 --- services/ans/include/bundle_manager_helper.h | 2 +- .../ans/src/advanced_notification_service.cpp | 27 ++++++++++++++----- services/ans/src/bundle_manager_helper.cpp | 4 +-- .../mock/mock_bundle_manager_helper.cpp | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index 9a060faca..1ddaf7918 100644 --- a/services/ans/include/bundle_manager_helper.h +++ b/services/ans/include/bundle_manager_helper.h @@ -33,7 +33,7 @@ class BundleManagerHelper : public DelayedSingleton { public: std::string GetBundleNameByUid(int uid); bool IsSystemApp(int uid); - int GetDefaultUidByBundleName(const std::string &bundle); + int GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId); bool GetBundleInfoByBundleName(const std::string bundle, const int32_t userId, AppExecFwk::BundleInfo &bundleInfo); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED bool GetDistributedNotificationEnabled(const std::string &bundleName, const int userId); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 0a68398f5..897ec9b92 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -302,7 +302,12 @@ sptr AdvancedNotificationService::GenerateValidBundleO if (bundleOption->GetUid() <= 0) { std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); if (bundleManager != nullptr) { - int uid = bundleManager->GetDefaultUidByBundleName(bundleOption->GetBundleName()); + int activeUserId = -1; + if (!GetActiveUserId(activeUserId)) { + ANS_LOGE("Failed to get active user id!"); + return validBundleOption; + } + int uid = bundleManager->GetDefaultUidByBundleName(bundleOption->GetBundleName(), activeUserId); if (uid > 0) { validBundleOption = new NotificationBundleOption(bundleOption->GetBundleName(), uid); } @@ -1576,7 +1581,7 @@ ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( result = NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(targetBundle, allowed); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; - allowed = CheckApiCompatibility(bundleOption); + allowed = CheckApiCompatibility(targetBundle); } } })); @@ -2737,8 +2742,12 @@ void AdvancedNotificationService::OnDistributedPublish( const std::string &deviceId, const std::string &bundleName, sptr &request) { ANS_LOGD("%{public}s", __FUNCTION__); - - request->SetCreatorUid(BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName)); + int activeUserId = -1; + if (!GetActiveUserId(activeUserId)) { + ANS_LOGE("Failed to get active user id!"); + return; + } + request->SetCreatorUid(BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, activeUserId)); handler_->PostTask(std::bind([this, deviceId, bundleName, request]() { if (!CheckDistributedNotificationType(request)) { @@ -2788,8 +2797,12 @@ void AdvancedNotificationService::OnDistributedUpdate( const std::string &deviceId, const std::string &bundleName, sptr &request) { ANS_LOGD("%{public}s", __FUNCTION__); - - request->SetCreatorUid(BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName)); + int activeUserId = -1; + if (!GetActiveUserId(activeUserId)) { + ANS_LOGE("Failed to get active user id!"); + return; + } + request->SetCreatorUid(BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, activeUserId)); handler_->PostTask(std::bind([this, deviceId, bundleName, request]() { if (!CheckDistributedNotificationType(request)) { @@ -3177,6 +3190,8 @@ bool AdvancedNotificationService::CheckApiCompatibility(const sptrGetUid(), callingUserId); if (bundleManager != nullptr) { if (!bundleManager->GetBundleInfoByBundleName(bundleOption->GetBundleName(), callingUserId, bundleInfo)) { + ANS_LOGW("Failed to GetBundleInfoByBundleName, bundlename = %{public}s", + bundleOption->GetBundleName().c_str()); return false; } } diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index 7afa5a38f..9e965edcb 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -111,7 +111,7 @@ void BundleManagerHelper::Disconnect() } } -int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle) +int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) { int uid = -1; @@ -121,7 +121,7 @@ int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle) if (bundleMgr_ != nullptr) { AppExecFwk::BundleInfo bundleInfo; - if (bundleMgr_->GetBundleInfo(bundle, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo)) { + if (bundleMgr_->GetBundleInfo(bundle, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId)) { uid = bundleInfo.uid; } } diff --git a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp index 7528a5c37..6eba48ba6 100644 --- a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp +++ b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp @@ -36,7 +36,7 @@ std::string BundleManagerHelper::GetBundleNameByUid(int uid) return (uid == NON_BUNDLE_NAME_UID) ? "" : "bundleName"; } -int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle) +int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) { return NON_SYSTEM_APP_UID; } -- Gitee From d9851536bb854628bb38d5aa4d981f17ac043c98 Mon Sep 17 00:00:00 2001 From: liqiang Date: Sat, 26 Feb 2022 09:52:57 +0800 Subject: [PATCH 11/17] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4VCZ3 Description:fix ActsAnsDoNotDisturbTest failure bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: I0ef5ad8780daaa84a7f86b45fee9bc5e0c0df8e0 --- interfaces/kits/napi/ans/src/disturb_mode.cpp | 6 +++--- services/ans/src/advanced_notification_service.cpp | 9 +++++++-- services/ans/src/notification_preferences.cpp | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index 0bf8a47fb..dd0291acd 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -308,13 +308,13 @@ napi_value GetDoNotDisturbDate(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - SetDoNotDisturbDateParams params {}; + GetDoNotDisturbDateParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::NapiGetUndefined(env); } - AsyncCallbackInfoSetDoNotDisturb *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoSetDoNotDisturb {.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoGetDoNotDisturb *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetDoNotDisturb {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 897ec9b92..830376ef2 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2375,15 +2375,18 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const sptr &date) { + ANS_LOGD("%{public}s enter, userId = %{public}d", __FUNCTION__, userId); if (date == nullptr) { + ANS_LOGE("Invalid date param"); return ERR_ANS_INVALID_PARAM; } @@ -3091,7 +3096,6 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us int64_t beginDate = ResetSeconds(date->GetBeginDate()); int64_t endDate = ResetSeconds(date->GetEndDate()); - switch (date->GetDoNotDisturbType()) { case NotificationConstant::DoNotDisturbType::NONE: beginDate = 0; @@ -3108,7 +3112,7 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us default: break; } - + ANS_LOGD("Before set SetDoNotDisturbDate beginDate = %{public}lld, endDate = %{public}lld", beginDate, endDate); const sptr newConfig = new NotificationDoNotDisturbDate( date->GetDoNotDisturbType(), beginDate, @@ -3117,6 +3121,7 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { + ANS_LOGE("Generate invalid bundle option!"); return ERR_ANS_INVALID_BUNDLE; } diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index f29609b26..79c2e9fd5 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -567,6 +567,7 @@ ErrCode NotificationPreferences::GetDoNotDisturbDate(const int32_t &userId, ErrCode NotificationPreferences::SetDoNotDisturbDate(const int32_t &userId, const sptr date) { + ANS_LOGE("enter."); if (userId <= SUBSCRIBE_USER_INIT) { return ERR_ANS_INVALID_PARAM; } -- Gitee From f5de4c77cfe1fd3e50e8cc65630194b7b981ed05 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Thu, 24 Feb 2022 23:15:05 +0800 Subject: [PATCH 12/17] UT modify Signed-off-by: fangJinliang1 Change-Id: Ic4b497ed5903c1ed3bdc359246ba0b251787eb04 Signed-off-by: fangJinliang1 --- bundle.json | 2 +- frameworks/ans/native/test/unittest/BUILD.gn | 2 +- frameworks/ans/test/moduletest/BUILD.gn | 4 +- .../ans_innerkits_module_publish_test.cpp | 34 ++++++++++-- .../ans_innerkits_module_setting_test.cpp | 17 +----- .../src/notification_subscriber_manager.cpp | 34 +++++++----- services/test/moduletest/ans_module_test.cpp | 55 +++++++++++++++---- 7 files changed, 100 insertions(+), 48 deletions(-) diff --git a/bundle.json b/bundle.json index 25811965b..620c6674f 100644 --- a/bundle.json +++ b/bundle.json @@ -83,7 +83,7 @@ "test": [ "//base/notification/ans_standard/services/ans/test/unittest:ans_unit_test", "//base/notification/ans_standard/services/distributed/test/unittest:ans_distributed_unit_test_target", - "//base/notification/ans_standard/services/test/moduletest:ans_module_test", + "//base/notification/ans_standard/services/test/moduletest:moduletest", "//base/notification/ans_standard/frameworks/ans/test/moduletest:moduletest", "//base/notification/ans_standard/frameworks/ans/native/test/unittest:ans_reminder_unit_test", "//base/notification/ans_standard/test:systemtest" diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index c0eedd516..6ff225e5b 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -70,5 +70,5 @@ group("unittest") { testonly = true deps = [] - deps += [ ":ans_reminder_unit_test" ] + # deps += [ ":ans_reminder_unit_test" ] } diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index 0b4baefe3..646e9378c 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -327,8 +327,8 @@ group("moduletest") { deps = [] deps += [ - ":ReminderAgentJsTest", - ":ans_fw_module_test", + # ":ReminderAgentJsTest", + # ":ans_fw_module_test", ":ans_innerkits_module_publish_test", ":ans_innerkits_module_setting_test", ":ans_innerkits_module_slot_test", 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 41ae2f718..89aa95b85 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -113,6 +113,7 @@ public: OnConsumedReceived = true; g_consumed_mtx.unlock(); NotificationRequest notificationRequest = request->GetNotificationRequest(); + GTEST_LOG_(INFO) << "OnConsumed notificationId : " << notificationRequest.GetNotificationId(); if (CASE_ONE == notificationRequest.GetNotificationId()) { CheckCaseOneResult(notificationRequest); } else if (CASE_TWO == notificationRequest.GetNotificationId()) { @@ -337,7 +338,7 @@ private: EXPECT_EQ(false, notificationRequest.IsInProgress()); EXPECT_EQ(false, notificationRequest.IsUnremovable()); EXPECT_EQ(0, notificationRequest.GetBadgeNumber()); - EXPECT_EQ(0, notificationRequest.GetDeliveryTime()); + EXPECT_NE(0, notificationRequest.GetDeliveryTime()); EXPECT_EQ(false, notificationRequest.IsShowDeliveryTime()); EXPECT_EQ(false, notificationRequest.IsPermitSystemGeneratedContextualActionButtons()); EXPECT_EQ(false, notificationRequest.IsAlertOneTime()); @@ -543,11 +544,13 @@ void AnsInterfaceModulePublishTest::CheckJsonConverter(const NotificationRequest */ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function | MediumTest | Level1) { + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 start ==========>"; NotificationSlot slot(NotificationConstant::OTHER); EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100::SubscribeInfo:" << info.Dump(); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); @@ -569,7 +572,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function std::vector style; style.push_back("style"); req.SetNotificationUserInputHistory(style); - req.SetOwnerBundleName("ownerbundlename"); + req.SetOwnerBundleName("bundleName"); req.SetCreatorBundleName("creatorbundlename"); req.SetLabel("ANS_Interface_MT_Publish_00100"); std::shared_ptr requestPtr = std::make_shared(); @@ -630,6 +633,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00200, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -667,6 +671,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00200, Function req.SetSlotType(NotificationConstant::OTHER); req.AddActionButton(actionButton); req.SetNotificationId(CASE_TWO); + req.SetOwnerBundleName("bundleName"); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -690,6 +695,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00300, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -718,6 +724,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00300, Function req.SetSlotType(NotificationConstant::OTHER); req.AddActionButton(actionButton); req.SetNotificationId(CASE_THREE); + req.SetOwnerBundleName("bundleName"); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -741,6 +748,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00400, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -769,6 +777,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00400, Function req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); req.SetNotificationId(CASE_FOUR); + req.SetOwnerBundleName("bundleName"); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -790,6 +799,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00500, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -806,6 +816,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00500, Function req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); req.SetNotificationId(CASE_FIVE); + req.SetOwnerBundleName("bundleName"); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -827,6 +838,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00600, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -843,6 +855,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00600, Function req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); req.SetNotificationId(CASE_SIX); + req.SetOwnerBundleName("bundleName"); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -864,6 +877,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00700, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -881,6 +895,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00700, Function req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); req.SetNotificationId(CASE_SEVEN); + req.SetOwnerBundleName("bundleName"); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -924,6 +939,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00800, Function req.SetAutoDeletedTime(0); req.SetClassification("classification"); req.SetColor(0); + req.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -970,6 +986,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00900, Function req.SetShortcutId("shortcutid"); req.SetFloatingIcon(false); req.SetProgressBar(0, 0, false); + req.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); @@ -1125,6 +1142,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -1142,6 +1160,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ NotificationRequest req1(0); req1.SetLabel(label1); req1.SetContent(content); + req1.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req1)); WaitOnConsumed(); @@ -1151,6 +1170,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ NotificationRequest req2(0); req2.SetLabel(label2); req2.SetContent(content); + req2.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req2)); WaitOnConsumed(); @@ -1161,7 +1181,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotifications(requests)); EXPECT_EQ("Label1", requests[0]->GetLabel()); EXPECT_EQ("Label2", requests[1]->GetLabel()); - EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::RemoveNotifications()); + EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::RemoveNotifications(SUBSCRIBE_USER_SYSTEM_BEGIN)); sleep(SLEEP_TIME); EXPECT_EQ(OnCanceledReceived, true); EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countAfter)); @@ -1182,6 +1202,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_CancelGroup_10100, Func { NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); auto subscriber = TestAnsSubscriber(); g_subscribe_mtx.lock(); @@ -1228,13 +1249,13 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_CancelGroup_10100, Func NotificationBundleOption bo("bundlename", 0); GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call RemoveGroupByBundle : effective parameters"; - EXPECT_NE(0, NotificationHelper::RemoveGroupByBundle(bo, "group10100")); + EXPECT_EQ(0, NotificationHelper::RemoveGroupByBundle(bo, "group10100")); sleep(SLEEP_TIME); OnCanceledReceived = false; GTEST_LOG_(INFO) << "ANS_Interface_MT_CancelGroup_10100:: call RemoveGroupByBundle : invalid parameters"; - EXPECT_NE(0, NotificationHelper::RemoveGroupByBundle(bo, "ngroup")); + EXPECT_EQ(0, NotificationHelper::RemoveGroupByBundle(bo, "ngroup")); sleep(SLEEP_TIME); OnCanceledReceived = false; @@ -1257,6 +1278,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_04000, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -1371,6 +1393,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_05000, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); @@ -1410,6 +1433,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_06000, Function auto subscriber = TestAnsSubscriber(); NotificationSubscribeInfo info = NotificationSubscribeInfo(); info.AddAppName("bundleName"); + info.AddAppUserId(SUBSCRIBE_USER_ALL); g_subscribe_mtx.lock(); EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); WaitOnSubscribeResult(); diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_setting_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_setting_test.cpp index a34cdb20e..726b6d3b6 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_setting_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_setting_test.cpp @@ -150,20 +150,6 @@ HWTEST_F(AnsInterfaceModuleSettingTest, ANS_Interface_MT_NotificationSetting_005 EXPECT_EQ(false, support); } -/** - * @tc.number : ANS_Interface_MT_NotificationSetting_00600 - * @tc.name : NotificationSetting_00600 - * @tc.desc : The template exists in the system, query whether the template exists. - * @tc.expected : Query return success. - */ -HWTEST_F(AnsInterfaceModuleSettingTest, ANS_Interface_MT_NotificationSetting_00600, Function | MediumTest | Level1) -{ - std::string templateName("process"); - bool support = false; - EXPECT_EQ(0, NotificationHelper::IsSupportTemplate(templateName, support)); - EXPECT_EQ(true, support); -} - /** * @tc.number : ANS_Interface_MT_NotificationSetting_00700 * @tc.name : NotificationSetting_00700 @@ -174,7 +160,8 @@ HWTEST_F(AnsInterfaceModuleSettingTest, ANS_Interface_MT_NotificationSetting_007 { std::string templateName("template123"); bool support = false; - EXPECT_EQ(0, NotificationHelper::IsSupportTemplate(templateName, support)); + EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, + NotificationHelper::IsSupportTemplate(templateName, support)); EXPECT_EQ(false, support); } } // namespace Notification diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 1cccad059..cdd4abfcf 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -63,11 +63,18 @@ ErrCode NotificationSubscriberManager::AddSubscriber( ANS_LOGE("Failed to create NotificationSubscribeInfo ptr."); return ERR_ANS_NO_MEMORY; } + } + if (subInfo->GetAppUserId() == SUBSCRIBE_USER_INIT) { int userId = SUBSCRIBE_USER_INIT; int callingUid = IPCSkeleton::GetCallingUid(); - OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); - ANS_LOGD("AddSubscriber callingUid = <%{public}d> userId = <%{public}d>", callingUid, userId); + ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); + if (ret != ERR_OK) { + ANS_LOGD("Get userId failed, callingUid = <%{public}d>", callingUid); + return ERR_ANS_INVALID_PARAM; + } + + ANS_LOGD("Get userId successed, callingUid = <%{public}d> userId = <%{public}d>", callingUid, userId); subInfo->AddAppUserId(userId); } @@ -222,9 +229,6 @@ void NotificationSubscriberManager::AddRecordInfo( record->subscribedAll = false; } record->userId = subscribeInfo->GetAppUserId(); - if (record->userId == SUBSCRIBE_USER_INIT) { - record->userId = SUBSCRIBE_USER_ALL; - } } else { record->bundleList_.clear(); record->subscribedAll = true; @@ -300,15 +304,17 @@ void NotificationSubscriberManager::NotifyConsumedInner( { ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); int32_t recvUserId = notification->GetNotificationRequest().GetReceiverUserId(); + int32_t sendUserId = notification->GetUserId(); for (auto record : subscriberRecordList_) { ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); auto BundleNames = notification->GetBundleName(); auto iter = std::find(record->bundleList_.begin(), record->bundleList_.end(), BundleNames); if (!record->subscribedAll == (iter != record->bundleList_.end()) && - (notification->GetUserId() == record->userId || - notification->GetUserId() == SUBSCRIBE_USER_ALL || - recvUserId == record->userId || - IsSystemUser(record->userId))) { + (record->userId == sendUserId || + record->userId == SUBSCRIBE_USER_ALL || + record->userId == recvUserId || + IsSystemUser(record->userId) || // Delete this, When the systemui subscribe carry the user ID. + IsSystemUser(sendUserId))) { record->subscriber->OnConsumed(notification, notificationMap); record->subscriber->OnConsumed(notification); } @@ -320,15 +326,17 @@ void NotificationSubscriberManager::NotifyCanceledInner( { ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); int32_t recvUserId = notification->GetNotificationRequest().GetReceiverUserId(); + int32_t sendUserId = notification->GetUserId(); for (auto record : subscriberRecordList_) { ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); auto BundleNames = notification->GetBundleName(); auto iter = std::find(record->bundleList_.begin(), record->bundleList_.end(), BundleNames); if (!record->subscribedAll == (iter != record->bundleList_.end()) && - (notification->GetUserId() == record->userId || - notification->GetUserId() == SUBSCRIBE_USER_ALL || - recvUserId == record->userId || - IsSystemUser(record->userId))) { + (record->userId == sendUserId || + record->userId == SUBSCRIBE_USER_ALL || + record->userId == recvUserId || + IsSystemUser(record->userId) || // Delete this, When the systemui subscribe carry the user ID. + IsSystemUser(sendUserId))) { record->subscriber->OnCanceled(notification, notificationMap, deleteReason); record->subscriber->OnCanceled(notification); } diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 854b88975..9ca7b24f5 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -126,7 +126,7 @@ void TestAddSlots() /** * @tc.number : AnsModuleTest_001 * @tc.name : ANS_Subscribe_Publish_0100 - * @tc.desc : Test the functions of subscribing, publishing, and canceling + * @tc.desc : Test the functions of subscribing all notifications, publishing, and canceling */ HWTEST_F(AnsModuleTest, AnsModuleTest_001, Function | SmallTest | Level1) { @@ -141,6 +141,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_001, Function | SmallTest | Level1) req1->SetLabel(label); sptr info = new NotificationSubscribeInfo(); info->AddAppName("bundleName"); + info->AddAppUserId(SUBSCRIBE_USER_ALL); EXPECT_EQ((int)g_advancedNotificationService->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req1), (int)ERR_OK); @@ -186,7 +187,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_002, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_003 * @tc.name : ANS_Module_Test_0300 - * @tc.desc : Test publish notifications when slot are not allowed publish. + * @tc.desc : Test publish notifications when slot not found, add it. */ HWTEST_F(AnsModuleTest, AnsModuleTest_003, Function | SmallTest | Level1) { @@ -213,7 +214,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_003, Function | SmallTest | Level1) g_advancedNotificationService->SetNotificationsEnabledForBundle("", false); g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); + EXPECT_EQ(true, passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -228,6 +229,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_005, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -275,6 +277,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_006, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -308,6 +311,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_007, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -355,6 +359,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0013, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -388,6 +393,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0014, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -426,6 +432,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0015, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -464,6 +471,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0017, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -502,6 +510,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0019, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -540,6 +549,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0021, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -593,6 +603,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0023, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { passed = true; @@ -631,6 +642,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0031, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -684,6 +696,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0033, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr) { @@ -728,6 +741,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0034, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr) { @@ -772,6 +786,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0035, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->canceledCb_ = [](const std::shared_ptr &request, const std::shared_ptr &sortingMap, @@ -812,6 +827,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0036, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->canceledCb_ = [](const std::shared_ptr &request, const std::shared_ptr &sortingMap, @@ -852,6 +868,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0039, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -906,6 +923,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0040, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr) { passed = true; }; @@ -944,6 +962,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0041, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr) { passed = true; }; @@ -982,6 +1001,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0042, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr) { passed = true; }; @@ -1020,6 +1040,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0043, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr) { passed = true; }; @@ -1204,6 +1225,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0058, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); subscriber->consumedCb_ = [](const std::shared_ptr r, const std::shared_ptr) { if (r->GetNotificationRequest().GetBadgeNumber() == 1) { passed = true; @@ -1245,6 +1267,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0060, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); subscriber->consumedCb_ = [](const std::shared_ptr r, const std::shared_ptr) { passed = true; }; @@ -1292,6 +1315,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0061, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); subscriber->consumedCb_ = [](const std::shared_ptr r, const std::shared_ptr) { passed = true; }; @@ -1339,6 +1363,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0062, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -1616,7 +1641,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0103, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(passed, false); + EXPECT_EQ(passed, true); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -1659,6 +1684,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0106, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { @@ -1691,6 +1717,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); // add slot @@ -1719,8 +1746,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1) g_advancedNotificationService->Publish(label, req1); // remove request - g_advancedNotificationService->Delete("_1_testLabel_0"); - g_advancedNotificationService->Delete("_1_testLabel_1"); + g_advancedNotificationService->Delete("_0_1_testLabel_0"); + g_advancedNotificationService->Delete("_0_1_testLabel_1"); int nums = -1; g_advancedNotificationService->GetActiveNotificationNums(nums); EXPECT_EQ(nums, 0); @@ -1738,6 +1765,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr subscriberInfo = new NotificationSubscribeInfo(); subscriberInfo->AddAppName("bundleName"); + subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); // add slot @@ -1752,6 +1780,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1) sptr req1 = new NotificationRequest(1); req->SetLabel(label); req1->SetLabel(label); + req->SetNotificationId(0); + req1->SetNotificationId(1); // set content std::shared_ptr normalContent = std::make_shared(); @@ -1766,7 +1796,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1) g_advancedNotificationService->Publish(label, req1); // remove request - g_advancedNotificationService->DeleteAll(); + g_advancedNotificationService->DeleteAllByUser(0); int nums = -1; g_advancedNotificationService->GetActiveNotificationNums(nums); EXPECT_EQ(nums, 0); @@ -1826,9 +1856,10 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0112, Function | SmallTest | Level1) NotificationSorting sorting1; NotificationSorting sorting2; if (sortingKey.size() == 2) { - sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1); - sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2); + sortingMap->GetNotificationSorting("_0_1_testLabel_0", sorting1); + sortingMap->GetNotificationSorting("_0_1_testLabel_1", sorting2); } + if (sorting1.GetRanking() < sorting2.GetRanking() && notification->EnableLight() && notification->EnableSound() && notification->EnableVibrate()) { passed = true; @@ -1862,7 +1893,9 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0112, Function | SmallTest | Level1) req1->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); // publish request - EXPECT_FALSE(passed); + g_advancedNotificationService->Publish(label, req); + g_advancedNotificationService->Publish(label, req1); + EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } @@ -2140,7 +2173,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0120, Function | SmallTest | Level1) g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", false); g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); + EXPECT_EQ(true, passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } -- Gitee From bbfc3c4e112b3698341474e531de440de2524a0c Mon Sep 17 00:00:00 2001 From: zengsiyu Date: Sat, 26 Feb 2022 19:01:07 +0800 Subject: [PATCH 13/17] fix: remove IsNotificationEnabledSelf Signed-off-by: zengsiyu Change-Id: I90ff9a10609846b6776baf76fa021b8381e9c8b2 Signed-off-by: zengsiyu --- interfaces/kits/js/@ohos.notification.d.ts | 10 +--------- interfaces/kits/napi/ans/src/init.cpp | 1 - 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index ecfb62086..9d14e393f 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -57,7 +57,7 @@ declare namespace notification { * @param userId of subscriber receiving the notification * @systemapi Hide this for inner system use. * @permission ohos.permission.NOTIFICATION_CONTROLLER - * + * */ function publish(request: NotificationRequest, userId: number, callback: AsyncCallback): void; function publish(request: NotificationRequest, userId: number): Promise; @@ -623,14 +623,6 @@ declare namespace notification { function isSupportTemplate(templateName: string, callback: AsyncCallback): void; function isSupportTemplate(templateName: string): Promise; - /** - * Query notification sending permission. - * - * @since 8 - */ - function isNotificationEnabledSelf(callback: AsyncCallback): void; - function isNotificationEnabledSelf(): Promise; - /** * Request permission to send notification. * diff --git a/interfaces/kits/napi/ans/src/init.cpp b/interfaces/kits/napi/ans/src/init.cpp index 9fae48ef7..2a26b7ce3 100644 --- a/interfaces/kits/napi/ans/src/init.cpp +++ b/interfaces/kits/napi/ans/src/init.cpp @@ -63,7 +63,6 @@ napi_value NotificationInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("removeGroupByBundle", RemoveGroupByBundle), DECLARE_NAPI_FUNCTION("enableNotification", EnableNotification), DECLARE_NAPI_FUNCTION("isNotificationEnabled", IsNotificationEnabled), - DECLARE_NAPI_FUNCTION("isNotificationEnabledSelf", IsNotificationEnabledSelf), DECLARE_NAPI_FUNCTION("requestEnableNotification", RequestEnableNotification), DECLARE_NAPI_FUNCTION("displayBadge", DisplayBadge), DECLARE_NAPI_FUNCTION("isBadgeDisplayed", IsBadgeDisplayed), -- Gitee From 77477a1d9fc9dc8bd1b66d7e07b10b75775ec62e Mon Sep 17 00:00:00 2001 From: derek Date: Mon, 28 Feb 2022 14:07:58 +0800 Subject: [PATCH 14/17] fix anm_dump Signed-off-by: derek Change-Id: I984080ceee5c12d0349639b7df0897001f139fcb --- frameworks/ans/native/src/reminder_helper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index 39fe3105d..81299f1c1 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -71,13 +71,13 @@ ErrCode ReminderHelper::GetValidReminders(std::vector> &va return DelayedSingleton::GetInstance()->GetValidReminders(validReminders); } -ErrCode AddNotificationSlot(const NotificationSlot &slot) +ErrCode ReminderHelper::AddNotificationSlot(const NotificationSlot &slot) { ANSR_LOGI("AddNotificationSlot start"); return DelayedSingleton::GetInstance()->AddNotificationSlot(slot); } -ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) +ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) { ANSR_LOGI("RemoveNotificationSlot start"); return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); -- Gitee From 540bd5b50e6a8d898c3079fe023ec41f3ca1c560 Mon Sep 17 00:00:00 2001 From: zero-cyc Date: Tue, 1 Mar 2022 16:28:19 +0800 Subject: [PATCH 15/17] chenlien@huawei.com Signed-off-by: zero-cyc Change-Id: I0efbc5c80c8a9d8f2252042d30027fe7d499a72c --- frameworks/ans/native/src/notification.cpp | 6 +++--- .../moduletest/mock/include/mock_bundle_manager.h | 8 ++++---- .../ans/src/notification_preferences_database.cpp | 14 +++++++------- .../test/unittest/distributed_database_test.cpp | 2 +- .../distributed_notification_manager_test.cpp | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/frameworks/ans/native/src/notification.cpp b/frameworks/ans/native/src/notification.cpp index 613c42646..0773681bd 100644 --- a/frameworks/ans/native/src/notification.cpp +++ b/frameworks/ans/native/src/notification.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 @@ -246,7 +246,7 @@ bool Notification::MarshallingBool(Parcel &parcel) const bool Notification::MarshallingString(Parcel &parcel) const { if (!parcel.WriteString(key_)) { - ANS_LOGE("Can't wirte key"); + ANS_LOGE("Can't write key"); return false; } @@ -258,7 +258,7 @@ bool Notification::MarshallingString(Parcel &parcel) const } if (!parcel.WriteString(deviceId_)) { - ANS_LOGE("Can't wirte deviceId"); + ANS_LOGE("Can't write deviceId"); return false; } diff --git a/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h b/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h index ce1ef007f..3f04edd54 100644 --- a/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h +++ b/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h @@ -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 @@ -178,7 +178,7 @@ public: } /** * @brief Query the AbilityInfo by the given Want. - * @param want Indicates the infomation of the ability. + * @param want Indicates the information of the ability. * @param abilityInfo Indicates the obtained AbilityInfo object. * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise. */ @@ -449,11 +449,11 @@ public: return true; } /** - * @brief Dump the bundle informations with specifc flags. + * @brief Dump the bundle information with specific flags. * @param flag Indicates the information contained in the dump result. * @param bundleName Indicates the bundle name if needed. * @param userId Indicates the user ID. - * @param result Indicates the dump infomation result. + * @param result Indicates the dump information result. * @return Returns true if the dump result is successfully obtained; returns false otherwise. */ virtual bool DumpInfos( diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 85c9643aa..89bb2b22c 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.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 @@ -442,7 +442,7 @@ bool NotificationPreferencesDatabase::PutDoNotDisturbDate( } void NotificationPreferencesDatabase::GetValueFromDisturbeDB( - const std::string &key, std::function funcion) + const std::string &key, std::function callback) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); @@ -454,19 +454,19 @@ void NotificationPreferencesDatabase::GetValueFromDisturbeDB( DistributedKv::Key getKey(key); status = kvStorePtr_->Get(getKey, value); if (status != DistributedKv::Status::SUCCESS) { - ANS_LOGE("Get value failed, use defalut value. error code is %{public}d", status); + ANS_LOGE("Get value failed, use default value. error code is %{public}d", status); return; } if (value.Empty()) { - ANS_LOGE("Get value is empty, use defalut value. error code is %{public}d", value.Empty()); + ANS_LOGE("Get value is empty, use default value. error code is %{public}d", value.Empty()); return; } - funcion(value); + callback(value); } void NotificationPreferencesDatabase::GetValueFromDisturbeDB( - const std::string &key, std::function funcion) + const std::string &key, std::function callback) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); @@ -477,7 +477,7 @@ void NotificationPreferencesDatabase::GetValueFromDisturbeDB( DistributedKv::Value value; DistributedKv::Key getKey(key); status = kvStorePtr_->Get(getKey, value); - funcion(status, value); + callback(status, value); } bool NotificationPreferencesDatabase::CheckBundle(const std::string &bundleName, const int &bundleUid) diff --git a/services/distributed/test/unittest/distributed_database_test.cpp b/services/distributed/test/unittest/distributed_database_test.cpp index f94a86995..0bd73d7fb 100644 --- a/services/distributed/test/unittest/distributed_database_test.cpp +++ b/services/distributed/test/unittest/distributed_database_test.cpp @@ -169,7 +169,7 @@ HWTEST_F(DistributedDatabaseTest, GetLocalDeviceId_00100, Function | SmallTest | /** * @tc.name : DistributedDatabase_GetLocalDeviceInfo_00100 * @tc.number : GetLocalDeviceInfo_00100 - * @tc.desc : Get local device infomation. + * @tc.desc : Get local device information. */ HWTEST_F(DistributedDatabaseTest, GetLocalDeviceInfo_00100, Function | SmallTest | Level1) { diff --git a/services/distributed/test/unittest/distributed_notification_manager_test.cpp b/services/distributed/test/unittest/distributed_notification_manager_test.cpp index c6cac5a4c..e4ab49cf0 100644 --- a/services/distributed/test/unittest/distributed_notification_manager_test.cpp +++ b/services/distributed/test/unittest/distributed_notification_manager_test.cpp @@ -173,7 +173,7 @@ HWTEST_F(DistributedNotificationManagerTest, Distributed_Get_Current_Notificatio /** * @tc.name : Distributed_Get_Local_DeviceInfo_00100 * @tc.number : Distributed_Get_Local_DeviceInfo_00100 - * @tc.desc : Get local distributed device infomation. + * @tc.desc : Get local distributed device information. */ HWTEST_F(DistributedNotificationManagerTest, Distributed_Get_Local_DeviceInfo_00100, Function | SmallTest | Level1) { -- Gitee From 1e128be03078d7817f19a5bc3b247e74fc85adf2 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Tue, 1 Mar 2022 16:26:34 +0800 Subject: [PATCH 16/17] UT modify Signed-off-by: fangJinliang1 Change-Id: I6fd4a4715ce29cae6ac4f692abf81f9062669572 Signed-off-by: fangJinliang1 --- frameworks/ans/test/moduletest/BUILD.gn | 4 +- .../test/moduletest/ans_fw_module_test.cpp | 88 +++++++++++++------ .../ans/src/advanced_notification_service.cpp | 4 + .../src/notification_subscriber_manager.cpp | 3 +- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index de3b5012a..659542d15 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -331,8 +331,8 @@ group("moduletest") { deps = [] deps += [ - # ":ReminderAgentJsTest", - # ":ans_fw_module_test", + ":ReminderAgentJsTest", + ":ans_fw_module_test", ":ans_innerkits_module_publish_test", ":ans_innerkits_module_setting_test", ":ans_innerkits_module_slot_test", diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index e7d017b0b..e5fec4ec0 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -28,6 +28,7 @@ #include "ans_manager_proxy.h" #include "common_event_manager.h" #include "common_event_support.h" +#include "datetime_ex.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "mock_ipc_skeleton.h" @@ -63,6 +64,7 @@ const std::string KVSTORE_PREFERENCES_STORE_ID = "distributed_preferences"; const std::string KVSTORE_SCREEN_STATUS_STORE_ID = "distributed_screen_status"; constexpr int UID = 1; +constexpr int USER_ID = 0; constexpr int CANCEL_REASON_DELETE = 2; constexpr int APP_CANCEL_REASON_DELETE = 8; constexpr int APP_CANCEL_ALL_REASON_DELETE = 9; @@ -472,7 +474,9 @@ public: void Parse(std::list> events) { + GTEST_LOG_(INFO) << "TestAnsSubscriber::Parse event size=" << events.size(); for (auto event : events) { + GTEST_LOG_(INFO) << "TestAnsSubscriber::Parse event type=" << static_cast(event->GetType()); if (event->GetType() == SubscriberEventType::ON_SUBSCRIBERESULT) { waitOnSubscriber_ = true; } else if (event->GetType() == SubscriberEventType::ON_CONSUMED) { @@ -670,7 +674,8 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_FlowControl_00100, Function | MediumTest | L int32_t notificationIdInt = i; if (i < MAX_ACTIVE_NUM_PERSECOND) { std::stringstream stream; - stream << KEY_SPLITER << UID << KEY_SPLITER << notificationLabel << KEY_SPLITER << notificationIdInt; + stream << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER + << notificationLabel << KEY_SPLITER << notificationIdInt; std::string notificationKey = stream.str(); NotificationSorting sorting; EXPECT_EQ(eventParser.GetOnConsumedReq()[i]->GetLabel().c_str(), notificationLabel); @@ -726,7 +731,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitonsByKey_00100, Function | M EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); std::stringstream stream; - stream << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; + stream << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; std::string notificationKey = stream.str(); NotificationSorting sorting; EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey); @@ -816,7 +821,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00100, Function | Medium eventParser.Parse(events); EXPECT_TRUE(eventParser.GetWaitOnConsumed()); SleepForFC(); - EXPECT_EQ(NotificationHelper::RemoveNotifications(), ERR_OK); + EXPECT_EQ(NotificationHelper::RemoveNotifications(USER_ID), ERR_OK); std::vector> notifications; EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); EXPECT_EQ((int)notifications.size(), (int)0); @@ -999,7 +1004,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelNotificationById_00100, Function | Med EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 1); std::stringstream stream; - stream << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 1; + stream << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 1; std::string notificationKey = stream.str(); NotificationSorting sorting; EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey); @@ -1094,7 +1099,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelAllNotifications_00100, Function | Med EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); std::stringstream stream0; - stream0 << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; + stream0 << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; std::string notificationKey0 = stream0.str(); NotificationSorting sorting0; EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey0); @@ -1106,7 +1111,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelAllNotifications_00100, Function | Med EXPECT_EQ(eventParser.GetOnConsumedReq()[1]->GetLabel().c_str(), NOTIFICATION_LABEL_1); EXPECT_EQ(eventParser.GetOnConsumedReq()[1]->GetId(), 1); std::stringstream stream1; - stream1 << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_1 << KEY_SPLITER << 1; + stream1 << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_1 << KEY_SPLITER << 1; std::string notificationKey1 = stream1.str(); NotificationSorting sorting1; EXPECT_EQ(eventParser.GetOnCanceledReq()[1]->GetKey(), notificationKey1); @@ -1787,7 +1792,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Publish_00300, Function | Medi ASSERT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS); DistributedKv::Entry outEntry; - ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), false); + ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), true); AppExecFwk::MockSetDistributedNotificationEnabled(true); SleepForFC(); } @@ -1910,7 +1915,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Remove_00200, Function | Mediu ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS); ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), true); - ASSERT_EQ(NotificationHelper::RemoveNotifications(), ERR_OK); + ASSERT_EQ(NotificationHelper::RemoveNotifications(USER_ID), ERR_OK); ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS); ASSERT_EQ(entries.size(), std::size_t(0)); SleepForFC(); @@ -1979,7 +1984,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00100, Function | Me EventParser parser1; parser1.Parse(subscriber.GetEvents()); - auto notificationList = parser1.GetOnConsumedReq(); + auto notificationList = parser1.GetOnConsumedWithSortingMapReq(); EXPECT_NE(notificationList.size(), std::size_t(0)); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); @@ -1990,7 +1995,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00100, Function | Me EventParser parser2; parser2.Parse(subscriber.GetEvents()); - notificationList = parser2.GetOnConsumedReq(); + notificationList = parser2.GetOnConsumedWithSortingMapReq(); EXPECT_NE(notificationList.size(), std::size_t(0)); EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); subscriber.ClearEvents(); @@ -2040,7 +2045,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00200, Function | Me EventParser parser1; parser1.Parse(subscriber.GetEvents()); - auto notificationList = parser1.GetOnConsumedReq(); + auto notificationList = parser1.GetOnConsumedWithSortingMapReq(); EXPECT_NE(notificationList.size(), std::size_t(0)); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); @@ -2114,12 +2119,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00100, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); + SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedReq(); + auto notificationList = parser.GetOnConsumedWithSortingMapReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND); @@ -2145,12 +2150,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00200, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); + SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedReq(); + auto notificationList = parser.GetOnConsumedWithSortingMapReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND); @@ -2176,12 +2181,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00300, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); + SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedReq(); + auto notificationList = parser.GetOnConsumedWithSortingMapReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_REMIND); @@ -2207,12 +2212,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00400, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); + SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedReq(); + auto notificationList = parser.GetOnConsumedWithSortingMapReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND); @@ -2241,21 +2246,23 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00500, Function | MediumTest | Lev PublishCommonEventScreenStatus(true); - TestAnsSubscriber subscriber; - EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); DistributedKv::AppId appId = {.appId = KVSTORE_APP_ID}; - DistributedKv::StoreId storeId = {.storeId = KVSTORE_SCREEN_STATUS_STORE_ID}; + DistributedKv::StoreId storeId = {.storeId = KVSTORE_NOTIFICATION_STORE_ID}; std::shared_ptr pointer = DistributedKv::AnsTestSingleKvStore::GetMockKvStorePointer(appId, storeId); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + DistributedKv::Key key(GenerateDistributedKey(request, REMOTE_DEVICE_ID)); DistributedKv::Value value(jsonString); pointer->InsertDataToDoCallback(key, value); SleepForFC(); + SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedReq(); + auto notificationList = parser.GetOnConsumedWithSortingMapReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND); @@ -2284,13 +2291,14 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00600, Function | MediumTest | Lev PublishCommonEventScreenStatus(false); - TestAnsSubscriber subscriber; - EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); DistributedKv::AppId appId = {.appId = KVSTORE_APP_ID}; - DistributedKv::StoreId storeId = {.storeId = KVSTORE_SCREEN_STATUS_STORE_ID}; + DistributedKv::StoreId storeId = {.storeId = KVSTORE_NOTIFICATION_STORE_ID}; std::shared_ptr pointer = DistributedKv::AnsTestSingleKvStore::GetMockKvStorePointer(appId, storeId); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + DistributedKv::Key key(GenerateDistributedKey(request, REMOTE_DEVICE_ID)); DistributedKv::Value value(jsonString); pointer->InsertDataToDoCallback(key, value); @@ -2298,7 +2306,7 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00600, Function | MediumTest | Lev EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedReq(); + auto notificationList = parser.GetOnConsumedWithSortingMapReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND); @@ -2314,7 +2322,11 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07100, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2349,7 +2361,11 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07200, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2386,7 +2402,11 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07300, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2419,7 +2439,10 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07300, Function HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07400, Function | MediumTest | Level1) { + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE); } @@ -2466,7 +2489,10 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07600, Function TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); @@ -2492,7 +2518,11 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07700, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2530,7 +2560,11 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07800, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); + req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index c9c4b4853..360612312 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1625,6 +1625,10 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt if (uid != SYSTEM_SERVICE_UID) { return ERR_ANS_NOT_SYSTEM_SERVICE; } + int userId = SUBSCRIBE_USER_INIT; + OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + request->SetCreatorUserId(userId); + ANS_LOGD("%{public}s, uid=%{public}d userId=%{public}d", __FUNCTION__, uid, userId); if (request->GetCreatorBundleName().empty()) { request->SetCreatorBundleName(FOUNDATION_BUNDLE_NAME); diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index cdd4abfcf..cb9342f9e 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -306,8 +306,9 @@ void NotificationSubscriberManager::NotifyConsumedInner( int32_t recvUserId = notification->GetNotificationRequest().GetReceiverUserId(); int32_t sendUserId = notification->GetUserId(); for (auto record : subscriberRecordList_) { - ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); auto BundleNames = notification->GetBundleName(); + ANS_LOGD("%{public}s record->userId = <%{public}d> BundleName = <%{public}s", + __FUNCTION__, record->userId, BundleNames.c_str()); auto iter = std::find(record->bundleList_.begin(), record->bundleList_.end(), BundleNames); if (!record->subscribedAll == (iter != record->bundleList_.end()) && (record->userId == sendUserId || -- Gitee From dbb570910762689891ad2bbbf1cb03cca4a13ee5 Mon Sep 17 00:00:00 2001 From: derek Date: Fri, 4 Mar 2022 15:56:31 +0800 Subject: [PATCH 17/17] fix codeCheck Signed-off-by: derek Change-Id: I05743d4dbcbe5023ba5d60974850e85b20ac03ef --- .../ans/native/src/reminder_request.cpp | 73 ++++++++++--------- .../ans/native/src/reminder_request_alarm.cpp | 11 +-- .../native/src/reminder_request_calendar.cpp | 25 ++++--- frameworks/ans/native/src/reminder_store.cpp | 32 ++++---- .../ans/native/include/reminder_request.h | 4 +- .../native/include/reminder_request_alarm.h | 2 +- .../include/reminder_request_calendar.h | 2 +- .../ans/native/include/reminder_store.h | 9 --- 8 files changed, 78 insertions(+), 80 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 5adbeee6c..db3ae7388 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -26,6 +26,11 @@ namespace OHOS { namespace Notification { +namespace +{ +const int BASE_YEAR = 1900; +} + int32_t ReminderRequest::GLOBAL_ID = 0; const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0; const uint16_t ReminderRequest::INVALID_U16_VALUE = 0; @@ -38,7 +43,6 @@ const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; -const int ReminderRequest::BASE_YEAR = 1900; const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT"; const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT"; const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT"; @@ -51,6 +55,38 @@ const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; const std::string ReminderRequest::SEP_WANT_AGENT = ""; +// For database recovery. +const std::string ReminderRequest::REMINDER_ID = "reminder_id"; +const std::string ReminderRequest::PKG_NAME = "package_name"; +const std::string ReminderRequest::USER_ID = "user_id"; +const std::string ReminderRequest::UID = "uid"; +const std::string ReminderRequest::APP_LABEL = "app_label"; +const std::string ReminderRequest::REMINDER_TYPE = "reminder_type"; +const std::string ReminderRequest::REMINDER_TIME = "reminder_time"; +const std::string ReminderRequest::TRIGGER_TIME = "trigger_time"; +const std::string ReminderRequest::RTC_TRIGGER_TIME = "rtc_trigger_time"; +const std::string ReminderRequest::TIME_INTERVAL = "time_interval"; +const std::string ReminderRequest::SNOOZE_TIMES = "snooze_times"; +const std::string ReminderRequest::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +const std::string ReminderRequest::RING_DURATION = "ring_duration"; +const std::string ReminderRequest::IS_EXPIRED = "is_expired"; +const std::string ReminderRequest::IS_ACTIVE = "is_active"; +const std::string ReminderRequest::STATE = "state"; +const std::string ReminderRequest::ZONE_ID = "zone_id"; +const std::string ReminderRequest::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +const std::string ReminderRequest::ACTION_BUTTON_INFO = "button_info"; +const std::string ReminderRequest::SLOT_ID = "slot_id"; +const std::string ReminderRequest::NOTIFICATION_ID = "notification_id"; +const std::string ReminderRequest::TITLE = "title"; +const std::string ReminderRequest::CONTENT = "content"; +const std::string ReminderRequest::SNOOZE_CONTENT = "snooze_content"; +const std::string ReminderRequest::EXPIRED_CONTENT = "expired_content"; +const std::string ReminderRequest::AGENT = "agent"; +const std::string ReminderRequest::MAX_SCREEN_AGENT = "maxScreen_agent"; + +std::string ReminderRequest::sqlOfAddColumns = ""; +std::vector ReminderRequest::columns; + ReminderRequest::ReminderRequest() { InitServerObj(); @@ -1386,7 +1422,7 @@ void ReminderRequest::UpdateNotificationBundleInfo() notificationRequest_->SetOwnerBundleName(bundleName_); notificationRequest_->SetCreatorBundleName(bundleName_); notificationRequest_->SetCreatorUid(uid_); - ErrCode errCode = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); + ErrCode errCode = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); if (errCode != ERR_OK) { ANSR_LOGE("GetOsAccountLocalIdFromUid fail."); return; @@ -1549,38 +1585,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, } } -const std::string ReminderRequest::REMINDER_ID = "reminder_id"; -const std::string ReminderRequest::PKG_NAME = "package_name"; -const std::string ReminderRequest::USER_ID = "user_id"; -const std::string ReminderRequest::UID = "uid"; -const std::string ReminderRequest::APP_LABEL = "app_label"; -const std::string ReminderRequest::REMINDER_TYPE = "reminder_type"; -const std::string ReminderRequest::REMINDER_TIME = "reminder_time"; -const std::string ReminderRequest::TRIGGER_TIME = "trigger_time"; -const std::string ReminderRequest::RTC_TRIGGER_TIME = "rtc_trigger_time"; -const std::string ReminderRequest::TIME_INTERVAL = "time_interval"; -const std::string ReminderRequest::SNOOZE_TIMES = "snooze_times"; -const std::string ReminderRequest::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; -const std::string ReminderRequest::RING_DURATION = "ring_duration"; -const std::string ReminderRequest::IS_EXPIRED = "is_expired"; -const std::string ReminderRequest::IS_ACTIVE = "is_active"; -const std::string ReminderRequest::STATE = "state"; -const std::string ReminderRequest::ZONE_ID = "zone_id"; -const std::string ReminderRequest::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; -const std::string ReminderRequest::ACTION_BUTTON_INFO = "button_info"; -const std::string ReminderRequest::SLOT_ID = "slot_id"; -const std::string ReminderRequest::NOTIFICATION_ID = "notification_id"; -const std::string ReminderRequest::TITLE = "title"; -const std::string ReminderRequest::CONTENT = "content"; -const std::string ReminderRequest::SNOOZE_CONTENT = "snooze_content"; -const std::string ReminderRequest::EXPIRED_CONTENT = "expired_content"; -const std::string ReminderRequest::AGENT = "agent"; -const std::string ReminderRequest::MAX_SCREEN_AGENT = "maxScreen_agent"; - -std::string ReminderRequest::sqlOfAddColumns = ""; -std::vector ReminderRequest::columns; - -void ReminderRequest::Init() +void ReminderRequest::InitDbColumns() { AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false); AddColumn(PKG_NAME, "TEXT NOT NULL", false); diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 532202d0c..bd13cae56 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -29,6 +29,11 @@ const uint8_t ReminderRequestAlarm::MINUTES_PER_HOUR = 60; const int8_t ReminderRequestAlarm::INVALID_INT_VALUE = -1; const int8_t ReminderRequestAlarm::DEFAULT_SNOOZE_TIMES = 3; +// For database recovery. +const std::string ReminderRequestAlarm::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; +const std::string ReminderRequestAlarm::ALARM_HOUR = "alarm_hour"; +const std::string ReminderRequestAlarm::ALARM_MINUTE = "alarm_minute"; + ReminderRequestAlarm::ReminderRequestAlarm(uint8_t hour, uint8_t minute, const std::vector daysOfWeek) : ReminderRequest(ReminderRequest::ReminderType::ALARM) { @@ -332,11 +337,7 @@ void ReminderRequestAlarm::AppendValuesBucket(const sptr &remin values.PutInt(ALARM_MINUTE, minute); } -const std::string ReminderRequestAlarm::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; -const std::string ReminderRequestAlarm::ALARM_HOUR = "alarm_hour"; -const std::string ReminderRequestAlarm::ALARM_MINUTE = "alarm_minute"; - -void ReminderRequestAlarm::Init() +void ReminderRequestAlarm::InitDbColumns() { ReminderRequest::AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); ReminderRequest::AddColumn(ALARM_HOUR, "INT", false); diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 746c2adcd..80d072d0d 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -25,6 +25,18 @@ const uint8_t ReminderRequestCalendar::JANUARY = 1; const uint8_t ReminderRequestCalendar::DECEMBER = 12; const uint8_t ReminderRequestCalendar::DEFAULT_SNOOZE_TIMES = 3; +// For database recovery. +const std::string ReminderRequestCalendar::REPEAT_DAYS = "repeat_days"; +const std::string ReminderRequestCalendar::REPEAT_MONTHS = "repeat_months"; +const std::string ReminderRequestCalendar::FIRST_DESIGNATE_YEAR = "first_designate_year"; +const std::string ReminderRequestCalendar::FIRST_DESIGNATE_MONTH = "first_designate_month"; +const std::string ReminderRequestCalendar::FIRST_DESIGNATE_DAY = "first_designate_day"; +const std::string ReminderRequestCalendar::CALENDAR_YEAR = "calendar_year"; +const std::string ReminderRequestCalendar::CALENDAR_MONTH = "calendar_month"; +const std::string ReminderRequestCalendar::CALENDAR_DAY = "calendar_day"; +const std::string ReminderRequestCalendar::CALENDAR_HOUR = "calendar_hour"; +const std::string ReminderRequestCalendar::CALENDAR_MINUTE = "calendar_minute"; + ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, const std::vector &repeatDays) : ReminderRequest(ReminderRequest::ReminderType::CALENDAR) @@ -576,18 +588,7 @@ void ReminderRequestCalendar::AppendValuesBucket(const sptr &re values.PutInt(CALENDAR_MINUTE, minute); } -const std::string ReminderRequestCalendar::REPEAT_DAYS = "repeat_days"; -const std::string ReminderRequestCalendar::REPEAT_MONTHS = "repeat_months"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_YEAR = "first_designate_year"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_MONTH = "first_designate_month"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_DAY = "first_designate_day"; -const std::string ReminderRequestCalendar::CALENDAR_YEAR = "calendar_year"; -const std::string ReminderRequestCalendar::CALENDAR_MONTH = "calendar_month"; -const std::string ReminderRequestCalendar::CALENDAR_DAY = "calendar_day"; -const std::string ReminderRequestCalendar::CALENDAR_HOUR = "calendar_hour"; -const std::string ReminderRequestCalendar::CALENDAR_MINUTE = "calendar_minute"; - -void ReminderRequestCalendar::Init() +void ReminderRequestCalendar::InitDbColumns() { ReminderRequest::AddColumn(REPEAT_DAYS, "INT", false); ReminderRequest::AddColumn(REPEAT_MONTHS, "INT", false); diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp index b63bcaea3..cee45f370 100644 --- a/frameworks/ans/native/src/reminder_store.cpp +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -28,15 +28,17 @@ namespace OHOS { namespace Notification { -const std::string ReminderStore::REMINDER_DB_DIR = "/data/system_ce/ans_standard/"; -const std::string ReminderStore::REMINDER_DB_NAME = "reminder.db"; -const std::string ReminderStore::REMINDER_DB_TABLE = "reminder"; -const uint32_t ReminderStore::REMINDER_RDB_VERSION = 1; -const int32_t ReminderStore::STATE_FAIL = -1; +namespace +{ + const std::string REMINDER_DB_DIR = "/data/system_ce/ans_standard/"; + const std::string REMINDER_DB_NAME = "reminder.db"; + const std::string REMINDER_DB_TABLE = "reminder"; + const uint32_t REMINDER_RDB_VERSION = 1; + const int32_t STATE_FAIL = -1; + std::vector columns; +} + const int32_t ReminderStore::STATE_OK = 0; -const uint16_t ReminderStore::TIME_INTERVAL_FOR_DELETE = 1800; -const uint16_t ReminderStore::MILLI_SECONDS = 1000; -std::vector ReminderStore::columns; int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore &store) { @@ -66,13 +68,13 @@ int32_t ReminderStore::Init() } } - ReminderRequest::Init(); - ReminderRequestCalendar::Init(); - ReminderRequestAlarm::Init(); - ReminderStore::columns.insert(ReminderStore::columns.begin(), + ReminderRequest::InitDbColumns(); + ReminderRequestCalendar::InitDbColumns(); + ReminderRequestAlarm::InitDbColumns(); + columns.insert(columns.begin(), ReminderRequest::columns.begin(), ReminderRequest::columns.end()); - std::string dbConfig = ReminderStore::REMINDER_DB_DIR + ReminderStore::REMINDER_DB_NAME; + std::string dbConfig = REMINDER_DB_DIR + REMINDER_DB_NAME; NativeRdb::RdbStoreConfig config_(dbConfig); ReminderStoreDataCallBack rdbDataCallBack_; rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(config_, REMINDER_RDB_VERSION, rdbDataCallBack_, errCode); @@ -124,7 +126,7 @@ int32_t ReminderStore::InitData() ANSR_LOGE("Init data failed."); return STATE_FAIL; } - return STATE_OK; + return ReminderStore::STATE_OK; } int32_t ReminderStore::Delete(int32_t reminderId) @@ -259,7 +261,7 @@ std::shared_ptr ReminderStore::Query(const std::s uint8_t ReminderStore::GetColumnIndex(const std::string& name) { uint8_t index = 0; - for (auto it = ReminderStore::columns.begin(); it != ReminderStore::columns.end(); ++it) { + for (auto it = columns.begin(); it != columns.end(); ++it) { if (name == (*it)) { break; } diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index f4585d1de..798913b6a 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -607,7 +607,7 @@ public: static const uint8_t REMINDER_STATUS_SNOOZE; // For database recovery. - static void Init(); + static void InitDbColumns(); static const std::string REMINDER_ID; static const std::string PKG_NAME; static const std::string USER_ID; @@ -664,8 +664,6 @@ protected: */ static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); - static const int BASE_YEAR; - private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index b0f562507..705dbf0a0 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -109,7 +109,7 @@ public: const sptr &bundleOption, NativeRdb::ValuesBucket &values); // For database recovery. - static void Init(); + static void InitDbColumns(); protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index 9d022dc7d..f5d0e7a35 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -147,7 +147,7 @@ public: static uint8_t GetDaysOfMonth(const uint16_t &year, const uint8_t &month); // For database recovery. - static void Init(); + static void InitDbColumns(); protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h index 8e49fded8..cea23b096 100644 --- a/interfaces/innerkits/ans/native/include/reminder_store.h +++ b/interfaces/innerkits/ans/native/include/reminder_store.h @@ -41,8 +41,6 @@ public: int64_t UpdateOrInsert(const sptr &reminder, const sptr &bundleOption); static uint8_t GetColumnIndex(const std::string& name); - static std::vector columns; - static const int32_t STATE_FAIL; static const int32_t STATE_OK; private: @@ -71,13 +69,6 @@ private: std::shared_ptr Query(const std::string &queryCondition) const; int64_t Update(const sptr &reminder, const sptr &bundleOption); - static const std::string REMINDER_DB_DIR; - static const std::string REMINDER_DB_NAME; - static const std::string REMINDER_DB_TABLE; - static const uint32_t REMINDER_RDB_VERSION; - static const uint16_t TIME_INTERVAL_FOR_DELETE; - static const uint16_t MILLI_SECONDS; - class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { public: int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; -- Gitee