diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 87ab3b7c8518f90bdbfc1ecbab2e6f87d310ccaf..9c60da4d5373af7e261a27a0bacba633c77620bf 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -104,6 +104,7 @@ ohos_shared_library("libdans") { "src/helper/ability_manager_helper.cpp", "src/helper/analytics_util.cpp", "src/helper/bundle_resource_helper.cpp", + "src/helper/device_type_helper.cpp", "src/helper/distributed_operation_connection.cpp", "src/helper/distributed_operation_helper.cpp", "src/helper/distributed_preference.cpp", diff --git a/services/distributed/include/helper/device_type_helper.h b/services/distributed/include/helper/device_type_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..85459110851005566201f8f3aaec04c05a479054 --- /dev/null +++ b/services/distributed/include/helper/device_type_helper.h @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2025 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_DEVICE_TYPE_HELPER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_DEVICE_TYPE_HELPER_H + +#include + +namespace OHOS { +namespace Notification { + +class DeviceTypeHelper { +public: + static std::string Dm2Ans(uint16_t deviceType); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_DEVICE_TYPE_HELPER_H \ No newline at end of file diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index e165673a73a4d9deacb4b35966bf2b77e89769f5..0960d47ea0f5aab6e5925d58bd55d718c7aaf43a 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -61,6 +61,8 @@ private: void OnHandleMsg(std::shared_ptr& box); void ConnectPeerDevice(DistributedDeviceInfo device); void HandleMatchSync(const std::shared_ptr& boxMessage); + bool OnConsumedSetFlags(const std::shared_ptr &request, + const DistributedDeviceInfo& peerDevice); private: std::shared_ptr serviceQueue_ = nullptr; diff --git a/services/distributed/src/helper/device_type_helper.cpp b/services/distributed/src/helper/device_type_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f0f32e27be750f1c4d28ef1515a74e976ce7bbb --- /dev/null +++ b/services/distributed/src/helper/device_type_helper.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2025 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 "device_type_helper.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace Notification { + +std::string DeviceTypeHelper::Dm2Ans(uint16_t deviceType) +{ + switch (deviceType) { + case DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH: { + return "wearable"; + } + case DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD: { + return "pad"; + } + case DistributedHardware::DmDeviceType::DEVICE_TYPE_PC: { + return "pc"; + } + default: + return ""; + } +} +} +} \ No newline at end of file diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index f0d99273291cea67b6f9a580b23553fa5855fb84..a5e4a09e9b97fa551ac717bb4694ac4e27ebc7d7 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -30,6 +30,7 @@ #include "distributed_operation_service.h" #include "distributed_publish_service.h" #include "distributed_subscribe_service.h" +#include "device_type_helper.h" #include "bundle_resource_helper.h" namespace OHOS { @@ -245,7 +246,10 @@ void DistributedService::OnConsumed(const std::shared_ptr &request ANS_LOGE("Check handler is null."); return; } - std::function task = std::bind([request, peerDevice]() { + std::function task = std::bind([request, peerDevice, this]() { + if (!OnConsumedSetFlags(request, peerDevice)) { + return; + } DistributedPublishService::GetInstance().SendNotifictionRequest(request, peerDevice); }); serviceQueue_->submit(task); @@ -454,5 +458,41 @@ void DistributedService::OnReceiveMsg(const void *data, uint32_t dataLen) } OnHandleMsg(box); } + +bool DistributedService::OnConsumedSetFlags(const std::shared_ptr &request, + const DistributedDeviceInfo& peerDevice) +{ + std::string deviceType = DeviceTypeHelper::Dm2Ans(peerDevice.deviceType_); + sptr requestPoint = request->GetNotificationRequestPoint(); + auto flagsMap = requestPoint->GetDeviceFlags(); + if (flagsMap == nullptr || flagsMap->size() <= 0) { + return false; + } + auto flagIter = flagsMap->find(deviceType); + if (flagIter != flagsMap->end() && flagIter->second != nullptr) { + ANS_LOGI("SetFlags-before filte, notificationKey = %{public}s flagIter \ + flags = %{public}d, deviceType:%{public}s", + requestPoint->GetKey().c_str(), flagIter->second->GetReminderFlags(), deviceType.c_str()); + std::shared_ptr tempFlags = requestPoint->GetFlags(); + tempFlags->SetSoundEnabled(tempFlags->IsSoundEnabled() == NotificationConstant::FlagStatus::OPEN && + flagIter->second->IsSoundEnabled() == NotificationConstant::FlagStatus::OPEN ? + NotificationConstant::FlagStatus::OPEN : NotificationConstant::FlagStatus::CLOSE); + tempFlags->SetVibrationEnabled(tempFlags->IsVibrationEnabled() == NotificationConstant::FlagStatus::OPEN && + flagIter->second->IsVibrationEnabled() == NotificationConstant::FlagStatus::OPEN ? + NotificationConstant::FlagStatus::OPEN : NotificationConstant::FlagStatus::CLOSE); + tempFlags->SetLockScreenVisblenessEnabled( + tempFlags->IsLockScreenVisblenessEnabled() && flagIter->second->IsLockScreenVisblenessEnabled()); + tempFlags->SetBannerEnabled( + tempFlags->IsBannerEnabled() && flagIter->second->IsBannerEnabled()); + tempFlags->SetLightScreenEnabled( + tempFlags->IsLightScreenEnabled() && flagIter->second->IsLightScreenEnabled()); + requestPoint->SetFlags(tempFlags); + ANS_LOGI("SetFlags-after filte, notificationKey = %{public}s flags = %{public}d", + requestPoint->GetKey().c_str(), tempFlags->GetReminderFlags()); + } else { + return false; + } + return true; +} } } diff --git a/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp b/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp index a11344b1f8a022858e15192f25fbca17cba07786..0ac43a57ffcdf44f9b3f877302c1236f331435ec 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp @@ -21,26 +21,13 @@ #include "notification_helper.h" #include "distributed_device_service.h" #include "notification_subscribe_info.h" +#include "device_type_helper.h" namespace OHOS { namespace Notification { const int32_t DEFAULT_FILTER_TYPE = 1; -static std::string SubscribeTransDeviceType(uint16_t deviceType) -{ - switch (deviceType) { - case DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH: { - return "wearable"; - } - case DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD: { - return "Pad"; - } - default: - return ""; - } -} - int32_t DistributedSubscribeService::GetCurrentActiveUserId() { int32_t userId = DEFAULT_USER_ID; @@ -75,7 +62,7 @@ void DistributedSubscribeService::SubscribeNotification(const DistributedDeviceI slotTypes.push_back(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); subscribeInfo->SetSlotTypes(slotTypes); subscribeInfo->SetFilterType(DEFAULT_FILTER_TYPE); - subscribeInfo->AddDeviceType(SubscribeTransDeviceType(peerDevice.deviceType_)); + subscribeInfo->AddDeviceType(DeviceTypeHelper::Dm2Ans(peerDevice.deviceType_)); subscribeInfo->AddAppUserId(userId); subscribeInfo->SetNeedNotifyApplication(true); subscribeInfo->SetNeedNotifyResponse(true); diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 8a09f6caad5b96f3ef5e77b9ffadfd0f9dd6bbdf..303d5c4c40b5c5e089790ef1f8ec5c6fefca8337 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -442,6 +442,7 @@ ohos_unittest("distributed_service_test") { "/${services_path}/distributed/src/helper/ability_manager_helper.cpp", "/${services_path}/distributed/src/helper/analytics_util.cpp", "/${services_path}/distributed/src/helper/bundle_resource_helper.cpp", + "/${services_path}/distributed/src/helper/device_type_helper.cpp", "/${services_path}/distributed/src/helper/distributed_operation_connection.cpp", "/${services_path}/distributed/src/helper/distributed_operation_helper.cpp", "/${services_path}/distributed/src/helper/distributed_preference.cpp", @@ -536,6 +537,7 @@ ohos_unittest("distributed_subscriber_test") { "/${services_path}/distributed/src/helper/ability_manager_helper.cpp", "/${services_path}/distributed/src/helper/analytics_util.cpp", "/${services_path}/distributed/src/helper/bundle_resource_helper.cpp", + "/${services_path}/distributed/src/helper/device_type_helper.cpp", "/${services_path}/distributed/src/helper/distributed_operation_connection.cpp", "/${services_path}/distributed/src/helper/distributed_operation_helper.cpp", "/${services_path}/distributed/src/helper/distributed_preference.cpp",