diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index f6b83c08dab9e7e2ca6f6816fe8c364e83f55896..23c350aa3ca3618c5cb2708eac70998f2e5ec1c7 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 06e18d018fa3b9d067f5df4df3d876bc38f270a0..24611063c4751c61f9c8cfcebeb02f63d9adcfb8 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 0000000000000000000000000000000000000000..ba41ed212635e9afdfa213f8e85535bda662ad76 --- /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 b85a7dcd333ebe33edbd885b1c552c996692a139..4fd4453a56ef22906af1dc6bf44317ce3ef293d0 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 0000000000000000000000000000000000000000..c91d0bf113de73304c91c970e721b53178530b0f --- /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