From ae89d3ff0ec8295f7b21ff8a90390f1c7ff9dbef Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Fri, 5 Sep 2025 11:09:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9D=80=E6=AD=BBfoundation?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=EF=BC=8C=E4=BB=BB=E7=84=B6=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=8D=8F=E5=90=8C=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- interfaces/inner_api/notification_constant.h | 27 ++-- .../ans/src/distributed_device_status.cpp | 15 ++- ...tification_distributed_manager_service.cpp | 3 +- ...liveview_all_scenarios_extension_wrapper.h | 4 +- .../soft_bus/distributed_device_service.h | 1 + .../include/soft_bus/distributed_service.h | 1 + ...veview_all_scenarios_extension_wrapper.cpp | 8 +- .../soft_bus/distributed_device_service.cpp | 13 ++ .../src/soft_bus/distributed_service.cpp | 118 +++++++++++------- 9 files changed, 121 insertions(+), 69 deletions(-) diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 4734ac399..501d91b4a 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -233,7 +233,7 @@ public: * Indicates that a notification is deleted because the application cancels all notifications. */ static const int32_t APP_CANCEL_ALL_REASON_DELETE = 9; - + /** * Indicates that a notification is deleted because this user is removed. */ @@ -273,7 +273,7 @@ public: * Indicates that a notification is deleted because the application cancel it by group. */ static const int32_t APP_CANCEL_GROPU_REASON_DELETE = 17; - + /** * Indicates that a notification is deleted by group because the system cancel it. */ @@ -303,7 +303,7 @@ public: * Indicates that notification is deleted because ten-minutes timer cancel it. */ static const int32_t TRIGGER_TEN_MINUTES_REASON_DELETE = 23; - + /** * Indicates that notification is deleted because fifteen-minutes timer cancel it. */ @@ -358,7 +358,7 @@ public: * Indicates that a notification is deleted because collaboration click. */ static const int32_t DISTRIBUTED_COLLABORATIVE_CLICK_DELETE = 34; - + /** * Indicates that a notification is deleted because distributed enable close removed. */ @@ -382,15 +382,15 @@ public: static const int64_t HOUR_TO_MS = 3600000; static const int64_t SECOND_TO_MS = 1000; - + static const int64_t TEN_MINUTES = 600000; - + static const int64_t FIFTEEN_MINUTES = 900000; - + static const int64_t THIRTY_MINUTES = 1800000; - + static const int64_t FINISH_PER = 100; - + static const int64_t DEFAULT_FINISH_STATUS = -1; static const int64_t MAX_FINISH_TIME = 8 * HOUR_TO_MS; @@ -409,13 +409,13 @@ public: static constexpr int32_t ANS_UID = 5523; static const int32_t MAX_BTN_NUM = 3; - + static const int32_t DISTRIBUTE_JUMP_INVALID = -1; - + static const int32_t DISTRIBUTE_JUMP_BY_NTF = 0; - + static const int32_t DISTRIBUTE_JUMP_BY_BTN = 1; - + static const int32_t DISTRIBUTE_JUMP_BY_LIVE_VIEW = 32; // live view max size is 512KB(extra size) + 8KB(base size) = 520KB @@ -436,6 +436,7 @@ public: constexpr static const char* WEARABLE_DEVICE_TYPE = "wearable"; constexpr static const char* PAD_DEVICE_TYPE = "tablet"; constexpr static const char* PC_DEVICE_TYPE = "2in1"; + constexpr static const char* SLAVE_DEVICE_TYPE = "slave"; constexpr static const char* DEVICESTYPES[] = {"headset", "liteWearable", "wearable", "2in1", "tablet"}; constexpr static const char* ANS_VOIP = "ANS_VOIP"; constexpr static const char* PC_PAD_VOIP_FLAG = "110101"; diff --git a/services/ans/src/distributed_device_status.cpp b/services/ans/src/distributed_device_status.cpp index 6f5f3ff75..6b65acdc6 100644 --- a/services/ans/src/distributed_device_status.cpp +++ b/services/ans/src/distributed_device_status.cpp @@ -112,11 +112,18 @@ ErrCode DistributedDeviceStatus::SetDeviceStatus(const std::string &deviceType, bool allConnect = ((1 << NETWORKID_FLAG) & controlFlag); #ifdef ALL_SCENARIO_COLLABORATION if (allConnect) { + if (deviceType == NotificationConstant::SLAVE_DEVICE_TYPE) { + DeviceStatueChangeInfo changeInfo; + changeInfo.deviceId = deviceId; + changeInfo.changeType = DeviceStatueChangeType::DEVICE_USING_CLOSE; + DistributedExtensionService::GetInstance().DeviceStatusChange(changeInfo); + ANS_LOGI("notify %{public}s network change.", StringAnonymous(deviceId).c_str()); + return ERR_OK; + } std::string udid; - int32_t result = DistributedExtensionService::GetInstance().TransDeviceIdToUdid(deviceId, udid); - if (result != ERR_OK) { - ANS_LOGI("Get udid failed %{public}s %{public}s %{public}d ", deviceType.c_str(), - StringAnonymous(deviceStatusId).c_str(), result); + if (DistributedExtensionService::GetInstance().TransDeviceIdToUdid(deviceId, udid) != ERR_OK) { + ANS_LOGI("Get udid failed %{public}s %{public}s", deviceType.c_str(), + StringAnonymous(deviceStatusId).c_str()); return ERR_ANS_TASK_ERR; } deviceStatusId = udid; 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 879442900..1c354f8ef 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 @@ -475,7 +475,8 @@ ErrCode AdvancedNotificationService::SetTargetDeviceStatus(const std::string &de return ERR_ANS_PERMISSION_DENIED; } - if (deviceType == NotificationConstant::PAD_DEVICE_TYPE || deviceType == NotificationConstant::PC_DEVICE_TYPE) { + if (deviceType == NotificationConstant::PAD_DEVICE_TYPE || deviceType == NotificationConstant::PC_DEVICE_TYPE || + deviceType == NotificationConstant::SLAVE_DEVICE_TYPE) { return DelayedSingleton::GetInstance()->SetDeviceStatus(deviceType, status, controlFlag, deviceId, userId); } 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 e5528cb23..a507bef9d 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 @@ -36,7 +36,7 @@ public: std::vector &buffer, const std::string& deviceType); typedef ErrCode (*TRIGGER_PUSH_WANT_AGENT)(const sptr &request, int32_t actionType, const AAFwk::WantParams extraInfo); - typedef ErrCode (*SUBSCRIBE_ALL_CONNECT)(); + typedef ErrCode (*SUBSCRIBE_ALL_CONNECT)(bool isPadOrPc); typedef ErrCode (*UNSUBSCRIBE_ALL_CONNECT)(); typedef ErrCode (*DISTRIBUTED_LIVE_VIEW_OPERATION)( sptr &request, const int32_t operationType, const int32_t btnIndex); @@ -51,7 +51,7 @@ public: const std::string& deviceType); ErrCode TriggerPushWantAgent(const sptr &request, int32_t actionType, const AAFwk::WantParams extraInfo); - ErrCode SubscribeAllConnect(); + ErrCode SubscribeAllConnect(bool isPadOrPc); ErrCode UnSubscribeAllConnect(); ErrCode DistributedLiveViewOperation( sptr &request, const int32_t operationType, const int32_t btnIndex); diff --git a/services/distributed/include/soft_bus/distributed_device_service.h b/services/distributed/include/soft_bus/distributed_device_service.h index a01f4329a..103537b18 100644 --- a/services/distributed/include/soft_bus/distributed_device_service.h +++ b/services/distributed/include/soft_bus/distributed_device_service.h @@ -64,6 +64,7 @@ public: void SetDeviceStatus(const std::shared_ptr& boxMessage); #else void InitCurrentDeviceStatus(); + bool GetDeviceInfoByNetworkId(const std::string& id, DistributedDeviceInfo& device); void SyncDeviceStatus(int32_t type, int32_t status, bool notificationEnable, bool liveViewEnable); #endif diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index 19b12f9ac..58397f2b6 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -66,6 +66,7 @@ public: private: void OnHandleMsg(std::shared_ptr& box); void ConnectPeerDevice(DistributedDeviceInfo device); + void HandleStatusChange(const DeviceStatueChangeInfo& changeInfo); void HandleMatchSync(const std::shared_ptr& boxMessage); bool OnConsumedSetFlags(const std::shared_ptr &request, const DistributedDeviceInfo& peerDevice); 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 234c61f66..1a5ae7b05 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 @@ -103,7 +103,7 @@ void DistributedLiveviewAllScenariosExtensionWrapper::InitDistributedCollaborate ANS_LOGE("update liveview Bin File 2 PiexlMap failed, error: %{public}s", dlerror()); return; } - + updateLiveviewPiexlMap2BinFile_ = (UPDATE_LIVE_VIEW_PIEXL_MAP_2_BIN_FILE)dlsym(ExtensionHandle_, "UpdateLiveviewPiexlMap2BinFile"); if (updateLiveviewPiexlMap2BinFile_ == nullptr) { @@ -161,13 +161,13 @@ ErrCode DistributedLiveviewAllScenariosExtensionWrapper::TriggerPushWantAgent( return triggerHandler_(request, actionType, extraInfo); } -ErrCode DistributedLiveviewAllScenariosExtensionWrapper::SubscribeAllConnect() +ErrCode DistributedLiveviewAllScenariosExtensionWrapper::SubscribeAllConnect(bool isPadOrPc) { if (subscribeHandler_ == nullptr) { ANS_LOGE("Subscribe all connect wrapper symbol failed"); return 0; } - return subscribeHandler_(); + return subscribeHandler_(isPadOrPc); } ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UnSubscribeAllConnect() @@ -217,7 +217,7 @@ ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewBinFile2P } return updateLiveviewBinFile2PiexlMap_(pixelMap, buffer); } - + ErrCode DistributedLiveviewAllScenariosExtensionWrapper::UpdateLiveviewPiexlMap2BinFile( const std::shared_ptr pixelMap, std::vector &buffer) { diff --git a/services/distributed/src/soft_bus/distributed_device_service.cpp b/services/distributed/src/soft_bus/distributed_device_service.cpp index 16fed316d..15577f109 100644 --- a/services/distributed/src/soft_bus/distributed_device_service.cpp +++ b/services/distributed/src/soft_bus/distributed_device_service.cpp @@ -383,6 +383,19 @@ void DistributedDeviceService::SetDeviceStatus(const std::shared_ptr& bo } } #else +bool DistributedDeviceService::GetDeviceInfoByNetworkId(const std::string& id, DistributedDeviceInfo& device) +{ + std::lock_guard lock(mapLock_); + for (auto deviceItem : peerDevice_) { + if (id == deviceItem.second.networkId_) { + device = deviceItem.second; + return true; + } + } + ANS_LOGI("Dans get deviceId unknonw %{public}s.", StringAnonymous(id).c_str()); + return false; +} + void DistributedDeviceService::InitCurrentDeviceStatus() { bool notificationEnable = false; diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index fd654a8e3..0de241a84 100644 --- a/services/distributed/src/soft_bus/distributed_service.cpp +++ b/services/distributed/src/soft_bus/distributed_service.cpp @@ -178,54 +178,84 @@ void DistributedService::ReleaseDevice(const std::string &deviceId, uint16_t dev serviceQueue_->submit(subscribeTask); } -void DistributedService::DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo) +#ifdef DISTRIBUTED_FEATURE_MASTER +void DistributedService::HandleStatusChange(const DeviceStatueChangeInfo& changeInfo) { - if (serviceQueue_ == nullptr) { - ANS_LOGE("Check handler is null."); - return; + if (changeInfo.changeType == DeviceStatueChangeType::DEVICE_USING_ONLINE) { + HandleDeviceUsingChange(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_ONLINE) { - HandleDeviceUsingChange(changeInfo); + + if (changeInfo.changeType == DeviceStatueChangeType::ALL_CONNECT_STATUS_CHANGE) { + if (DistributedDeviceService::GetInstance().CheckNeedSubscribeAllConnect()) { + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(false); + DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); } + } - if (changeInfo.changeType == DeviceStatueChangeType::ALL_CONNECT_STATUS_CHANGE) { - if (DistributedDeviceService::GetInstance().CheckNeedSubscribeAllConnect()) { - DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(); - DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); - } + if (changeInfo.changeType == DeviceStatueChangeType::DEVICE_USING_CLOSE) { + DistributedDeviceInfo device; + if (!DistributedDeviceService::GetInstance().GetDeviceInfoByUdid(changeInfo.deviceId, device)) { + ANS_LOGW("get deviceId err"); + return; + } + DistributedSubscribeService::GetInstance().UnSubscribeNotification(device.deviceId_, + device.deviceType_, false); + std::string deviceType = DistributedDeviceService::DeviceTypeToTypeString(device.deviceType_); + if (!deviceType.empty()) { + auto ret = NotificationHelper::SetTargetDeviceBundleList(deviceType, device.udid_, + BundleListOperationType::RELEASE_BUNDLES, std::vector(), std::vector()); + ANS_LOGI("Remove bundle %{public}s %{public}s %{public}d.", deviceType.c_str(), + StringAnonymous(device.deviceId_).c_str(), ret); } - if (changeInfo.changeType == DeviceStatueChangeType::DEVICE_USING_CLOSE) { - DistributedDeviceInfo device; - if (!DistributedDeviceService::GetInstance().GetDeviceInfoByUdid(changeInfo.deviceId, device)) { - ANS_LOGW("get deviceId err"); - return; - } - DistributedPublishService::GetInstance().RemoveAllDistributedNotifications(device); - DistributedSubscribeService::GetInstance().UnSubscribeNotification(device.deviceId_, - device.deviceType_, false); - std::string deviceType = DistributedDeviceService::DeviceTypeToTypeString(device.deviceType_); - if (!deviceType.empty()) { - auto ret = NotificationHelper::SetTargetDeviceBundleList(deviceType, device.udid_, - BundleListOperationType::RELEASE_BUNDLES, std::vector(), std::vector()); - ANS_LOGI("Remove bundle %{public}s %{public}s %{public}d.", deviceType.c_str(), - StringAnonymous(device.deviceId_).c_str(), ret); - } + DistributedClient::GetInstance().ReleaseDevice(device.deviceId_, device.deviceType_, false); + DistributedDeviceService::GetInstance().ResetDeviceInfo(device.deviceId_, DeviceState::STATE_OFFLINE); + } +} - DistributedDeviceService::GetInstance().SyncDeviceMatch(device, MatchType::MATCH_OFFLINE); - DistributedClient::GetInstance().ReleaseDevice(device.deviceId_, device.deviceType_, false); - DistributedDeviceService::GetInstance().ResetDeviceInfo(device.deviceId_, DeviceState::STATE_OFFLINE); - } #else - if (changeInfo.changeType == DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE) { - DistributedDeviceService::GetInstance().SyncDeviceStatus(DistributedDeviceService::STATE_TYPE_SWITCH, - false, changeInfo.enableChange, changeInfo.liveViewChange); +void DistributedService::HandleStatusChange(const DeviceStatueChangeInfo& changeInfo) +{ + if (DistributedDeviceService::GetInstance().IsLocalPadOrPC() && + changeInfo.changeType == DeviceStatueChangeType::ALL_CONNECT_STATUS_CHANGE) { + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(true); + DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); + } + + if (changeInfo.changeType == DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE) { + DistributedDeviceService::GetInstance().SyncDeviceStatus(DistributedDeviceService::STATE_TYPE_SWITCH, + false, changeInfo.enableChange, changeInfo.liveViewChange); + } + + if (changeInfo.changeType == DeviceStatueChangeType::DEVICE_USING_CLOSE) { + DistributedDeviceInfo device; + if (!DistributedDeviceService::GetInstance().GetDeviceInfoByNetworkId(changeInfo.deviceId, device)) { + ANS_LOGW("get deviceId err"); + return; } + std::vector hashcodes; + DistributedSubscribeService::GetInstance().UnSubscribeNotification(device.deviceId_, + device.deviceType_, false); + NotificationHelper::RemoveDistributedNotifications(hashcodes, + NotificationConstant::SlotType::SOCIAL_COMMUNICATION, + NotificationConstant::DistributedDeleteType::DEVICE_ID, + NotificationConstant::DISTRIBUTED_RELEASE_DELETE, device.udid_); + DistributedClient::GetInstance().ReleaseDevice(device.deviceId_, device.deviceType_, false); + DistributedDeviceService::GetInstance().ResetDeviceInfo(device.deviceId_, DeviceState::STATE_OFFLINE); + } +} #endif + +void DistributedService::DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo) +{ + if (serviceQueue_ == nullptr) { + ANS_LOGE("Check handler is null."); + return; + } + std::function task = std::bind([&, changeInfo]() { + ANS_LOGI("Device change %{public}d %{public}d %{public}d", changeInfo.changeType, + changeInfo.enableChange, changeInfo.liveViewChange); + HandleStatusChange(changeInfo); }); serviceQueue_->submit(task); } @@ -341,7 +371,7 @@ void DistributedService::HandleDeviceUsingChange(const DeviceStatueChangeInfo& c DistributedDeviceService::GetInstance().SetDeviceSyncData(device.deviceId_, DistributedDeviceService::DEVICE_USAGE, true); if (!DistributedDeviceService::GetInstance().IsSubscribeAllConnect()) { - DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(); + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(false); DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); } // sync to peer device @@ -456,14 +486,12 @@ void DistributedService::HandleMatchSync(const std::shared_ptr& boxMessa DistributedDeviceService::GetInstance().InitCurrentDeviceStatus(); DistributedBundleService::GetInstance().SyncInstalledBundles(device, true); DistributedDeviceService::GetInstance().SyncDeviceMatch(device, MatchType::MATCH_ACK); + if (!DistributedDeviceService::GetInstance().IsSubscribeAllConnect()) { + DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->SubscribeAllConnect(true); + DistributedDeviceService::GetInstance().SetSubscribeAllConnect(true); + } return; } - if (matchType == MatchType::MATCH_OFFLINE) { - DistributedSubscribeService::GetInstance().UnSubscribeNotification(device.deviceId_, - device.deviceType_, false); - DistributedClient::GetInstance().ReleaseDevice(device.deviceId_, device.deviceType_, false); - DistributedDeviceService::GetInstance().ResetDeviceInfo(device.deviceId_, DeviceState::STATE_OFFLINE); - } } if (matchType == MatchType::MATCH_SYN) { -- Gitee