diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 19531421fdd9b4cdea4704d225c68a4f4fe30cef..93ce0ab67e7923a256631c6fa85e503b777db6c9 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1561,7 +1561,7 @@ private: const sptr &callerToken, const sptr bundleOption, const bool innerLake); - void ClearSlotTypeData(const sptr &request, int32_t callingUid); + void ClearSlotTypeData(const sptr &request, int32_t callingUid, int32_t sourceType); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index d3759300face3db601a5a33f11d7f89cc33671f8..97eed85dcc1d2badb5e88c03b8e1a43e8a0b2140 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -449,10 +449,10 @@ public: uint32_t GetHashCodeRule(const int32_t uid); bool GetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType); + const NotificationConstant::SlotType &slotType, int32_t sourceType); bool SetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType); + const NotificationConstant::SlotType &slotType, int32_t sourceType); private: bool GetBundleInfo(NotificationPreferencesInfo &preferencesInfo, diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 98f9928e2cc3ac1a674d0daed8bfd94b0a816e78..b0ad444f1c44abb5e25b0d519682eba8540f3888 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -310,10 +310,10 @@ public: uint32_t GetHashCodeRule(const int32_t uid); bool SetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType); + const NotificationConstant::SlotType &slotType, int32_t sourceType); bool GetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType); + const NotificationConstant::SlotType &slotType, int32_t sourceType); /** * @brief ParseBundleFromDistureDB * @param info bundle info. diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 7cad489225c7acbc6da9644ef723d14d39243fb0..27f4d9e782b11db86a9c235c9509b93d6ce0ca43 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -78,6 +78,8 @@ const static std::string BUNDLE_NAME_ZYT = "com.zhuoyi.appstore.lite"; const static std::string BUNDLE_NAME_ABROAD = "com.easy.transfer.abroad"; const static std::string INSTALL_SOURCE_EASYABROAD = "com.easy.abroad"; constexpr int32_t BADGE_NUM_LIMIT = 0; +constexpr int32_t CLEAR_SLOT_FROM_AVSEESAION = 1; +constexpr int32_t CLEAR_SLOT_FROM_RSS = 2; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( const sptr &bundleOption, bool enabled) @@ -2485,13 +2487,23 @@ void AdvancedNotificationService::UpdateUnifiedGroupInfo(const std::string &key, }); } -void AdvancedNotificationService::ClearSlotTypeData(const sptr &request, int32_t callingUid) +void AdvancedNotificationService::ClearSlotTypeData(const sptr &request, int32_t callingUid, + int32_t sourceType) { - if (request == nullptr || callingUid != AVSEESAION_PID) { + if (request == nullptr || (sourceType != CLEAR_SLOT_FROM_AVSEESAION && sourceType != CLEAR_SLOT_FROM_RSS)) { return; } - if (request->GetSlotType() != NotificationConstant::SlotType::LIVE_VIEW) { - return; + + if (sourceType == CLEAR_SLOT_FROM_AVSEESAION) { + if (callingUid != AVSEESAION_PID || + request->GetSlotType() != NotificationConstant::SlotType::LIVE_VIEW) { + return; + } + } + if (sourceType == CLEAR_SLOT_FROM_RSS) { + if (request->GetCreatorUid() != RSS_PID || !request->IsSystemLiveView()) { + return; + } } int32_t uid = request->GetOwnerUid(); @@ -2503,13 +2515,13 @@ void AdvancedNotificationService::ClearSlotTypeData(const sptrGetBundleRemoveFlag(bundleOption, - NotificationConstant::SlotType::LIVE_VIEW)) { + NotificationConstant::SlotType::LIVE_VIEW, sourceType)) { return; } NotificationPreferences::GetInstance()->RemoveNotificationSlot(bundleOption, NotificationConstant::SlotType::LIVE_VIEW); NotificationPreferences::GetInstance()->SetBundleRemoveFlag(bundleOption, - NotificationConstant::SlotType::LIVE_VIEW); + NotificationConstant::SlotType::LIVE_VIEW, sourceType); } ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptr &request) @@ -2632,6 +2644,7 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrrequest, ipcUid, CLEAR_SLOT_FROM_RSS); return; } bool isNotificationExists = IsNotificationExists(record->notification->GetKey()); @@ -2644,7 +2657,7 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrrequest, ipcUid); + ClearSlotTypeData(record->request, ipcUid, CLEAR_SLOT_FROM_AVSEESAION); UpdateRecentNotification(record->notification, false, 0); sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 7e9044d6952da043de0d5acc00bba3a8feaf7ad8..488a956cb122c106c6de5fc10255683b32b5303b 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -1509,21 +1509,21 @@ uint32_t NotificationPreferences::GetHashCodeRule(const int32_t uid) } bool NotificationPreferences::GetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType) + const NotificationConstant::SlotType &slotType, int32_t sourceType) { if (preferncesDB_ == nullptr) { return true; } - return preferncesDB_->GetBundleRemoveFlag(bundleOption, slotType); + return preferncesDB_->GetBundleRemoveFlag(bundleOption, slotType, sourceType); } bool NotificationPreferences::SetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType) + const NotificationConstant::SlotType &slotType, int32_t sourceType) { if (preferncesDB_ == nullptr) { return false; } - return preferncesDB_->SetBundleRemoveFlag(bundleOption, slotType); + return preferncesDB_->SetBundleRemoveFlag(bundleOption, slotType, sourceType); } } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 6097447a730fd42cd5e783b39ec629718e943ca0..1e7f4e521800bb983cee49e8b99c0455175767af 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -238,6 +238,7 @@ const static std::string KEY_REMOVED_FLAG = "1"; const static std::string KEY_SECOND_REMOVED_FLAG = "2"; +constexpr int32_t CLEAR_SLOT_FROM_AVSEESAION = 1; /** * Indicates hashCode rule. */ @@ -2633,8 +2634,22 @@ uint32_t NotificationPreferencesDatabase::GetHashCodeRule(const int32_t uid) return result; } +static std::string GetBundleRemoveFlagKey(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, int32_t sourceType) +{ + std::string key; + if (sourceType == CLEAR_SLOT_FROM_AVSEESAION) { + key = KEY_REMOVE_SLOT_FLAG + bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid()) + + KEY_UNDER_LINE + std::to_string(slotType); + } else { + key = KEY_REMOVE_SLOT_FLAG + std::to_string(sourceType) + KEY_UNDER_LINE + bundleOption->GetBundleName() + + std::to_string(bundleOption->GetUid()) + KEY_UNDER_LINE + std::to_string(slotType); + } + return key; +} + bool NotificationPreferencesDatabase::SetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType) + const NotificationConstant::SlotType &slotType, int32_t sourceType) { if (bundleOption == nullptr) { ANS_LOGW("Current bundle option is null"); @@ -2652,14 +2667,13 @@ bool NotificationPreferencesDatabase::SetBundleRemoveFlag(const sptrGetBundleName() + std::to_string(bundleOption->GetUid()) + - KEY_UNDER_LINE + std::to_string(slotType); + std::string key = GetBundleRemoveFlagKey(bundleOption, slotType, sourceType); int32_t result = rdbDataManager_->InsertData(key, KEY_SECOND_REMOVED_FLAG, userId); return (result == NativeRdb::E_OK); } bool NotificationPreferencesDatabase::GetBundleRemoveFlag(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType) + const NotificationConstant::SlotType &slotType, int32_t sourceType) { if (bundleOption == nullptr) { ANS_LOGW("Current bundle option is null"); @@ -2673,8 +2687,7 @@ bool NotificationPreferencesDatabase::GetBundleRemoveFlag(const sptrGetBundleName() + std::to_string(bundleOption->GetUid()) + - KEY_UNDER_LINE + std::to_string(slotType); + std::string key = GetBundleRemoveFlagKey(bundleOption, slotType, sourceType); bool existFlag = true; std::string result; GetValueFromDisturbeDB(key, userId, [&](const int32_t& status, std::string& value) {