diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 9110ac4a871329f69faf89ae93d574a730439db7..98f514cca3f4676815caca08d6011668c683b79b 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 0a3f1bd339bb9f9cd75765d10033eebec377eca9..ee4a0894f3d9e781d4506407a7f189f56d3c3fcc 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 90660bfee0a728f96d988e0b191db0bea0884fa0..f80d329260afe520c38a98f23a0bd26871570b6d 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 539c4360e81c62617249bc333430ee46ed485a07..fb86fd4e03edb176fdb86f1bfb8ed486fe0115f5 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 0c583550351610ef96b15fcf55a27b60b5a45867..a68618e0894a2f0499ba3ddca76451346acbdb1f 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 5920b76f980f063cf369e63fc6c04b3097936006..63d6053779f2f7c6f528cc246e7ab9c024c3b85a 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 0d943c24a47c75261334dd4c9a4293d041a88710..5382772b0e7170052df6a54b345f30d4b99f45c4 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 732e1d736fc0bfe5e7e9fd217b72dfd1bca24631..b7af5c22c73b26e01f445e15a39628095c3a95fb 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 9985085a5e44909426d042bb54383837ff035eee..0a68398f59dd4fb29f08658b449a6f444ee9d17b 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 38729309f170d1e7aeb28418451f388fe6a1b515..f29609b269038206ee223a5ab09382a1f573ab4e 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 f445f5321c1b9c5c7de9373b74c5761aebdb3cd8..85c9643aae91da15919ec540fa5e7d9aa03714cd 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 55eabc6c099c80fe72c571bed32c3c083ea98bda..1afe46b42ffd44781c82a602940a94cc3bf6d02e 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 64df9b4db8f602d32f3f16b947407f2f84b5cc24..3a1874b82063389e8afa6f732f75b08cc450cd06 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