From 57b6c960a61357713a0ef7ee6de562c3dac6eff4 Mon Sep 17 00:00:00 2001 From: xdongs Date: Tue, 3 Jun 2025 09:56:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?dans=E9=80=9A=E9=81=93=E5=8D=8F=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xdongs --- services/distributed/BUILD.gn | 1 + .../include/helper/device_type_helper.h | 31 ++++++++++++++ .../include/soft_bus/distributed_service.h | 2 + .../src/helper/device_type_helper.cpp | 38 ++++++++++++++++++ .../src/soft_bus/distributed_service.cpp | 40 +++++++++++++++++++ .../distributed_subscribe_service_v2.cpp | 17 +------- 6 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 services/distributed/include/helper/device_type_helper.h create mode 100644 services/distributed/src/helper/device_type_helper.cpp diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 87ab3b7c8..9c60da4d5 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 000000000..854591108 --- /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 a14e533da..17cd8409c 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -59,6 +59,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 000000000..3f0f32e27 --- /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 dbab00a71..c0d8af391 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" namespace OHOS { namespace Notification { @@ -214,6 +215,9 @@ void DistributedService::OnConsumed(const std::shared_ptr &request return; } std::function task = std::bind([request, peerDevice]() { + if (!OnConsumedSetFlags(request, peerDevice)) { + return; + } DistributedPublishService::GetInstance().SendNotifictionRequest(request, peerDevice); }); serviceQueue_->submit(task); @@ -387,5 +391,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 0f2e9f2fc..a46f5ff0c 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 ""; - } -} - static int32_t 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); -- Gitee From 2ea9fc207e53d1fc76600ebf788b979ac28ba498 Mon Sep 17 00:00:00 2001 From: xdongs2009 Date: Tue, 3 Jun 2025 02:49:51 +0000 Subject: [PATCH 2/3] update services/distributed/src/soft_bus/distributed_service.cpp. Signed-off-by: xdongs2009 --- services/distributed/src/soft_bus/distributed_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index c77f034a6..a5e4a09e9 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -246,7 +246,7 @@ 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; } -- Gitee From 95e4e50c6218f3f17742b1d7e69663be902faee3 Mon Sep 17 00:00:00 2001 From: xdongs2009 Date: Tue, 3 Jun 2025 03:56:25 +0000 Subject: [PATCH 3/3] update services/distributed/test/unittest/BUILD.gn. Signed-off-by: xdongs2009 --- services/distributed/test/unittest/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 8a09f6caa..303d5c4c4 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", -- Gitee