diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index bfcd6465f2198f73670da07ce8c68b54c27c4bd9..eeabb3f17bb0d8f6e1bbbf0a4e97a9b99ec5e892 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1633,6 +1633,7 @@ private: const sptr &bundle, bool enabled, bool isForceControl); ErrCode OnRecoverLiveView(const std::vector &keys); + ErrCode CollaborateFilter(const sptr &request); void HandleUpdateLiveViewNotificationTimer(const int32_t uid, const bool isPaused); void CancelWantAgent(const sptr ¬ification); void CancelOnceWantAgent(const std::shared_ptr &wantAgent); diff --git a/services/ans/include/distributed_device_status.h b/services/ans/include/distributed_device_status.h index 34946459f6f2be7d63847e31e3f8604d47311c8d..f4f8826527cfc4ee5e7d10525ef6895bd792dea2 100644 --- a/services/ans/include/distributed_device_status.h +++ b/services/ans/include/distributed_device_status.h @@ -55,7 +55,7 @@ private: SafeMap deviceStatus_; public: - static constexpr int32_t USERID_FLAG = 16; + static constexpr int32_t USERID_FLAG = 5; static constexpr int32_t STATUS_SIZE = 4; static constexpr int32_t USING_FLAG = 0; static constexpr int32_t LOCK_FLAG = 1; diff --git a/services/ans/include/notification_extension/distributed_extension_service.h b/services/ans/include/notification_extension/distributed_extension_service.h index e6aeaf70ba00ed4cfc667dec6ee35b94948e35d9..292fe96331523fd52d0f140a76f673df1fae97f8 100644 --- a/services/ans/include/notification_extension/distributed_extension_service.h +++ b/services/ans/include/notification_extension/distributed_extension_service.h @@ -49,6 +49,7 @@ public: bool initConfig(); int32_t InitDans(); int32_t ReleaseLocalDevice(); + void OnAllConnectOnline(); void OnDeviceOnline(const DmDeviceInfo &deviceInfo); void OnDeviceOffline(const DmDeviceInfo &deviceInfo); void OnDeviceChanged(const DmDeviceInfo &deviceInfo); diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 7259e3da377191e0e4da86bd9c1fb89938b93ba0..39c8078d1ba371fd795437c21f03712475f771bb 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -58,6 +58,7 @@ #include "advanced_notification_flow_control_service.h" #include "notification_operation_info.h" #include "notification_operation_service.h" +#include "bool_wrapper.h" namespace OHOS { namespace Notification { @@ -171,6 +172,53 @@ ErrCode AdvancedNotificationService::SetCollaborateRequest(const sptr &request) +{ + auto params = request->GetExtendInfo(); + if (params == nullptr) { + ANS_LOGI("Collaborate filter extend info is null."); + return ERR_OK; + } + + auto value = params->GetParam("notification_collaboration_check"); + AAFwk::IBoolean* ao = AAFwk::IBoolean::Query(value); + if (ao == nullptr) { + ANS_LOGI("Collaborate filter invalid extend info."); + return ERR_OK; + } + if (!AAFwk::Boolean::Unbox(ao)) { + ANS_LOGI("Collaborate filter check is false."); + return ERR_OK; + } + bool switchEnabled = false; + std::string deviceType = params->GetStringParam("notification_collaboration_deviceType"); + std::string deviceId = params->GetStringParam("notification_collaboration_deviceId"); + int32_t userId = params->GetIntParam("notification_collaboration_userId", DEFAULT_USER_ID); + auto result = NotificationPreferences::GetInstance()->GetDistributedAuthStatus(deviceType, + deviceId, userId, switchEnabled); + if (result != ERR_OK || !switchEnabled) { + ANS_LOGW("Collaborate live view auth %{public}d %{public}d.", result, switchEnabled); + return ERR_ANS_NOT_ALLOWED; + } + NotificationConstant::SlotType slotType = request->GetSlotType(); + if (slotType == NotificationConstant::SlotType::LIVE_VIEW) { + result = NotificationPreferences::GetInstance()->IsDistributedEnabledBySlot( + NotificationConstant::SlotType::LIVE_VIEW, deviceType, switchEnabled); + if (result != ERR_OK || !switchEnabled) { + ANS_LOGW("Get live view distributed failed %{public}d %{public}d.", result, switchEnabled); + return ERR_ANS_NOT_ALLOWED; + } + return ERR_OK; + } + NotificationConstant::ENABLE_STATUS enable; + result = NotificationPreferences::GetInstance()->IsDistributedEnabled(deviceType, enable); + if (result != ERR_OK || enable != NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) { + ANS_LOGW("Get notification distributed failed %{public}d %{public}d.", result, enable); + return ERR_ANS_NOT_ALLOWED; + } + return ERR_OK; +} + ErrCode AdvancedNotificationService::CollaboratePublish(const sptr &request) { auto tokenCaller = IPCSkeleton::GetCallingTokenID(); @@ -189,7 +237,9 @@ ErrCode AdvancedNotificationService::CollaboratePublish(const sptrbundleOption = new (std::nothrow) NotificationBundleOption(request->GetCreatorBundleName(), 0); record->notification->SetKey(request->GetLabel() + request->GetDistributedHashCode()); - + if (CollaborateFilter(request) != ERR_OK) { + return ERR_ANS_NOT_ALLOWED; + } if (notificationSvrQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/advanced_notification_service_ability.cpp b/services/ans/src/advanced_notification_service_ability.cpp index a1d06afd40c6a9c4dd71b2af241010982d429ad5..df31576ea89135c65a0828cbdbf0f9acf2552ce6 100644 --- a/services/ans/src/advanced_notification_service_ability.cpp +++ b/services/ans/src/advanced_notification_service_ability.cpp @@ -20,6 +20,7 @@ #include "liveview_all_scenarios_extension_wrapper.h" #include "distributed_device_manager.h" #include "advanced_datashare_helper.h" +#include "distributed_extension_service.h" namespace OHOS { namespace Notification { @@ -29,6 +30,7 @@ REGISTER_SYSTEM_ABILITY_BY_ID(AdvancedNotificationServiceAbility, ADVANCED_NOTIF const std::string EXTENSION_BACKUP = "backup"; const std::string EXTENSION_RESTORE = "restore"; +const int32_t ALL_CONNECT_SA_ID = 70633; AdvancedNotificationServiceAbility::AdvancedNotificationServiceAbility(const int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate), service_(nullptr) @@ -59,6 +61,7 @@ void AdvancedNotificationServiceAbility::OnStart() TEL_EXTENTION_WRAPPER->InitTelExtentionWrapper(); #endif AddSystemAbilityListener(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); + AddSystemAbilityListener(ALL_CONNECT_SA_ID); } void AdvancedNotificationServiceAbility::OnStop() @@ -105,6 +108,8 @@ void AdvancedNotificationServiceAbility::OnAddSystemAbility(int32_t systemAbilit } else if (systemAbilityId == DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID) { ANS_LOGW("DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID"); DistributedDeviceManager::GetInstance().RegisterDms(true); + } else if (systemAbilityId == ALL_CONNECT_SA_ID) { + DistributedExtensionService::GetInstance().OnAllConnectOnline(); } } diff --git a/services/ans/src/distributed_device_status.cpp b/services/ans/src/distributed_device_status.cpp index dbd2d66415b38ab74182ae5c810d59c96c2fcdab..49974dcbe8ce9ea5034f5ab3190c1d8a4e1fa66d 100644 --- a/services/ans/src/distributed_device_status.cpp +++ b/services/ans/src/distributed_device_status.cpp @@ -16,6 +16,7 @@ #include "distributed_device_status.h" #include "distributed_data_define.h" +#include "distributed_extension_service.h" namespace OHOS { namespace Notification { @@ -59,7 +60,8 @@ ErrCode DistributedDeviceStatus::SetDeviceStatus(const std::string &deviceType, return ERR_OK; } -void ChangeStatus(DeviceStatus& device, const uint32_t status, const uint32_t controlFlag, int32_t userId) +void ChangeStatus(DeviceStatus& device, const std::string &deviceType, const uint32_t status, + const uint32_t controlFlag, int32_t userId) { uint32_t beforeStatus = device.status; if ((1 << DistributedDeviceStatus::USERID_FLAG) & controlFlag) { @@ -73,8 +75,20 @@ void ChangeStatus(DeviceStatus& device, const uint32_t status, const uint32_t co device.status &= ~(1 << i); } } + if (deviceType == NotificationConstant::PAD_DEVICE_TYPE || + deviceType == NotificationConstant::PC_DEVICE_TYPE) { + if (((1 << DistributedDeviceStatus::USING_FLAG) & controlFlag) && + ((1 << DistributedDeviceStatus::USING_FLAG) & device.status)) { + DeviceStatueChangeInfo changeInfo; + changeInfo.deviceId = device.deviceId; + changeInfo.changeType = DeviceStatueChangeType::DEVICE_USING_CHANGE; + DistributedExtensionService::GetInstance().DeviceStatusChange(changeInfo); + ANS_LOGI("notify %{public}s %{public}s using change.", device.deviceType.c_str(), + StringAnonymous(device.deviceId).c_str()); + } + } - ANS_LOGI("update %{public}s %{public}s %{public}d status %{public}d %{public}u%{public}u", + ANS_LOGI("update %{public}s %{public}s %{public}d status %{public}d %{public}u %{public}u", device.deviceType.c_str(), StringAnonymous(device.deviceId).c_str(), userId, controlFlag, beforeStatus, device.status); } @@ -89,14 +103,14 @@ ErrCode DistributedDeviceStatus::SetDeviceStatus(const std::string &deviceType, if (device->deviceType != deviceType || device->deviceId != deviceId) { continue; } - ChangeStatus(*device, status, controlFlag, userId); + ChangeStatus(*device, deviceType, status, controlFlag, userId); existFlag = true; break; } if (!existFlag) { DeviceStatus device = DeviceStatus(deviceType, deviceId); - ChangeStatus(device, status, controlFlag, userId); + ChangeStatus(device, deviceType, status, controlFlag, userId); deviceInfo_.emplace_back(device); ANS_LOGI("Add device %{public}s %{public}s", deviceType.c_str(), StringAnonymous(deviceId).c_str()); } diff --git a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp index 18eb9b8facf010d17e981be22b72742a94b5964f..536c9c2841feb8ce9a9f5d736873064557833092 100644 --- a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp +++ b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp @@ -41,6 +41,7 @@ #include "notification_analytics_util.h" #include "notification_operation_service.h" #include "distributed_device_data_service.h" +#include "distributed_extension_service.h" namespace OHOS { namespace Notification { @@ -93,7 +94,18 @@ ErrCode AdvancedNotificationService::SetDistributedEnabledBySlot( ErrCode result = NotificationPreferences::GetInstance()->SetDistributedEnabledBySlot(slotType, deviceType, enabled); - + if (result == ERR_OK && slotType == NotificationConstant::SlotType::LIVE_VIEW) { + NotificationConstant::ENABLE_STATUS notification = NotificationConstant::ENABLE_STATUS::ENABLE_NONE; + if (NotificationPreferences::GetInstance()->IsDistributedEnabled(deviceType, + notification) != ERR_OK) { + ANS_LOGW("Get notification distributed failed %{public}s!", deviceType.c_str()); + } + DeviceStatueChangeInfo changeInfo; + changeInfo.enableChange = (notification == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) ? true : false; + changeInfo.liveViewChange = enabled; + changeInfo.changeType = DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE; + DistributedExtensionService::GetInstance().DeviceStatusChange(changeInfo); + } ANS_LOGI("SetDistributedEnabledBySlot %{public}d, deviceType: %{public}s, enabled: %{public}s, " "SetDistributedEnabledBySlot result: %{public}d", slotType, deviceType.c_str(), std::to_string(enabled).c_str(), result); @@ -624,26 +636,41 @@ ErrCode AdvancedNotificationService::IsDistributedEnabledByBundle(const sptrSetDistributedEnabled(deviceType, - enabled? NotificationConstant::ENABLE_STATUS::ENABLE_TRUE : NotificationConstant::ENABLE_STATUS::ENABLE_FALSE); + auto result = NotificationPreferences::GetInstance()->SetDistributedEnabled(deviceType, + enabled ? NotificationConstant::ENABLE_STATUS::ENABLE_TRUE : NotificationConstant::ENABLE_STATUS::ENABLE_FALSE); + if (result == ERR_OK) { + bool liveViewEnabled = false; + if (NotificationPreferences::GetInstance()->IsDistributedEnabledBySlot( + NotificationConstant::SlotType::LIVE_VIEW, deviceType, liveViewEnabled) != ERR_OK) { + ANS_LOGW("Get live view distributed failed %{public}s!", deviceType.c_str()); + } + DeviceStatueChangeInfo changeInfo; + changeInfo.enableChange = enabled; + changeInfo.liveViewChange = liveViewEnabled; + changeInfo.changeType = DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE; + DistributedExtensionService::GetInstance().DeviceStatusChange(changeInfo); + } + return result; } ErrCode AdvancedNotificationService::IsDistributedEnabled(const std::string &deviceType, bool &enabled) { ANS_LOGD("%{public}s", __FUNCTION__); - if (!AccessTokenHelper::IsSystemApp()) { - ANS_LOGD("IsSystemApp is bogus."); + bool isSubSystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubSystem && !AccessTokenHelper::IsSystemApp()) { + ANS_LOGW("Not system app or SA!"); return ERR_ANS_NON_SYSTEM_APP; } NotificationConstant::ENABLE_STATUS enableStatus; ErrCode errResult = NotificationPreferences::GetInstance()->IsDistributedEnabled(deviceType, enableStatus); - enabled = enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE; + enabled = (enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE); return errResult; } diff --git a/services/ans/src/notification_extension/distributed_device_data_service.cpp b/services/ans/src/notification_extension/distributed_device_data_service.cpp index cd82c3b1e887236bfc55b2e55d06e9d92d301ae4..d68776ebc7e41dfe5fde5df433b39f817923abb9 100644 --- a/services/ans/src/notification_extension/distributed_device_data_service.cpp +++ b/services/ans/src/notification_extension/distributed_device_data_service.cpp @@ -48,7 +48,7 @@ int32_t DistributedDeviceDataService::SetDeviceSyncSwitch(const std::string& dev if (itemIter->deviceType == deviceType && itemIter->deviceId == deviceId) { itemIter->liveViewSyncEnable = liveViewEnable; itemIter->notificationSyncEnable = notificationEnable; - ANS_LOGW("Set device %{public}s %{public}d %{public}d", StringAnonymous(deviceId).c_str(), + ANS_LOGI("Set device %{public}s %{public}d %{public}d", StringAnonymous(deviceId).c_str(), notificationEnable, liveViewEnable); return ERR_OK; } @@ -73,14 +73,14 @@ int32_t DistributedDeviceDataService::SetDeviceSyncSwitch(const std::string& dev int32_t DistributedDeviceDataService::SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, int operatorType, const std::vector& bundleList) { - ANS_LOGW("Set bundles %{public}s %{public}s %{public}d %{public}zu.", StringAnonymous(deviceId).c_str(), - deviceType.c_str(), operatorType, bundleList.size()); std::lock_guard lock(lock_); for (auto itemIter = devicesData_.begin(); itemIter != devicesData_.end(); itemIter++) { if (itemIter->deviceType != deviceType || itemIter->deviceId != deviceId) { continue; } - + ANS_LOGI("Set bundles %{public}s %{public}s %{public}d %{public}zu %{public}zu.", + StringAnonymous(deviceId).c_str(), deviceType.c_str(), operatorType, + itemIter->installedBundles.size(), bundleList.size()); if (operatorType == BunleListOperationType::ADD_BUNDLES) { for (auto& bundle : bundleList) { itemIter->installedBundles.insert(bundle); @@ -96,6 +96,8 @@ int32_t DistributedDeviceDataService::SetTargetDeviceBundleList(const std::strin if (operatorType == BunleListOperationType::RELEASE_BUNDLES) { itemIter->installedBundles.clear(); } + ANS_LOGI("After Set bundles %{public}s %{public}d %{public}zu.", + deviceType.c_str(), operatorType, itemIter->installedBundles.size()); return ERR_OK; } @@ -112,7 +114,8 @@ int32_t DistributedDeviceDataService::SetTargetDeviceBundleList(const std::strin deviceData.installedBundles.insert(bundle); } devicesData_.emplace_back(deviceData); - ANS_LOGI("Set device add %{public}s %{public}zu", StringAnonymous(deviceId).c_str(), bundleList.size()); + ANS_LOGI("Set device add %{public}s %{public}s %{public}zu", StringAnonymous(deviceId).c_str(), + deviceType.c_str(), bundleList.size()); return ERR_OK; } diff --git a/services/ans/src/notification_extension/distributed_extension_service.cpp b/services/ans/src/notification_extension/distributed_extension_service.cpp index ad226e0664837865c6551ace48a65c5223a2d07e..1b8c312fb63857b603cff5c75d7fdc28c4f410a2 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -18,6 +18,7 @@ #include "ans_log_wrapper.h" #include "event_report.h" #include "notification_analytics_util.h" +#include "distributed_device_data_service.h" #include @@ -67,11 +68,34 @@ std::string TransDeviceTypeToName(uint16_t deviceType_) return "Watch"; } case DmDeviceType::DEVICE_TYPE_PAD: { - return "Pad"; + return "Tablet"; } case DmDeviceType::DEVICE_TYPE_PHONE: { return "Phone"; } + case DmDeviceType::DEVICE_TYPE_2IN1: { + return "Pc"; + } + case DmDeviceType::DEVICE_TYPE_PC: { + return "Pc"; + } + default: + return ""; + } +} + +std::string DeviceTypeToTypeString(uint16_t deviceType) +{ + switch (deviceType) { + case DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD: { + return "pad"; + } + case DistributedHardware::DmDeviceType::DEVICE_TYPE_PC: { + return "pc"; + } + case DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1: { + return "pc"; + } default: return ""; } @@ -251,6 +275,8 @@ void DistributedExtensionService::OnDeviceOnline(const DmDeviceInfo &deviceInfo) return; } std::lock_guard lock(mapLock_); + DistributedDeviceDataService::GetInstance().ResetTargetDevice( + DeviceTypeToTypeString(deviceInfo.deviceTypeId), deviceInfo.deviceId); handler(deviceInfo.deviceId, deviceInfo.deviceTypeId, deviceInfo.networkId); std::string reason = "deviceType: " + std::to_string(deviceInfo.deviceTypeId) + " ; deviceId: " + StringAnonymous(deviceInfo.deviceId) + " ; networkId: " + @@ -382,6 +408,14 @@ void DistributedExtensionService::OnDeviceChanged(const DmDeviceInfo &deviceInfo distributedQueue_->submit(changeTask); } +void DistributedExtensionService::OnAllConnectOnline() +{ + DeviceStatueChangeInfo changeInfo; + changeInfo.enableChange = true; + changeInfo.changeType = DeviceStatueChangeType::ALL_CONNECT_STATUS_CHANGE; + DeviceStatusChange(changeInfo); +} + void DistributedExtensionService::DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo) { if (distributedQueue_ == nullptr) { diff --git a/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp b/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp index 63e52c7be38f2ccd82a70aaf5d3661f275027649..27d18cf2344966b9399488207c6931cb327f851b 100644 --- a/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp +++ b/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp @@ -452,9 +452,9 @@ void SmartReminderCenter::FillRequestExtendInfo(const string &deviceType, Device extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_APP_ICON, AAFwk::String::Box(appInfo.icon)); extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_APP_INDEX, AAFwk::Integer::Box(appInfo.appIndex)); - extendInfo->SetParam(EXTEND_INFO_PRE + "_" + deviceType + "_" + EXTEND_INFO_DEVICE_ID, + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_DEVICE_ID + "_" + deviceType, AAFwk::String::Box(deviceStatus.deviceId)); - extendInfo->SetParam(EXTEND_INFO_PRE + "_" + deviceType + "_" + EXTEND_INFO_USER_ID, + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_USER_ID + "_" + deviceType, AAFwk::Integer::Box(deviceStatus.userId)); return; } diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 9c60da4d5373af7e261a27a0bacba633c77620bf..87ab3b7c8518f90bdbfc1ecbab2e6f87d310ccaf 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -104,7 +104,6 @@ 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/base/distributed_liveview_all_scenarios_extension_wrapper.h b/services/distributed/include/base/distributed_liveview_all_scenarios_extension_wrapper.h index 51df956f67cea709f3608f0ef9ce9d87994206a7..fc4be0046dbdb2008876f9668c8bf991df6d7613 100644 --- a/services/distributed/include/base/distributed_liveview_all_scenarios_extension_wrapper.h +++ b/services/distributed/include/base/distributed_liveview_all_scenarios_extension_wrapper.h @@ -35,11 +35,17 @@ public: std::vector &buffer); typedef ErrCode (*TRIGGER_PUSH_WANT_AGENT)(const sptr &request, int32_t actionType, const AAFwk::WantParams extraInfo); + typedef ErrCode (*SUBSCRIBE_ALL_CONNECT)(); + typedef ErrCode (*UnSUBSCRIBE_ALL_CONNECT)(); ErrCode UpdateLiveviewDecodeContent(const sptr &request, std::vector &buffer); ErrCode TriggerPushWantAgent(const sptr &request, int32_t actionType, const AAFwk::WantParams extraInfo); + ErrCode SubscribeAllConnect(); + ErrCode UnSubscribeAllConnect(); private: void* ExtensionHandle_ = nullptr; + SUBSCRIBE_ALL_CONNECT subscribeHandler_ = nullptr; + UnSUBSCRIBE_ALL_CONNECT unSubscribeHandler_ = nullptr; TRIGGER_PUSH_WANT_AGENT triggerHandler_ = nullptr; UPDATE_LIVEVIEW_ENCODE_CONTENT updateLiveviewEncodeContent_ = nullptr; UPDATE_LIVEVIEW_DECODE_CONTENT updateLiveviewDecodeContent_ = nullptr; diff --git a/services/distributed/include/helper/device_type_helper.h b/services/distributed/include/helper/device_type_helper.h deleted file mode 100644 index 85459110851005566201f8f3aaec04c05a479054..0000000000000000000000000000000000000000 --- a/services/distributed/include/helper/device_type_helper.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -* 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_device_service.h b/services/distributed/include/soft_bus/distributed_device_service.h index 1a52e937d7c185a8b408ce17cecc665a2264bda1..eacf4e071e0c984b684a5d68440645c9612ea6c7 100644 --- a/services/distributed/include/soft_bus/distributed_device_service.h +++ b/services/distributed/include/soft_bus/distributed_device_service.h @@ -18,6 +18,7 @@ #include "distributed_device_data.h" +#include #include "match_box.h" namespace OHOS { @@ -38,6 +39,9 @@ public: bool IsReportDataByHa(); void InitLocalDevice(const std::string &deviceId, uint16_t deviceType); DistributedDeviceInfo GetLocalDevice(); + void SetSubscribeAllConnect(bool subscribe); + bool IsSubscribeAllConnect(); + bool CheckNeedSubscribeAllConnect(); bool IsSyncLiveView(const std::string& deviceId, bool forceSync); bool IsSyncIcons(const std::string& deviceId, bool forceSync); bool IsSyncInstalledBundle(const std::string& deviceId, bool forceSync); @@ -59,6 +63,8 @@ public: #endif private: + std::mutex mapLock_; + bool subscribeAllConnect = false; DistributedDeviceInfo localDevice_; std::map peerDevice_; }; diff --git a/services/distributed/include/soft_bus/distributed_publish_service.h b/services/distributed/include/soft_bus/distributed_publish_service.h index 635eee5b448d0c48283371de2fee49d0bab047e1..44edf6a7a626b5c92f652b337f7360026d5535ca 100644 --- a/services/distributed/include/soft_bus/distributed_publish_service.h +++ b/services/distributed/include/soft_bus/distributed_publish_service.h @@ -38,6 +38,8 @@ public: void SyncLiveViewNotification(const DistributedDeviceInfo peerDevice, bool isForce); void SendNotifictionRequest(const std::shared_ptr request, const DistributedDeviceInfo& peerDevice, bool isSyncNotification = false); + void SetNotificationExtendInfo(const sptr notificationRequest, + int32_t deviceType, std::shared_ptr& requestBox); private: void SyncNotifictionList(const DistributedDeviceInfo& peerDevice, const std::vector& notificationList); @@ -49,6 +51,7 @@ private: void PublishNotification(const std::shared_ptr& boxMessage); void PublishSynchronousLiveView(const std::shared_ptr& boxMessage); private: + void MakeExtendInfo(const NotificationRequestBox& box, sptr& request); void MakeNotificationButtons(const NotificationRequestBox& box, NotificationConstant::SlotType slotType, sptr& request); void MakeNotificationContent(const NotificationRequestBox& box, sptr& request, diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index a3892cdfc5930396d18fae455dfa5c31613aa346..717e8c989b368a098e36ec745298b2befaa109b4 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -52,6 +52,7 @@ public: void OnReceiveMsg(const void *data, uint32_t dataLen); #ifdef DISTRIBUTED_FEATURE_MASTER void HandleBundlesEvent(const std::string& bundleName, const std::string& action); + void HandleDeviceUsingChange(const DeviceStatueChangeInfo& changeInfo); #else void SyncDeviceStatus(int32_t status); void SyncInstalledBundle(const std::string& bundleName, bool isAdd); diff --git a/services/distributed/include/tlv_box/request_box.h b/services/distributed/include/tlv_box/request_box.h index bc323e3865d06e791017812665112da119eae495..81e94c8f038d4c105117da6bd5797efecb0f94f2 100644 --- a/services/distributed/include/tlv_box/request_box.h +++ b/services/distributed/include/tlv_box/request_box.h @@ -46,12 +46,19 @@ public: bool SetNotificationBigPicture(const std::shared_ptr& bigPicture); bool SetNotificationActionName(const std::string& actionName); bool SetNotificationUserInput(const std::string& userInput); - bool SetBigIcon(const std::shared_ptr& bigIcon); - bool SetOverlayIcon(const std::shared_ptr& overlayIcon); + bool SetSmallIcon(const std::string& icon); + bool SetBigIcon(const std::shared_ptr& bigIcon, int32_t deviceType); + bool SetOverlayIcon(const std::shared_ptr& overlayIcon, int32_t deviceType); bool SetCommonLiveView(const std::vector& byteSequence); bool SetFinishTime(int64_t time); bool SetAutoDeleteTime(int64_t time); bool SetAppMessageId(const std::string& appMessageId); + bool SetAppName(const std::string& appName); + bool SetAppLabel(const std::string& appLabel); + bool SetAppIndex(const int32_t& appIndex); + bool SetNotificationUserId(const int32_t& userId); + bool SetDeviceUserId(const int32_t& userId); + bool SetDeviceId(const std::string& deviceId); #else bool GetNotificationHashCode(std::string& hasdCode) const; @@ -70,12 +77,19 @@ public: bool GetNotificationBigPicture(std::shared_ptr& bigPicture) const; bool GetNotificationActionName(std::string& actionName) const; bool GetNotificationUserInput(std::string& userInput) const; + bool GetSmallIcon(std::shared_ptr& smallIcon) const; bool GetBigIcon(std::shared_ptr& bigIcon) const; bool GetOverlayIcon(std::shared_ptr& overlayIcon) const; bool GetCommonLiveView(std::vector& byteSequence) const; bool GetFinishTime(int64_t& time) const; bool GetAutoDeleteTime(int64_t& time) const; bool GetAppMessageId(std::string& appMessageId) const; + bool GetAppName(std::string& appName) const; + bool GetAppLabel(std::string& appLabel) const; + bool GetAppIndex(int32_t& appIndex) const; + bool GetNotificationUserId(int32_t& userId) const; + bool GetDeviceUserId(int32_t& userId) const; + bool GetDeviceId(std::string& deviceId) const; #endif }; } // namespace Notification diff --git a/services/distributed/include/tlv_box/tlv_box.h b/services/distributed/include/tlv_box/tlv_box.h index 4aace3a5a2f1997cd7cc61fc16a203368b286716..309b0bf9d7a285f8afa94ba642f58afcf3c0c983 100644 --- a/services/distributed/include/tlv_box/tlv_box.h +++ b/services/distributed/include/tlv_box/tlv_box.h @@ -63,6 +63,11 @@ enum TlvType : int32_t { NOTIFICATION_LONG_TITLE = 22, ALL_LINES_LENGTH = 23, NOTIFICATION_APP_MESSAGE_ID = 24, + NOTIFICATION_USERID = 982, + DEVICE_USERID = 983, + APP_INDEX = 984, + APP_LABEL = 985, + APP_NAME = 986, LIVEVIEW_SYNC_ENABLE = 987, NOTIFICATION_SYNC_ENABLE = 988, RESULT_CODE = 989, diff --git a/services/distributed/libdans.map b/services/distributed/libdans.map index bfed70f1b94061d0b6f55657162f887107b701c9..fbcc6557308e25865544673a22b3b7bc7cc93278 100644 --- a/services/distributed/libdans.map +++ b/services/distributed/libdans.map @@ -20,6 +20,7 @@ ReleaseLocalDevice; InitHACallBack; InitSendReportCallBack; + DeviceStatusChange; local: *; }; diff --git a/services/distributed/src/base/distributed_liveview_all_scenarios_extension_wrapper.cpp b/services/distributed/src/base/distributed_liveview_all_scenarios_extension_wrapper.cpp index 944310a1b9512b1e81be6b108877f7055bacc594..577e864bb36269f3156303ea5d213eda2797bd1a 100644 --- a/services/distributed/src/base/distributed_liveview_all_scenarios_extension_wrapper.cpp +++ b/services/distributed/src/base/distributed_liveview_all_scenarios_extension_wrapper.cpp @@ -59,6 +59,16 @@ void DistributedLiveviewAllScenariosExtensionWrapper::InitExtentionWrapper() ANS_LOGE("distributed liveview all trigger failed, error: %{public}s", dlerror()); return; } + subscribeHandler_ = (SUBSCRIBE_ALL_CONNECT)dlsym(ExtensionHandle_, "SubscribeAllConnect"); + if (subscribeHandler_ == nullptr) { + ANS_LOGE("distributed subscribe all conncet failed, error: %{public}s", dlerror()); + return; + } + unSubscribeHandler_ = (UnSUBSCRIBE_ALL_CONNECT)dlsym(ExtensionHandle_, "UnSubscribeAllConnect"); + if (unSubscribeHandler_ == nullptr) { + ANS_LOGE("distributed unsubscribe all conncet failed, error: %{public}s", dlerror()); + return; + } ANS_LOGI("distributed liveview all scenarios extension wrapper init success"); } @@ -66,6 +76,8 @@ void DistributedLiveviewAllScenariosExtensionWrapper::CloseExtentionWrapper() { if (ExtensionHandle_ != nullptr) { dlclose(ExtensionHandle_); + subscribeHandler_ = nullptr; + unSubscribeHandler_ = nullptr; ExtensionHandle_ = nullptr; triggerHandler_ = nullptr; updateLiveviewEncodeContent_ = nullptr; @@ -103,4 +115,22 @@ ErrCode DistributedLiveviewAllScenariosExtensionWrapper::TriggerPushWantAgent( } return triggerHandler_(request, actionType, extraInfo); } + +ErrCode DistributedLiveviewAllScenariosExtensionWrapper::SubscribeAllConnect() +{ + if (subscribeHandler_ == nullptr) { + ANS_LOGE("Subscribe all connect wrapper symbol failed"); + return 0; + } + return subscribeHandler_(); +} + +ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UnSubscribeAllConnect() +{ + if (unSubscribeHandler_ == nullptr) { + ANS_LOGE("UnSubscribe all connect wrapper symbol failed"); + return 0; + } + return unSubscribeHandler_(); +} } diff --git a/services/distributed/src/helper/device_type_helper.cpp b/services/distributed/src/helper/device_type_helper.cpp deleted file mode 100644 index 3f0f32e27be750f1c4d28ef1515a74e976ce7bbb..0000000000000000000000000000000000000000 --- a/services/distributed/src/helper/device_type_helper.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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_bundle_service.cpp b/services/distributed/src/soft_bus/distributed_bundle_service.cpp index b98ce0779bcac4fea08d2ffacd7e07eb9874315b..486655551e95b89021e7b15c7628a0f927420386 100644 --- a/services/distributed/src/soft_bus/distributed_bundle_service.cpp +++ b/services/distributed/src/soft_bus/distributed_bundle_service.cpp @@ -366,16 +366,12 @@ void DistributedBundleService::SyncInstalledBundles(const DistributedDeviceInfo& { auto localDevice = DistributedDeviceService::GetInstance().GetLocalDevice(); if (localDevice.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD && + localDevice.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1 && localDevice.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { return; } - bool isSync = false; - if (DistributedDeviceService::GetInstance().IsSyncInstalledBundle(peerDevice.deviceId_, isSync) != ERR_OK) { - return; - } - if (!isForce && isSync) { - ANS_LOGI("Dans %{public}d %{public}d.", isForce, isSync); + if (!DistributedDeviceService::GetInstance().IsSyncInstalledBundle(peerDevice.deviceId_, isForce)) { return; } @@ -413,6 +409,10 @@ void DistributedBundleService::SendInstalledBundles(const DistributedDeviceInfo& iconBox->SetLocalDeviceId(localDeviceId); iconBox->SetIconSyncType(type); iconBox->SetBundleList(bundles); + if (!iconBox->Serialize()) { + ANS_LOGW("Dans SendInstalledBundles serialize failed."); + return; + } DistributedClient::GetInstance().SendMessage(iconBox, TransDataType::DATA_TYPE_MESSAGE, peerDevice.deviceId_, MODIFY_ERROR_EVENT_CODE); diff --git a/services/distributed/src/soft_bus/distributed_device_service.cpp b/services/distributed/src/soft_bus/distributed_device_service.cpp index c1172d002a81d3649abae40ffbb6716bc7a5896e..527ba1dc7fa53fe72c5e614fa9c52fcd59d684e1 100644 --- a/services/distributed/src/soft_bus/distributed_device_service.cpp +++ b/services/distributed/src/soft_bus/distributed_device_service.cpp @@ -42,13 +42,19 @@ std::string DistributedDeviceService::DeviceTypeToTypeString(uint16_t deviceType return "wearable"; } case DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD: { - return "Pad"; + return "pad"; + } + case DistributedHardware::DmDeviceType::DEVICE_TYPE_PC: { + return "pc"; + } + case DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1: { + return "pc"; } case DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE: { - return "Phone"; + return "phone"; } default: - return std::string(); + return ""; } } @@ -68,15 +74,44 @@ bool DistributedDeviceService::IsReportDataByHa() return localDevice_.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH; } +void DistributedDeviceService::SetSubscribeAllConnect(bool subscribe) +{ + subscribeAllConnect = subscribe; +} + +bool DistributedDeviceService::IsSubscribeAllConnect() +{ + return subscribeAllConnect; +} + +bool DistributedDeviceService::CheckNeedSubscribeAllConnect() +{ + std::lock_guard lock(mapLock_); + for (auto& device : peerDevice_) { + if (device.second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD || + device.second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1 || + device.second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { + return true; + } + } + return false; +} + bool DistributedDeviceService::IsSyncLiveView(const std::string& deviceId, bool forceSync) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device is data %{public}s.", StringAnonymous(deviceId).c_str()); return false; } - if (iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD || - iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { + + if (iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC || + iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1) { + ANS_LOGI("Dans device pc no need sync %{public}s.", StringAnonymous(deviceId).c_str()); + return false; + } + if (iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD) { if (!iter->second.deviceUsage || iter->second.peerState_ != DeviceState::STATE_SYNC) { return false; } @@ -91,11 +126,15 @@ bool DistributedDeviceService::IsSyncLiveView(const std::string& deviceId, bool bool DistributedDeviceService::IsSyncIcons(const std::string& deviceId, bool forceSync) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device is data %{public}s.", StringAnonymous(deviceId).c_str()); return false; } + if (iter->second.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + return false; + } if (!forceSync && iter->second.iconSync) { ANS_LOGI("Dans icon sync %{public}d %{public}d.", forceSync, iter->second.iconSync); @@ -106,12 +145,17 @@ bool DistributedDeviceService::IsSyncIcons(const std::string& deviceId, bool for bool DistributedDeviceService::IsSyncInstalledBundle(const std::string& deviceId, bool forceSync) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device is data %{public}s.", StringAnonymous(deviceId).c_str()); return false; } + if (iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + return false; + } + if (!forceSync && iter->second.installedBunlesSync) { ANS_LOGI("Dans bundle sync %{public}d %{public}d.", forceSync, iter->second.installedBunlesSync); return false; @@ -121,6 +165,7 @@ bool DistributedDeviceService::IsSyncInstalledBundle(const std::string& deviceId void DistributedDeviceService::SetDeviceSyncData(const std::string& deviceId, int32_t type, bool syncData) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device set data %{public}s.", StringAnonymous(deviceId).c_str()); @@ -142,6 +187,7 @@ void DistributedDeviceService::SetDeviceSyncData(const std::string& deviceId, in void DistributedDeviceService::SetDeviceState(const std::string& deviceId, int32_t state) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device set status %{public}s.", StringAnonymous(deviceId).c_str()); @@ -152,6 +198,7 @@ void DistributedDeviceService::SetDeviceState(const std::string& deviceId, int32 bool DistributedDeviceService::CheckDeviceExist(const std::string& deviceId) { + std::lock_guard lock(mapLock_); if (peerDevice_.find(deviceId) == peerDevice_.end()) { ANS_LOGI("Dans unknown device %{public}s.", StringAnonymous(deviceId).c_str()); return false; @@ -161,6 +208,7 @@ bool DistributedDeviceService::CheckDeviceExist(const std::string& deviceId) bool DistributedDeviceService::GetDeviceInfo(const std::string& deviceId, DistributedDeviceInfo& device) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGI("Dans get deviceId unknonw %{public}s.", StringAnonymous(deviceId).c_str()); @@ -172,13 +220,15 @@ bool DistributedDeviceService::GetDeviceInfo(const std::string& deviceId, Distri bool DistributedDeviceService::CheckDeviceNeedSync(const std::string& deviceId) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device connected %{public}s.", StringAnonymous(deviceId).c_str()); return false; } if (iter->second.connectedTry_ >= MAX_CONNECTED_TYR || iter->second.peerState_ != DeviceState::STATE_SYNC) { - ANS_LOGE("Dans no need try %{public}d.", iter->second.connectedTry_); + ANS_LOGI("Dans no need try %{public}d %{public}d.", iter->second.connectedTry_, + iter->second.peerState_); iter->second.connectedTry_ = 0; return false; } @@ -187,6 +237,7 @@ bool DistributedDeviceService::CheckDeviceNeedSync(const std::string& deviceId) void DistributedDeviceService::IncreaseDeviceSyncCount(const std::string& deviceId) { + std::lock_guard lock(mapLock_); auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device count %{public}s.", StringAnonymous(deviceId).c_str()); @@ -199,11 +250,13 @@ void DistributedDeviceService::IncreaseDeviceSyncCount(const std::string& device void DistributedDeviceService::AddDeviceInfo(DistributedDeviceInfo deviceItem) { + std::lock_guard lock(mapLock_); peerDevice_[deviceItem.deviceId_] = deviceItem; } void DistributedDeviceService::DeleteDeviceInfo(const std::string& deviceId) { + std::lock_guard lock(mapLock_); auto deviceIter = peerDevice_.find(deviceId); if (deviceIter != peerDevice_.end()) { ANS_LOGI("Delete device %{public}s.", StringAnonymous(deviceId).c_str()); @@ -213,6 +266,7 @@ void DistributedDeviceService::DeleteDeviceInfo(const std::string& deviceId) std::map& DistributedDeviceService::GetDeviceList() { + std::lock_guard lock(mapLock_); return peerDevice_; } @@ -300,6 +354,7 @@ void DistributedDeviceService::SyncDeviceStatus(int32_t type, int32_t status, ANS_LOGW("Dans SyncDeviceState serialize failed."); return; } + std::lock_guard lock(mapLock_); for (const auto& peer : peerDevice_) { DistributedClient::GetInstance().SendMessage(stateBox, TransDataType::DATA_TYPE_MESSAGE, peer.second.deviceId_, MODIFY_ERROR_EVENT_CODE); diff --git a/services/distributed/src/soft_bus/distributed_observer_service.cpp b/services/distributed/src/soft_bus/distributed_observer_service.cpp index 79e88b6e8df0178f688fe500182f4a93e8114949..7eed738dae4812def3ca7ac9cc1c0c56ac5d9493 100644 --- a/services/distributed/src/soft_bus/distributed_observer_service.cpp +++ b/services/distributed/src/soft_bus/distributed_observer_service.cpp @@ -88,6 +88,7 @@ void OberverService::Init(uint16_t deviceType) matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); #else if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD || + deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1 || deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); diff --git a/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp b/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp index 88075c2c84924b19caf4e04d67ee3afd05fe52f3..8459e1d347070930057753072707c976ff636a54 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp @@ -32,11 +32,26 @@ #include "distributed_data_define.h" #include "distributed_preference.h" #include "distributed_liveview_all_scenarios_extension_wrapper.h" +#include "bool_wrapper.h" +#include "int_wrapper.h" +#include "string_wrapper.h" +#include "distributed_subscribe_service.h" namespace OHOS { namespace Notification { static const std::string DISTRIBUTED_LABEL = "ans_distributed"; +static const std::string EXTENDINFO_INFO_PRE = "notification_collaboration_"; +static const std::string EXTENDINFO_FLAG = "flag"; +static const std::string EXTENDINFO_USERID = "userId_"; +static const std::string EXTENDINFO_APP_NAME = "app_name"; +static const std::string EXTENDINFO_APP_LABEL = "app_label"; +static const std::string EXTENDINFO_APP_ICON = "app_icon"; +static const std::string EXTENDINFO_APP_INDEX = "app_index"; +static const std::string EXTENDINFO_DEVICE_USERID = "userId"; +static const std::string EXTENDINFO_DEVICE_ID = "deviceId"; +static const std::string EXTENDINFO_ENABLE_CHECK = "check"; +static const std::string EXTENDINFO_DEVICETYPE = "deviceType"; DistributedPublishService& DistributedPublishService::GetInstance() { @@ -216,6 +231,8 @@ void DistributedPublishService::SendNotifictionRequest(const std::shared_ptrGetNotificationRequestPoint(); ANS_LOGI("Dans OnConsumed Notification key = %{public}s, notificationFlag = %{public}s", request->GetKey().c_str(), requestPoint->GetFlags() == nullptr ? "null" : requestPoint->GetFlags()->Dump().c_str()); + auto local = DistributedDeviceService::GetInstance().GetLocalDevice(); + requestBox->SetDeviceId(local.deviceId_); requestBox->SetAutoDeleteTime(requestPoint->GetAutoDeletedTime()); requestBox->SetFinishTime(requestPoint->GetFinishDeadLine()); requestBox->SetNotificationHashCode(request->GetKey()); @@ -234,17 +251,12 @@ void DistributedPublishService::SendNotifictionRequest(const std::shared_ptrSetCreatorBundleName(request->GetBundleName()); } - if (requestPoint->GetBigIcon() != nullptr) { - requestBox->SetBigIcon(requestPoint->GetBigIcon()); - } - if (requestPoint->GetOverlayIcon() != nullptr) { - requestBox->SetOverlayIcon(requestPoint->GetOverlayIcon()); - } if (requestPoint->IsCommonLiveView()) { std::vector buffer; DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewEncodeContent(requestPoint, buffer); requestBox->SetCommonLiveView(buffer); } + SetNotificationExtendInfo(requestPoint, peerDevice.deviceType_, requestBox); SetNotificationButtons(requestPoint, requestPoint->GetSlotType(), requestBox); SetNotificationContent(request->GetNotificationRequestPoint()->GetContent(), requestPoint->GetNotificationType(), requestBox); @@ -336,6 +348,43 @@ void DistributedPublishService::SetNotificationButtons(const sptr notificationRequest, + int32_t deviceType, std::shared_ptr& requestBox) +{ + if (notificationRequest->GetBigIcon() != nullptr) { + requestBox->SetBigIcon(notificationRequest->GetBigIcon(), deviceType); + } + if (notificationRequest->GetOverlayIcon() != nullptr) { + requestBox->SetOverlayIcon(notificationRequest->GetOverlayIcon(), deviceType); + } + + auto params = notificationRequest->GetExtendInfo(); + if (params == nullptr) { + ANS_LOGI("Send request invalid extend info."); + return; + } + std::string content = params->GetStringParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_NAME); + if (!content.empty()) { + requestBox->SetAppName(content); + } + content = params->GetStringParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_LABEL); + if (!content.empty()) { + requestBox->SetAppLabel(content); + } + content = params->GetStringParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_ICON); + if (!content.empty()) { + requestBox->SetSmallIcon(content); + } + int32_t appIndex = params->GetIntParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_INDEX, 0); + requestBox->SetAppIndex(appIndex); + std::string key = EXTENDINFO_INFO_PRE + EXTENDINFO_USERID + + DistributedDeviceService::DeviceTypeToTypeString(deviceType); + int32_t userId = params->GetIntParam(key, DEFAULT_USER_ID); + requestBox->SetNotificationUserId(userId); + requestBox->SetDeviceUserId(DistributedSubscribeService::GetCurrentActiveUserId()); +} + #else void DistributedPublishService::PublishNotification(const std::shared_ptr& boxMessage) { @@ -353,6 +402,7 @@ void DistributedPublishService::PublishNotification(const std::shared_ptr(contentType) == NotificationContent::Type::LIVE_VIEW) && (static_cast(slotType) == NotificationConstant::SlotType::LIVE_VIEW); } + MakeExtendInfo(requestBox, request); MakeNotificationButtons(requestBox, static_cast(slotType), request); MakeNotificationContent(requestBox, request, isCommonLiveView, contentType); MakeNotificationIcon(requestBox, request, isCommonLiveView); @@ -464,6 +514,43 @@ void DistributedPublishService::MakeNotificationReminderFlag(const NotificationR request->SetLabel(DISTRIBUTED_LABEL); } +void DistributedPublishService::MakeExtendInfo(const NotificationRequestBox& box, + sptr& request) +{ + std::string info; + std::shared_ptr extendInfo = std::make_shared(); + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_FLAG, AAFwk::Boolean::Box(true)); + auto local = DistributedDeviceService::GetInstance().GetLocalDevice(); + if (local.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_ENABLE_CHECK, AAFwk::Boolean::Box(false)); + } else { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_ENABLE_CHECK, AAFwk::Boolean::Box(true)); + if (box.GetAppLabel(info)) { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_LABEL, AAFwk::String::Box(info)); + } + if (box.GetAppName(info)) { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_NAME, AAFwk::String::Box(info)); + } + if (box.GetDeviceId(info)) { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_DEVICE_ID, AAFwk::String::Box(info)); + } + std::string deviceType = DistributedDeviceService::DeviceTypeToTypeString(local.deviceType_); + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_DEVICETYPE, AAFwk::String::Box(deviceType)); + int32_t appIndex; + if (box.GetAppIndex(appIndex)) { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_INDEX, AAFwk::Integer::Box(appIndex)); + } + int32_t userId; + if (box.GetDeviceUserId(userId)) { + extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_DEVICE_USERID, AAFwk::Integer::Box(userId)); + } + if (box.GetNotificationUserId(userId)) { + request->SetReceiverUserId(userId); + } + } + request->SetExtendInfo(extendInfo); +} + void DistributedPublishService::MakeNotificationIcon(const NotificationRequestBox& box, sptr& request, bool isCommonLiveView) { @@ -474,18 +561,8 @@ void DistributedPublishService::MakeNotificationIcon(const NotificationRequestBo if (box.GetOverlayIcon(icon)) { request->SetOverlayIcon(icon); } - - if (isCommonLiveView) { - std::string bundleName; - if (!box.GetCreatorBundleName(bundleName)) { - return; - } - std::string icon; - DistributedPreferences::GetInstance().GetIconByBundleName(bundleName, icon); - if (!icon.empty()) { - auto iconPixelMap = AnsImageUtil::UnPackImage(icon); - request->SetLittleIcon(iconPixelMap); - } + if (box.GetSmallIcon(icon)) { + request->SetLittleIcon(icon); } } diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index 612cfa0ad81456773eaf9338efee00af4fbd5b01..6df3bac0d789249a07cb6097735035645d0c39a1 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -31,7 +31,7 @@ #include "distributed_publish_service.h" #include "distributed_subscribe_service.h" #include "bundle_resource_helper.h" -#include "device_type_helper.h" +#include "distributed_liveview_all_scenarios_extension_wrapper.h" namespace OHOS { namespace Notification { @@ -99,6 +99,9 @@ void DistributedService::DestoryService() DistributedClient::GetInstance().ReleaseClient(); DistributedServer::GetInstance().ReleaseServer(); OberverService::GetInstance().Destory(); +#ifdef DISTRIBUTED_FEATURE_MASTER + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UnSubscribeAllConnect(); +#endif DistributedSubscribeService::GetInstance().UnSubscribeAllNotification(); }); serviceQueue_->wait(handler); @@ -107,7 +110,7 @@ void DistributedService::DestoryService() void DistributedService::ConnectPeerDevice(DistributedDeviceInfo device) { if (!DistributedDeviceService::GetInstance().CheckDeviceNeedSync(device.deviceId_)) { - ANS_LOGE("ConnectPeerDevice device is failed."); + ANS_LOGI("ConnectPeerDevice device is failed."); return; } @@ -159,20 +162,19 @@ void DistributedService::DeviceStatusChange(const DeviceStatueChangeInfo& change ANS_LOGE("Check handler is null."); return; } - std::function task = std::bind([changeInfo]() { + std::function task = std::bind([&, changeInfo]() { ANS_LOGI("Device change %{public}d %{public}d %{public}d", changeInfo.changeType, changeInfo.enableChange, changeInfo.liveViewChange); #ifdef DISTRIBUTED_FEATURE_MASTER if (changeInfo.changeType == DeviceStatueChangeType::DEVICE_USING_CHANGE) { - DistributedDeviceService::GetInstance().SetDeviceSyncData(changeInfo.deviceId, - DistributedDeviceService::DEVICE_USAGE, true); - DistributedDeviceInfo device; - if (DistributedDeviceService::GetInstance().GetDeviceInfo(changeInfo.deviceId, device)) { - DistributedPublishService::GetInstance().SyncLiveViewNotification(device, false); - } + HandleDeviceUsingChange(changeInfo); } if (changeInfo.changeType == DeviceStatueChangeType::ALL_CONNECT_STATUS_CHANGE) { + if (DistributedDeviceService::GetInstance().CheckNeedSubscribeAllConnect()) { + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(); + DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); + } } #else if (changeInfo.changeType == DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE) { @@ -286,6 +288,20 @@ void DistributedService::HandleBundlesEvent(const std::string& bundleName, const }); serviceQueue_->submit(task); } + +void DistributedService::HandleDeviceUsingChange(const DeviceStatueChangeInfo& changeInfo) +{ + DistributedDeviceService::GetInstance().SetDeviceSyncData(changeInfo.deviceId, + DistributedDeviceService::DEVICE_USAGE, true); + DistributedDeviceInfo device; + if (DistributedDeviceService::GetInstance().GetDeviceInfo(changeInfo.deviceId, device)) { + if (!DistributedDeviceService::GetInstance().IsSubscribeAllConnect()) { + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(); + DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); + } + DistributedPublishService::GetInstance().SyncLiveViewNotification(device, false); + } +} #else void DistributedService::OnConsumed(const std::shared_ptr &request, const DistributedDeviceInfo& peerDevice) @@ -462,7 +478,7 @@ void DistributedService::OnReceiveMsg(const void *data, uint32_t dataLen) bool DistributedService::OnConsumedSetFlags(const std::shared_ptr &request, const DistributedDeviceInfo& peerDevice) { - std::string deviceType = DeviceTypeHelper::Dm2Ans(peerDevice.deviceType_); + std::string deviceType = DistributedDeviceService::DeviceTypeToTypeString(peerDevice.deviceType_); sptr requestPoint = request->GetNotificationRequestPoint(); auto flagsMap = requestPoint->GetDeviceFlags(); if (flagsMap == nullptr || flagsMap->size() <= 0) { 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 0ac43a57ffcdf44f9b3f877302c1236f331435ec..4e355c789389df04bf5fabb7ffb011398642ce07 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp @@ -21,12 +21,12 @@ #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; +const int32_t FILTER_IM_TYPE = 1; +const int32_t FILTER_IM_REPLY_TYPE = 2; int32_t DistributedSubscribeService::GetCurrentActiveUserId() { @@ -57,12 +57,18 @@ void DistributedSubscribeService::SubscribeNotification(const DistributedDeviceI subscriber->SetLocalDevice(DistributedDeviceService::GetInstance().GetLocalDevice()); subscriber->SetPeerDevice(peerDevice); sptr subscribeInfo = new NotificationSubscribeInfo(); - std::vector slotTypes; - slotTypes.push_back(NotificationConstant::SlotType::LIVE_VIEW); - slotTypes.push_back(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - subscribeInfo->SetSlotTypes(slotTypes); - subscribeInfo->SetFilterType(DEFAULT_FILTER_TYPE); - subscribeInfo->AddDeviceType(DeviceTypeHelper::Dm2Ans(peerDevice.deviceType_)); + if (peerDevice.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + std::vector slotTypes; + slotTypes.push_back(NotificationConstant::SlotType::LIVE_VIEW); + slotTypes.push_back(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + subscribeInfo->SetSlotTypes(slotTypes); + subscribeInfo->SetFilterType(FILTER_IM_TYPE); + } else if (peerDevice.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC || + peerDevice.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_2IN1 || + peerDevice.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD) { + subscribeInfo->SetFilterType(FILTER_IM_REPLY_TYPE); + } + subscribeInfo->AddDeviceType(DistributedDeviceService::DeviceTypeToTypeString(peerDevice.deviceType_)); subscribeInfo->AddAppUserId(userId); subscribeInfo->SetNeedNotifyApplication(true); subscribeInfo->SetNeedNotifyResponse(true); diff --git a/services/distributed/src/soft_bus/distributed_subscriber.cpp b/services/distributed/src/soft_bus/distributed_subscriber.cpp index 3b74ca54500b5a0181441bc2efb0c1fe157c188f..bfec665f7bb74a6804477b6c719900a3706edb28 100644 --- a/services/distributed/src/soft_bus/distributed_subscriber.cpp +++ b/services/distributed/src/soft_bus/distributed_subscriber.cpp @@ -20,6 +20,7 @@ #include "notification_config_parse.h" #include "distributed_preferences.h" #include "distributed_local_config.h" +#include "distributed_device_service.h" namespace OHOS { namespace Notification { @@ -76,6 +77,26 @@ void DistribuedSubscriber::OnConsumed(const std::shared_ptr &reque localDevice_.deviceType_, StringAnonymous(localDevice_.deviceId_).c_str()); return; } + if (peerDevice_.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + DistributedService::GetInstance().OnConsumed(request, peerDevice_); + return; + } + if (request == nullptr || request->GetNotificationRequestPoint() == nullptr) { + return; + } + auto requestPoint = request->GetNotificationRequestPoint(); + auto params = requestPoint->GetExtendInfo(); + if (params == nullptr) { + ANS_LOGI("Dans OnConsumed invalid extend info."); + return; + } + std::string deviceId = params->GetStringParam("notification_collaboration_deviceId_" + + DistributedDeviceService::DeviceTypeToTypeString(peerDevice_.deviceType_)); + if (deviceId.empty() || deviceId != peerDevice_.deviceId_) { + ANS_LOGI("Dans OnConsumed invalid device %{public}s %{public}s.", StringAnonymous(deviceId).c_str(), + StringAnonymous(peerDevice_.deviceId_).c_str()); + return; + } DistributedService::GetInstance().OnConsumed(request, peerDevice_); } diff --git a/services/distributed/src/tlv_box/request_box.cpp b/services/distributed/src/tlv_box/request_box.cpp index 407df781e99337c937bd42268ebe29dad3901e0c..ea49b12b3d9f528aad78bb3e55d9a9a34748f2a0 100644 --- a/services/distributed/src/tlv_box/request_box.cpp +++ b/services/distributed/src/tlv_box/request_box.cpp @@ -90,7 +90,7 @@ bool NotificationRequestBox::SetNotificationTitle(const std::string& title) } uint32_t maxLength = static_cast(DistributedLocalConfig::GetInstance().GetTitleLength()); if (title.size() > maxLength) { - ANS_LOGI("SetNotificationTitle truncate %{public}d %{public}d", (int32_t)(title.size()), (int32_t)(maxLength)); + ANS_LOGI("SetNotificationTitle truncate %{public}zu %{public}u", title.size(), maxLength); std::string subTitle = title.substr(0, maxLength); ANS_LOGI("SetNotificationTitle truncate %{public}s %{public}s", subTitle.c_str(), title.c_str()); return box_->PutValue(std::make_shared(NOTIFICATION_TITLE, subTitle)); @@ -105,7 +105,7 @@ bool NotificationRequestBox::SetNotificationText(const std::string& text) } uint32_t maxLength = static_cast(DistributedLocalConfig::GetInstance().GetContentLength()); if (text.size() > maxLength) { - ANS_LOGI("SetNotificationText truncate %{public}d %{public}d", (int32_t)(text.size()), (int32_t)(maxLength)); + ANS_LOGI("SetNotificationText truncate %{public}zu %{public}u", text.size(), maxLength); std::string subText = text.substr(0, maxLength); ANS_LOGI("SetNotificationTitle truncate %{public}s %{public}s", subText.c_str(), text.c_str()); return box_->PutValue(std::make_shared(NOTIFICATION_CONTENT, subText)); @@ -188,34 +188,55 @@ bool NotificationRequestBox::SetNotificationUserInput(const std::string& userInp return box_->PutValue(std::make_shared(ACTION_USER_INPUT, userInput)); } -bool NotificationRequestBox::SetBigIcon(const std::shared_ptr& bigIcon) +bool NotificationRequestBox::SetSmallIcon(const std::string& icon) { if (box_ == nullptr) { return false; } + return box_->PutValue(std::make_shared(BUNDLE_ICON, icon)); +} - std::string copyIcon = AnsImageUtil::PackImage(bigIcon); - auto copyPixelMap = AnsImageUtil::UnPackImage(copyIcon); - if (!AnsImageUtil::ImageScale(copyPixelMap, DEFAULT_ICON_WITHE, DEFAULT_ICON_HEIGHT)) { +bool NotificationRequestBox::SetBigIcon(const std::shared_ptr& bigIcon, + int32_t deviceType) +{ + if (box_ == nullptr) { return false; } - std::string icon = AnsImageUtil::PackImage(copyPixelMap); - ANS_LOGI("SetBigIcon %{public}d, %{public}d", (int32_t)(copyIcon.size()), (int32_t)(icon.size())); + + std::string icon; + if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + std::string copyIcon = AnsImageUtil::PackImage(bigIcon); + auto copyPixelMap = AnsImageUtil::UnPackImage(copyIcon); + if (!AnsImageUtil::ImageScale(copyPixelMap, DEFAULT_ICON_WITHE, DEFAULT_ICON_HEIGHT)) { + return false; + } + icon = AnsImageUtil::PackImage(copyPixelMap); + ANS_LOGI("SetBigIcon %{public}zu, %{public}zu", copyIcon.size(), icon.size()); + } else { + icon = AnsImageUtil::PackImage(bigIcon); + } return box_->PutValue(std::make_shared(NOTIFICATION_BIG_ICON, icon)); } -bool NotificationRequestBox::SetOverlayIcon(const std::shared_ptr& overlayIcon) +bool NotificationRequestBox::SetOverlayIcon(const std::shared_ptr& overlayIcon, + int32_t deviceType) { if (box_ == nullptr) { return false; } - std::string copyIcon = AnsImageUtil::PackImage(overlayIcon); - auto copyPixelMap = AnsImageUtil::UnPackImage(copyIcon); - if (!AnsImageUtil::ImageScale(copyPixelMap, DEFAULT_ICON_WITHE, DEFAULT_ICON_HEIGHT)) { - return false; + + std::string icon; + if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) { + std::string copyIcon = AnsImageUtil::PackImage(overlayIcon); + auto copyPixelMap = AnsImageUtil::UnPackImage(copyIcon); + if (!AnsImageUtil::ImageScale(copyPixelMap, DEFAULT_ICON_WITHE, DEFAULT_ICON_HEIGHT)) { + return false; + } + icon = AnsImageUtil::PackImage(copyPixelMap); + ANS_LOGI("SetOverlayIcon %{public}zu, %{public}zu", copyIcon.size(), icon.size()); + } else { + icon = AnsImageUtil::PackImage(overlayIcon); } - std::string icon = AnsImageUtil::PackImage(copyPixelMap); - ANS_LOGI("SetOverlayIcon %{public}d, %{public}d", (int32_t)(copyIcon.size()), (int32_t)(icon.size())); return box_->PutValue(std::make_shared(NOTIFICATION_OVERLAY_ICON, icon)); } @@ -245,6 +266,54 @@ bool NotificationRequestBox::SetAutoDeleteTime(int64_t time) return box_->PutValue(std::make_shared(AUTO_DELETE_TIME, time)); } +bool NotificationRequestBox::SetAppName(const std::string& appName) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(APP_NAME, appName)); +} + +bool NotificationRequestBox::SetAppLabel(const std::string& appLabel) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(APP_LABEL, appLabel)); +} + +bool NotificationRequestBox::SetAppIndex(const int32_t& appIndex) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(APP_INDEX, appIndex)); +} + +bool NotificationRequestBox::SetNotificationUserId(const int32_t& userId) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(NOTIFICATION_USERID, userId)); +} + +bool NotificationRequestBox::SetDeviceUserId(const int32_t& userId) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(DEVICE_USERID, userId)); +} + +bool NotificationRequestBox::SetDeviceId(const std::string& deviceId) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(LOCAL_DEVICE_ID, deviceId)); +} + #else bool NotificationRequestBox::GetNotificationHashCode(std::string& hasdCode) const { @@ -378,6 +447,20 @@ bool NotificationRequestBox::GetNotificationUserInput(std::string& userInput) co return box_->GetStringValue(ACTION_USER_INPUT, userInput); } +bool NotificationRequestBox::GetSmallIcon(std::shared_ptr& smallIcon) const +{ + if (box_ == nullptr) { + return false; + } + std::string content; + if (!box_->GetStringValue(BUNDLE_ICON, content)) { + return false; + } + ANS_LOGI("GetBigIcon %{public}zu", content.size()); + smallIcon = AnsImageUtil::UnPackImage(content); + return true; +} + bool NotificationRequestBox::GetBigIcon(std::shared_ptr& bigIcon) const { if (box_ == nullptr) { @@ -387,7 +470,7 @@ bool NotificationRequestBox::GetBigIcon(std::shared_ptr& bigIco if (!box_->GetStringValue(NOTIFICATION_BIG_ICON, bigIconContent)) { return false; } - ANS_LOGI("GetBigIcon %{public}d", (int32_t)(bigIconContent.size())); + ANS_LOGI("GetBigIcon %{public}zu", bigIconContent.size()); bigIcon = AnsImageUtil::UnPackImage(bigIconContent); return true; } @@ -401,7 +484,7 @@ bool NotificationRequestBox::GetOverlayIcon(std::shared_ptr& ov if (!box_->GetStringValue(NOTIFICATION_OVERLAY_ICON, overlayContent)) { return false; } - ANS_LOGI("GetOverlayIcon %{public}d", (int32_t)(overlayContent.size())); + ANS_LOGI("GetOverlayIcon %{public}zu", overlayContent.size()); overlayIcon = AnsImageUtil::UnPackImage(overlayContent); return true; } @@ -437,6 +520,55 @@ bool NotificationRequestBox::GetAppMessageId(std::string& appMessageId) const } return box_->GetStringValue(NOTIFICATION_APP_MESSAGE_ID, appMessageId); } + +bool NotificationRequestBox::GetAppName(std::string& appName) const +{ + if (box_ == nullptr) { + return false; + } + return box_->GetStringValue(APP_NAME, appName); +} + +bool NotificationRequestBox::GetAppLabel(std::string& appLabel) const +{ + if (box_ == nullptr) { + return false; + } + return box_->GetStringValue(APP_LABEL, appLabel); +} + +bool NotificationRequestBox::GetAppIndex(int32_t& appIndex) const +{ + if (box_ == nullptr) { + return false; + } + return box_->GetInt32Value(APP_INDEX, appIndex); +} + +bool NotificationRequestBox::GetNotificationUserId(int32_t& userId) const +{ + if (box_ == nullptr) { + return false; + } + return box_->GetInt32Value(NOTIFICATION_USERID, userId); +} + +bool NotificationRequestBox::GetDeviceUserId(int32_t& userId) const +{ + if (box_ == nullptr) { + return false; + } + return box_->GetInt32Value(DEVICE_USERID, userId); +} + +bool NotificationRequestBox::GetDeviceId(std::string& deviceId) const +{ + if (box_ == nullptr) { + return false; + } + return box_->GetStringValue(LOCAL_DEVICE_ID, deviceId); +} #endif } } + diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 303d5c4c40b5c5e089790ef1f8ec5c6fefca8337..8a09f6caad5b96f3ef5e77b9ffadfd0f9dd6bbdf 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -442,7 +442,6 @@ 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", @@ -537,7 +536,6 @@ 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",