diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 22aa43d4062f29124d753efdac09f0bd5e270bc4..e3593f178fc7f2bace9becc3a37fb72610d4e1ff 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -196,6 +196,8 @@ public: /* one hour */ static const int64_t DEFAULT_AUTO_DELETE_TIME = 3600; + static const int64_t NO_DELAY_DELETE_TIME = 0; + static constexpr uint64_t INVALID_TIMER_ID = 0ULL; // live view max size is 512KB(extra size) + 8KB(base size) = 520KB diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index be9fd407af353c157e8becd3d6c3a86aee572650..7f0c782131578fd6b2fe0a34dfe76ba52ff1918a 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -645,6 +645,10 @@ void AdvancedNotificationService::CancelUpdateTimer(const std::shared_ptr &record) { auto deleteTime = record->request->GetAutoDeletedTime(); + if (deleteTime == NotificationConstant::NO_DELAY_DELETE_TIME) { + TriggerAutoDelete(record->notification->GetKey(), NotificationConstant::APP_CANCEL_REASON_DELETE); + return; + } if (deleteTime <= NotificationConstant::INVALID_AUTO_DELETE_TIME) { deleteTime = NotificationConstant::DEFAULT_AUTO_DELETE_TIME; } @@ -2023,16 +2027,40 @@ std::shared_ptr AdvancedNotificationService::GetRecordFromNo return nullptr; } +ErrCode AdvancedNotificationService::isAllowedGetNotificationByFilter( + const std::shared_ptr &record) +{ + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (isSubsystem || AccessTokenHelper::IsSystemApp()) { + if (CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + return ERR_OK; + } + + ANS_LOGD("Get live view by filter failed because check permission is false."); + return ERR_ANS_PERMISSION_DENIED; + } + + std::string bundle = GetClientBundleName(); + if (bundle.empty()) { + return ERR_ANS_NON_SYSTEM_APP; + } + int32_t uid = IPCSkeleton::GetCallingUid(); + if (uid == record->bundleOption->GetUid() && bundle == record->bundleOption->GetBundleName()) { + return ERR_OK; + } + + return ERR_ANS_NON_SYSTEM_APP; +} + ErrCode AdvancedNotificationService::GetActiveNotificationByFilter( const sptr &bundleOption, const int32_t notificationId, const std::string &label, const std::vector extraInfoKeys, sptr &request) { ANS_LOGD("%{public}s", __FUNCTION__); - ErrCode result = CheckCommonParams(); - if (result != ERR_OK) { - ANS_LOGE("get live view by filter invalid param."); - return result; + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("Serial queue is invalidity."); + return ERR_ANS_INVALID_PARAM; } if (bundleOption == nullptr) { @@ -2043,7 +2071,7 @@ ErrCode AdvancedNotificationService::GetActiveNotificationByFilter( return ERR_ANS_INVALID_BUNDLE; } - result = ERR_ANS_NOTIFICATION_NOT_EXISTS; + ErrCode result = ERR_ANS_NOTIFICATION_NOT_EXISTS; ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { ANS_LOGD("ffrt enter!"); @@ -2051,7 +2079,11 @@ ErrCode AdvancedNotificationService::GetActiveNotificationByFilter( if ((record == nullptr) || (!record->request->IsCommonLiveView())) { return; } - result = ERR_OK; + result = isAllowedGetNotificationByFilter(record); + if (result != ERR_OK) { + return; + } + if (extraInfoKeys.empty()) { // return all liveViewExtraInfo because no extraInfoKeys request = record->request;