From 639f45468015e7699ff9e16a86bad1ade2aebb4f Mon Sep 17 00:00:00 2001 From: z30053788 Date: Thu, 21 Mar 2024 15:17:08 +0800 Subject: [PATCH] 5.0 Signed-off-by: z30053788 Change-Id: I8afde7902baef6221f21aa7f5400ec2cb2ff61e4 --- services/ans/BUILD.gn | 1 + .../include/advanced_notification_service.h | 6 ++- .../ans/include/distributed_device_status.h | 38 ++++++++++++++++++ .../advanced_notification_publish_service.cpp | 20 +++++++++- .../ans/src/distributed_device_status.cpp | 40 +++++++++++++++++++ 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 services/ans/include/distributed_device_status.h create mode 100644 services/ans/src/distributed_device_status.cpp diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index f6b83c08d..23c350aa3 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -59,6 +59,7 @@ ohos_shared_library("libans") { "src/advanced_notification_subscriber_service.cpp", "src/advanced_notification_utils.cpp", "src/bundle_manager_helper.cpp", + "src/distributed_device_status.cpp", "src/event_report.cpp", "src/notification_config_parse.cpp", "src/notification_dialog.cpp", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 06e18d018..24611063c 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -42,6 +42,7 @@ #include "push_callback_interface.h" #include "system_event_observer.h" #include "notification_subscriber_manager.h" +#include "distributed_device_status.h" namespace OHOS { namespace Notification { @@ -1079,9 +1080,9 @@ private: ErrCode DistributedNotificationDump(const std::string& bundle, int32_t userId, std::vector &dumpInfo); #endif + ErrCode SetRecentNotificationCount(const std::string arg); void UpdateRecentNotification(sptr ¬ification, bool isDelete, int32_t reason); - void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate); static bool CheckPermission(const std::string &permission); ErrCode PrepareNotificationRequest(const sptr &request); @@ -1206,6 +1207,7 @@ private: std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; std::list> notificationList_; + std::list flowControlTimestampList_; std::list flowControlUpdateTimestampList_; std::shared_ptr recentInfo_ = nullptr; @@ -1219,6 +1221,8 @@ private: #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED NotificationConstant::DistributedReminderPolicy distributedReminderPolicy_ = DEFAULT_DISTRIBUTED_REMINDER_POLICY; bool localScreenOn_ = true; + std::shared_ptr DistributedDeviceStatus_; + #endif std::shared_ptr permissonFilter_ = nullptr; std::shared_ptr notificationSlotFilter_ = nullptr; diff --git a/services/ans/include/distributed_device_status.h b/services/ans/include/distributed_device_status.h new file mode 100644 index 000000000..ba41ed212 --- /dev/null +++ b/services/ans/include/distributed_device_status.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_DEVICE_STATUS_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_DEVICE_STATUS_H + +#include "errors.h" +#include +#include + +namespace OHOS { +namespace Notification { +class DistributedDeviceStatus { +public: + DistributedDeviceStatus(); + ~DistributedDeviceStatus(); + ErrCode setDeviceStatus(std::string deviceType, int status); + + int32_t getDeviceStatus(std::string deviceType); +private: + std::map deviceStatus_; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DISTRIBUTED_DEVICE_STATUS_H \ No newline at end of file diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index b85a7dcd3..4fd4453a5 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -81,7 +81,25 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s", __FUNCTION__); - +ANS_LOGI("zbx_test_start"); + int zbx_temp = 0; + + DistributedDeviceStatus_->setDeviceStatus("zbx",1); + zbx_temp = DistributedDeviceStatus_->getDeviceStatus("zbx"); + ANS_LOGI("zbx = %{public}d", zbx_temp); + DistributedDeviceStatus_->setDeviceStatus("zbx",2); + zbx_temp = DistributedDeviceStatus_->getDeviceStatus("zbx"); + ANS_LOGI("zbx = %{public}d", zbx_temp); + DistributedDeviceStatus_->setDeviceStatus("zbx1",3); + zbx_temp = DistributedDeviceStatus_->getDeviceStatus("zbx1"); + ANS_LOGI("zbx1 = %{public}d", zbx_temp); + DistributedDeviceStatus_->setDeviceStatus("zbx1",4); + DistributedDeviceStatus_->setDeviceStatus("zbx",5); + zbx_temp = DistributedDeviceStatus_->getDeviceStatus("zbx1"); + ANS_LOGI("zbx1 = %{public}d", zbx_temp); + zbx_temp = DistributedDeviceStatus_->getDeviceStatus("zbx"); + ANS_LOGI("zbx1 = %{public}d", zbx_temp); + if (!request) { ANSR_LOGE("ReminderRequest object is nullptr"); return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/distributed_device_status.cpp b/services/ans/src/distributed_device_status.cpp new file mode 100644 index 000000000..c91d0bf11 --- /dev/null +++ b/services/ans/src/distributed_device_status.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "distributed_device_status.h" + +namespace OHOS { +namespace Notification { +DistributedDeviceStatus::DistributedDeviceStatus() {} + +DistributedDeviceStatus::~DistributedDeviceStatus() {} + + +ErrCode DistributedDeviceStatus::setDeviceStatus(std::string deviceType, int status) +{ + deviceStatus_[deviceType] = status; + return ERR_OK; +} + +int32_t DistributedDeviceStatus::getDeviceStatus(std::string deviceType) +{ + auto it = deviceStatus_.find(deviceType); + if (it != deviceStatus_.end()) { + return it->second; + } + return -1; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file -- Gitee