diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index 4aad26fc33ef2f811a8d5739df93f2a0c7a49c8e..0b3437b65236156b0af3110af0671e1276a019b2 100644 --- a/frameworks/ans/IAnsManager.idl +++ b/frameworks/ans/IAnsManager.idl @@ -273,7 +273,7 @@ interface OHOS.Notification.IAnsManager { void SetTargetDeviceStatus([in] String deviceType, [in] unsigned int status, [in] String deveiceId); - void SetTargetDeviceStatus([in] String deviceType, [in] unsigned int status, [in] unsigned int controlFlag, [in] String deveiceId); + void SetTargetDeviceStatus([in] String deviceType, [in] unsigned int status, [in] unsigned int controlFlag, [in] String deveiceId, [in] int userId); void GetDoNotDisturbProfile([in] long id, [out] sptr profile); @@ -292,9 +292,13 @@ interface OHOS.Notification.IAnsManager { void GetNotificationRequestByHashCode( [in] String hashCode, [out] null_sptr notificationRequest); + void SetTargetDeviceBundleList([in] String deviceType, [in] String deviceId, [in] int operatorType, [in] String[] bundleList); + + void SetTargetDeviceSwitch([in] String deviceType, [in] String deviceId, [in] boolean notificaitonEnable, [in] boolean liveViewEnable); + void SetHashCodeRule([in] unsigned int type); [macrodef NOTIFICATION_SMART_REMINDER_SUPPORTED] void RegisterSwingCallback([in] IRemoteObject swingCallback); void GetOverlayIconScaleSize([out] unsigned int scaleSize); -} \ No newline at end of file +} diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 4077b57ce7b96df126f1f9beee9ea9bbbfedf8d3..b687d449a018a6ec4ddc2d7ddd091a4d24dbfaf1 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -629,10 +629,24 @@ ErrCode NotificationHelper::SetTargetDeviceStatus(const std::string &deviceType, } ErrCode NotificationHelper::SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status, - const uint32_t controlFlag, const std::string deveiceId) + const uint32_t controlFlag, const std::string deveiceId, int32_t userId) { return DelayedSingleton::GetInstance()->SetTargetDeviceStatus(deviceType, status, controlFlag, - deveiceId); + deveiceId, userId); +} + +ErrCode NotificationHelper::SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList) +{ + return DelayedSingleton::GetInstance()->SetTargetDeviceBundleList(deviceType, deviceId, + operatorType, bundleList); +} + +ErrCode NotificationHelper::SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable) +{ + return DelayedSingleton::GetInstance()->SetTargetDeviceSwitch(deviceType, deviceId, + notificaitonEnable, liveViewEnable); } ErrCode NotificationHelper::RegisterSwingCallback(const std::function swingCbFunc) diff --git a/frameworks/core/common/include/distributed_data_define.h b/frameworks/core/common/include/distributed_data_define.h index bb305431bff6a02b1516fb32e1b70f944b2a7be2..d03734511e9983d9e414a92ca186a620c233fb9d 100644 --- a/frameworks/core/common/include/distributed_data_define.h +++ b/frameworks/core/common/include/distributed_data_define.h @@ -31,6 +31,25 @@ constexpr char const AnonymousString[] = "******"; constexpr int32_t DEFAULT_REPLY_TIMEOUT = 3; } +enum BunleListOperationType { + ADD_BUNDLES = 0, // add bundles + REMOVE_BUNDLES, // remove bundle + RELEASE_BUNDLES // release bundles +}; + +enum DeviceStatueChangeType { + DEVICE_USING_CHANGE = 0, + NOTIFICATION_ENABLE_CHANGE = 1, + ALL_CONNECT_STATUS_CHANGE = 2, +}; + +struct DeviceStatueChangeInfo { + int32_t changeType; + std::string deviceId; + bool enableChange; + bool liveViewChange; +}; + struct DistributedDeviceConfig { int32_t maxTitleLength; int32_t maxContentLength; diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 5b9060fda73ad180ec047d9533b4dbe9d607732e..2f6a79e9faefacfa38c67181378c22eccd2964ae 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -1191,7 +1191,13 @@ public: * @return Returns set result. */ ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status, const uint32_t controlFlag, - const std::string deveiceId = std::string()); + const std::string deveiceId = std::string(), int32_t userId = 0); + + ErrCode SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList); + + ErrCode SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED /** diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 3b29981986d8492f862f527a5f3d92bbbd8202d7..9c03b1277496b02015c669984f3a052e7d4651cc 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -2118,7 +2118,7 @@ ErrCode AnsNotification::SetTargetDeviceStatus(const std::string &deviceType, co } ErrCode AnsNotification::SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status, - const uint32_t controlFlag, const std::string deveiceId) + const uint32_t controlFlag, const std::string deveiceId, int32_t userId) { ANS_LOGD("enter"); sptr proxy = GetAnsManagerProxy(); @@ -2127,7 +2127,29 @@ ErrCode AnsNotification::SetTargetDeviceStatus(const std::string &deviceType, co return ERR_ANS_SERVICE_NOT_CONNECTED; } - return proxy->SetTargetDeviceStatus(deviceType, status, controlFlag, deveiceId); + return proxy->SetTargetDeviceStatus(deviceType, status, controlFlag, deveiceId, userId); +} + +ErrCode AnsNotification::SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->SetTargetDeviceBundleList(deviceType, deviceId, operatorType, bundleList); +} + +ErrCode AnsNotification::SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->SetTargetDeviceSwitch(deviceType, deviceId, notificaitonEnable, liveViewEnable); } ErrCode AnsNotification::GetTargetDeviceStatus(const std::string &deviceType, int32_t &status) diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index 70d38ff1003ea8f9867911d15fb4fe5a04d73622..4c435cf26543c10429092b72491cfca5b8fb7eed 100644 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -605,7 +605,19 @@ public: } ErrCode SetTargetDeviceStatus(const std::string &deviceType, uint32_t status, - uint32_t controlFlag, const std::string& deveiceId) override + uint32_t controlFlag, const std::string& deveiceId, int32_t userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable) override { return ERR_ANS_INVALID_PARAM; } diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index a33fcc3c89e6330d8fa0720f9b885b478c4dd1b2..e338bab563109cc7d48d8d5410f9815d5adf70de 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -367,6 +367,8 @@ public: constexpr static const char* HEADSET_DEVICE_TYPE = "headset"; constexpr static const char* LITEWEARABLE_DEVICE_TYPE = "liteWearable"; constexpr static const char* WEARABLE_DEVICE_TYPE = "wearable"; + constexpr static const char* PAD_DEVICE_TYPE = "Pad"; + constexpr static const char* PC_DEVICE_TYPE = "Pc"; constexpr static const char* DEVICESTYPES[] = {"headset", "liteWearable", "wearable"}; }; } // namespace Notification diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index f923c81496f3a1f595c7852854a746f1a0905844..3689b9f6f079d906df99f54e8abee1458d9fe817 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -1178,7 +1178,30 @@ public: * @return Returns set result. */ static ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status, - const uint32_t controlFlag, const std::string deveiceId = std::string()); + const uint32_t controlFlag, const std::string deveiceId = std::string(), int32_t userId = 0); + + /** + * @brief set target device of bundle list. + * + * @param deviceType device type. + * @param operatorType operation type. + * @param bundleList device of bundle list. + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList); + + /** + * @brief set target device of bundle list. + * + * @param deviceType device type. + * @param operatorType operation type. + * @param notificaitonEnable notification switch. + * @param liveViewEnable live view switch. + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable); /** * @brief Register Swing Callback Function. diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index e4fd4b1393cbbdb1185d1b3c1ce5e89eee13cd00..a6f8a0a7dd69b7e349ec0c6a75a65560c8c3c915 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -114,6 +114,7 @@ ohos_source_set("ans_service_sources") { "src/liveview_all_scenarios_extension_wrapper.cpp", "src/notification_dialog.cpp", "src/notification_dialog_manager.cpp", + "src/notification_extension/distributed_device_data_service.cpp", "src/notification_extension/distributed_device_manager.cpp", "src/notification_extension/distributed_extension_service.cpp", "src/notification_extension/notification_operation_service.cpp", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index d97970863cca7dc451f7d5e0ddbd5b8cb428fb88..e2b290e446c4a24010220e5e2866eb84067ed848 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1112,7 +1112,13 @@ public: * @return Returns set result. */ ErrCode SetTargetDeviceStatus(const std::string &deviceType, uint32_t status, - uint32_t controlFlag, const std::string &deveiceId) override; + uint32_t controlFlag, const std::string &deveiceId, int32_t userId) override; + + ErrCode SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList) override; + + ErrCode SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable) override; /** * @brief clear notification when aggregate local switch close. diff --git a/services/ans/include/distributed_device_status.h b/services/ans/include/distributed_device_status.h index 9c08f040a625330416cf88a54e5081efa1f7e68b..40e6f36df8c15e33973dade8d127a954a972dc56 100644 --- a/services/ans/include/distributed_device_status.h +++ b/services/ans/include/distributed_device_status.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "errors.h" #include "ans_log_wrapper.h" @@ -26,19 +27,32 @@ namespace OHOS { namespace Notification { + +struct DeviceStatus { + DeviceStatus(std::string type, std::string id) : deviceType(type), deviceId(id) {} + std::string deviceType; + std::string deviceId; + uint32_t status = 0; + int32_t userId = 0; +}; + class DistributedDeviceStatus : public DelayedSingleton { public: DistributedDeviceStatus(); ~DistributedDeviceStatus(); ErrCode SetDeviceStatus(const std::string &deviceType, const uint32_t status, const uint32_t controlFlag); + ErrCode SetDeviceStatus(const std::string &deviceType, const uint32_t status, + const uint32_t controlFlag, const std::string deveiceId, int32_t userId); uint32_t GetDeviceStatus(const std::string &deviceType); private: std::mutex mapLock_; + std::vector deviceInfo_; SafeMap deviceStatus_; public: + static constexpr int32_t USERID_FLAG = 16; 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_device_data_service.h b/services/ans/include/notification_extension/distributed_device_data_service.h new file mode 100644 index 0000000000000000000000000000000000000000..1fec4385bb43b6d23f542f4b78d9d3154c823542 --- /dev/null +++ b/services/ans/include/notification_extension/distributed_device_data_service.h @@ -0,0 +1,58 @@ +/* + * 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 NOTIFICATION_DISTRIBUTED_EXTENSION_DISTRIBUTED_DEVICE_DATA_SERVICE_H +#define NOTIFICATION_DISTRIBUTED_EXTENSION_DISTRIBUTED_DEVICE_DATA_SERVICE_H + +#include +#include +#include +#include + +namespace OHOS { +namespace Notification { + +struct DeviceData { + std::string deviceId; + std::string deviceType; + bool notificationSyncEnable = true; + bool liveViewSyncEnable = true; + std::unordered_set installedBundles; +}; + +class DistributedDeviceDataService { +public: + static DistributedDeviceDataService& GetInstance(); + + void ResetTargetDevice(const std::string& deviceType, const std::string& deviceId); + int32_t SetDeviceSyncSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificationEnable, bool liveViewEnable); + int32_t SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList); + bool CheckDeviceBundleExist(const std::string& deviceType, const std::string& deviceId, + const std::string bundleName); + bool GetDeviceNotificationEnable(const std::string& deviceType, const std::string& deviceId); + bool GetDeviceLiveViewEnable(const std::string& deviceType, const std::string& deviceId); + +private: + DistributedDeviceDataService() = default; + ~DistributedDeviceDataService() = default; + + std::mutex lock_; + std::vector devicesData_; +}; +} +} +#endif // NOTIFICATION_DISTRIBUTED_EXTENSION_DISTRIBUTED_DEVICE_DATA_SERVICE_H diff --git a/services/ans/include/notification_extension/distributed_extension_service.h b/services/ans/include/notification_extension/distributed_extension_service.h index c82a5e3a4dcc64d05676babf0f22537947b4f9f1..e6aeaf70ba00ed4cfc667dec6ee35b94948e35d9 100644 --- a/services/ans/include/notification_extension/distributed_extension_service.h +++ b/services/ans/include/notification_extension/distributed_extension_service.h @@ -52,6 +52,7 @@ public: void OnDeviceOnline(const DmDeviceInfo &deviceInfo); void OnDeviceOffline(const DmDeviceInfo &deviceInfo); void OnDeviceChanged(const DmDeviceInfo &deviceInfo); + void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo); static DistributedExtensionService& GetInstance(); void HADotCallback(int32_t code, int32_t ErrCode, uint32_t branchId, std::string reason); void SendReportCallback(int32_t messageType, int32_t errCode, std::string reason); diff --git a/services/ans/src/distributed_device_status.cpp b/services/ans/src/distributed_device_status.cpp index 12c467232b348335fb399eaf9418edb9207825e9..52a93bd7fcf914d529893df244efdf74a9963ecb 100644 --- a/services/ans/src/distributed_device_status.cpp +++ b/services/ans/src/distributed_device_status.cpp @@ -15,6 +15,8 @@ #include "distributed_device_status.h" +#include "distributed_data_define.h" + namespace OHOS { namespace Notification { namespace { @@ -57,6 +59,50 @@ 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) +{ + uint32_t beforeStatus = device.status; + if ((1 << DistributedDeviceStatus::USERID_FLAG) & controlFlag) { + device.userId = userId; + } + for (uint32_t i = 0; i < DistributedDeviceStatus::STATUS_SIZE; i++) { + if (((1 << i) & controlFlag) && ((1 << i) & status)) { + device.status |= (1 << i); + } + if (((1 << i) & controlFlag) && !((1 << i) & status)) { + device.status &= ~(1 << i); + } + } + + 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); +} + +ErrCode DistributedDeviceStatus::SetDeviceStatus(const std::string &deviceType, const uint32_t status, + const uint32_t controlFlag, const std::string deviceId, int32_t userId) +{ + bool existFlag = false; + uint32_t finalStatus = 0; + std::lock_guard lock(mapLock_); + for (auto device = deviceInfo_.begin(); device != deviceInfo_.end(); device++) { + if (device->deviceType != deviceType || device->deviceId != deviceId) { + continue; + } + ChangeStatus(*device, status, controlFlag, userId); + existFlag = true; + break; + } + + if (!existFlag) { + DeviceStatus device = DeviceStatus(deviceType, deviceId); + ChangeStatus(device, status, controlFlag, userId); + deviceInfo_.emplace_back(device); + ANS_LOGI("Add device %{public}s %{public}s", deviceType.c_str(), StringAnonymous(deviceId).c_str()); + } + return ERR_OK; +} + uint32_t DistributedDeviceStatus::GetDeviceStatus(const std::string &deviceType) { std::lock_guard lock(mapLock_); 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 ab3e79d70244fb2375fbb4a8e9329eefbb06e77f..f00cebb96a2183c9f9a0f26548bd6712d33759f3 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 @@ -38,6 +38,7 @@ #include "../advanced_notification_inline.cpp" #include "notification_analytics_util.h" #include "notification_operation_service.h" +#include "distributed_device_data_service.h" namespace OHOS { namespace Notification { @@ -417,7 +418,7 @@ ErrCode AdvancedNotificationService::SetTargetDeviceStatus(const std::string &de } ErrCode AdvancedNotificationService::SetTargetDeviceStatus(const std::string &deviceType, uint32_t status, - uint32_t controlFlag, const std::string &deveiceId) + uint32_t controlFlag, const std::string &deveiceId, int32_t userId) { ANS_LOGD("%{public}s", __FUNCTION__); if (deviceType.empty()) { @@ -435,11 +436,45 @@ ErrCode AdvancedNotificationService::SetTargetDeviceStatus(const std::string &de return ERR_ANS_PERMISSION_DENIED; } + if (deviceType == NotificationConstant::PAD_DEVICE_TYPE || deviceType == NotificationConstant::PC_DEVICE_TYPE) { + return DelayedSingleton::GetInstance()->SetDeviceStatus(deviceType, status, + controlFlag, deveiceId, userId); + } + DelayedSingleton::GetInstance()->SetDeviceStatus(deviceType, status, controlFlag); ANS_LOGI("update %{public}s status %{public}u %{public}u", deviceType.c_str(), status, controlFlag); return ERR_OK; } +ErrCode AdvancedNotificationService::SetTargetDeviceBundleList(const std::string& deviceType, + const std::string& deviceId, int operatorType, const std::vector& bundleList) +{ + if (!AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID())) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + ANS_LOGD("AccessTokenHelper::CheckPermission is false."); + return ERR_ANS_PERMISSION_DENIED; + } + return DistributedDeviceDataService::GetInstance().SetTargetDeviceBundleList(deviceType, deviceId, + operatorType, bundleList); +} + +ErrCode AdvancedNotificationService::SetTargetDeviceSwitch(const std::string& deviceType, + const std::string& deviceId, bool notificaitonEnable, bool liveViewEnable) +{ + if (!AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID())) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + ANS_LOGD("AccessTokenHelper::CheckPermission is false."); + return ERR_ANS_PERMISSION_DENIED; + } + return DistributedDeviceDataService::GetInstance().SetDeviceSyncSwitch(deviceType, deviceId, + notificaitonEnable, liveViewEnable); +} ErrCode AdvancedNotificationService::GetAllDistribuedEnabledBundles( const std::string& deviceType, std::vector &bundleOption) diff --git a/services/ans/src/notification_extension/distributed_device_data_service.cpp b/services/ans/src/notification_extension/distributed_device_data_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd82c3b1e887236bfc55b2e55d06e9d92d301ae4 --- /dev/null +++ b/services/ans/src/notification_extension/distributed_device_data_service.cpp @@ -0,0 +1,157 @@ +/* + * 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 "distributed_device_data_service.h" + +#include "ans_log_wrapper.h" +#include "ans_inner_errors.h" +#include "distributed_data_define.h" + +namespace OHOS { +namespace Notification { + +DistributedDeviceDataService& DistributedDeviceDataService::GetInstance() +{ + static DistributedDeviceDataService distributedDeviceDataService; + return distributedDeviceDataService; +} + +void DistributedDeviceDataService::ResetTargetDevice(const std::string& deviceType, const std::string& deviceId) +{ + std::lock_guard lock(lock_); + for (auto itemIter = devicesData_.begin(); itemIter != devicesData_.end(); itemIter++) { + if (itemIter->deviceType == deviceType && itemIter->deviceId == deviceId) { + devicesData_.erase(itemIter); + ANS_LOGI("Reset device %{public}s %{public}s", deviceType.c_str(), StringAnonymous(deviceId).c_str()); + return; + } + } +} + +int32_t DistributedDeviceDataService::SetDeviceSyncSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificationEnable, bool liveViewEnable) +{ + std::lock_guard lock(lock_); + for (auto itemIter = devicesData_.begin(); itemIter != devicesData_.end(); itemIter++) { + 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(), + notificationEnable, liveViewEnable); + return ERR_OK; + } + } + + if (deviceType.empty() || deviceId.empty()) { + ANS_LOGW("Set device failed %{public}s %{public}d %{public}d", StringAnonymous(deviceId).c_str(), + notificationEnable, liveViewEnable); + return ERR_ANS_INVALID_PARAM; + } + DeviceData deviceData; + deviceData.deviceType = deviceType; + deviceData.deviceId = deviceId; + deviceData.liveViewSyncEnable = liveViewEnable; + deviceData.notificationSyncEnable = notificationEnable; + devicesData_.emplace_back(deviceData); + ANS_LOGI("Set device add %{public}s %{public}d %{public}d", StringAnonymous(deviceId).c_str(), + notificationEnable, liveViewEnable); + return ERR_OK; +} + +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; + } + + if (operatorType == BunleListOperationType::ADD_BUNDLES) { + for (auto& bundle : bundleList) { + itemIter->installedBundles.insert(bundle); + } + } + + if (operatorType == BunleListOperationType::REMOVE_BUNDLES) { + for (auto& bundle : bundleList) { + itemIter->installedBundles.erase(bundle); + } + } + + if (operatorType == BunleListOperationType::RELEASE_BUNDLES) { + itemIter->installedBundles.clear(); + } + return ERR_OK; + } + + if (deviceType.empty() || deviceId.empty() || operatorType != BunleListOperationType::ADD_BUNDLES) { + ANS_LOGW("Set device failed %{public}s %{public}d", StringAnonymous(deviceId).c_str(), + operatorType); + return ERR_ANS_INVALID_PARAM; + } + + DeviceData deviceData; + deviceData.deviceType = deviceType; + deviceData.deviceId = deviceId; + for (auto& bundle : bundleList) { + deviceData.installedBundles.insert(bundle); + } + devicesData_.emplace_back(deviceData); + ANS_LOGI("Set device add %{public}s %{public}zu", StringAnonymous(deviceId).c_str(), bundleList.size()); + return ERR_OK; +} + +bool DistributedDeviceDataService::CheckDeviceBundleExist(const std::string& deviceType, const std::string& deviceId, + const std::string bundleName) +{ + std::lock_guard lock(lock_); + for (auto& item : devicesData_) { + if (item.deviceType == deviceType && item.deviceId == deviceId) { + return item.installedBundles.count(bundleName); + } + } + ANS_LOGW("Get bundle failed %{public}s %{public}s", deviceType.c_str(), StringAnonymous(deviceId).c_str()); + return true; +} + +bool DistributedDeviceDataService::GetDeviceNotificationEnable(const std::string& deviceType, + const std::string& deviceId) +{ + std::lock_guard lock(lock_); + for (auto& item : devicesData_) { + if (item.deviceType == deviceType && item.deviceId == deviceId) { + return item.notificationSyncEnable; + } + } + ANS_LOGW("Get notification failed %{public}s %{public}s", deviceType.c_str(), StringAnonymous(deviceId).c_str()); + return false; +} + +bool DistributedDeviceDataService::GetDeviceLiveViewEnable(const std::string& deviceType, const std::string& deviceId) +{ + std::lock_guard lock(lock_); + for (auto& item : devicesData_) { + if (item.deviceType == deviceType && item.deviceId == deviceId) { + return item.liveViewSyncEnable; + } + } + ANS_LOGW("Get live view failed %{public}s %{public}s", deviceType.c_str(), StringAnonymous(deviceId).c_str()); + return false; +} +} +} diff --git a/services/ans/src/notification_extension/distributed_extension_service.cpp b/services/ans/src/notification_extension/distributed_extension_service.cpp index 4e5c957d5c387684957e01995b1f8d3da64d152a..ad226e0664837865c6551ace48a65c5223a2d07e 100644 --- a/services/ans/src/notification_extension/distributed_extension_service.cpp +++ b/services/ans/src/notification_extension/distributed_extension_service.cpp @@ -35,6 +35,7 @@ typedef void (*ADD_DEVICE)(const std::string &deviceId, uint16_t deviceType, typedef void (*RELEASE_DEVICE)(const std::string &deviceId, uint16_t deviceType); typedef void (*REFRESH_DEVICE)(const std::string &deviceId, uint16_t deviceType, const std::string &networkId); +typedef void (*CHANGE_STATUS)(const DeviceStatueChangeInfo& changeInfo); typedef void (*INIT_HA_CALLBACK)( std::function callback); typedef void (*INIT_SENDREPORT_CALLBACK)( @@ -381,6 +382,29 @@ void DistributedExtensionService::OnDeviceChanged(const DmDeviceInfo &deviceInfo distributedQueue_->submit(changeTask); } +void DistributedExtensionService::DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo) +{ + if (distributedQueue_ == nullptr) { + return; + } + std::function changeTask = std::bind([&, changeInfo]() { + if (!dansRunning_.load() || dansHandler_ == nullptr || !dansHandler_->IsValid()) { + ANS_LOGE("Dans state not normal %{public}d", dansRunning_.load()); + return; + } + CHANGE_STATUS handler = (CHANGE_STATUS)dansHandler_->GetProxyFunc("DeviceStatusChange"); + if (handler == nullptr) { + ANS_LOGE("Dans handler is null ptr."); + return; + } + handler(changeInfo); + ANS_LOGI("Dans statuc change %{public}s %{public}d %{public}d %{public}d.", + StringAnonymous(changeInfo.deviceId).c_str(), changeInfo.changeType, changeInfo.enableChange, + changeInfo.liveViewChange); + }); + distributedQueue_->submit(changeTask); +} + int32_t DistributedExtensionService::GetOperationReplyTimeout() { return deviceConfig_.operationReplyTimeout * DURATION_ONE_SECOND; diff --git a/services/distributed/include/base/distributed_device_data.h b/services/distributed/include/base/distributed_device_data.h index e5d5a1514fff38dc774ba466a4070852a7b27a21..17182796853bb0c0b6cc5c7b7fd9e0153eaae0fa 100644 --- a/services/distributed/include/base/distributed_device_data.h +++ b/services/distributed/include/base/distributed_device_data.h @@ -46,13 +46,16 @@ struct DistributedDeviceInfo { : deviceType_(deviceType), deviceId_(deviceId) {} DistributedDeviceInfo(uint16_t deviceType, std::string deviceId, std::string networkId) : deviceType_(deviceType), deviceId_(deviceId), networkId_(networkId) {} + bool deviceUsage = false; + bool liveViewSync = false; + bool iconSync = false; + bool installedBunlesSync = false; uint16_t deviceType_; - std::string deviceId_; - std::string networkId_; int32_t peerState_ = DeviceState::STATE_INIT; int32_t socketId_ = -1; int32_t connectedTry_ = 0; - bool isSync = false; + std::string deviceId_; + std::string networkId_; }; struct ConnectedSocketInfo { diff --git a/services/distributed/include/helper/bundle_resource_helper.h b/services/distributed/include/helper/bundle_resource_helper.h index 69d805715b4a73568a9390ffcb0141b424c76708..0b049563b853ad98f5844bb65037319b381e1247 100644 --- a/services/distributed/include/helper/bundle_resource_helper.h +++ b/services/distributed/include/helper/bundle_resource_helper.h @@ -65,6 +65,30 @@ public: ErrCode GetBundleInfo(const std::string &bundleName, AppExecFwk::BundleResourceInfo &bundleResourceInfo, const int32_t appIndex = 0); + /** + * @brief Obtains all installed bundle info. + * + * @param flag Indicates the bundle flag. + * @param bundleInfo Indicates the bundle resource. + * @param userId Indicates the userId. + * @return Returns the invock result. + */ + ErrCode GetAllBundleInfos(int32_t flags, std::vector &bundleInfos, int32_t userId); + + /** + * @brief Obtains all installed bundle info. + * + * @param bundlesName Indicates the bundle name. + * @param userId Indicates the userId. + * @return Returns the invock result. + */ + ErrCode GetAllInstalledBundles(std::vector &bundlesName, int32_t userId); + + ErrCode GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, + AppExecFwk::ApplicationInfo &appInfo); + + bool CheckSystemApp(const std::string& bundleName, int32_t userId); + private: void Connect(); void Disconnect(); diff --git a/services/distributed/include/soft_bus/distributed_bundle_service.h b/services/distributed/include/soft_bus/distributed_bundle_service.h index 867cb2687567317539f3958e3d4921d61b10cc87..db8e91c75e2c7c50f93d4844bb92726b7f2b18b8 100644 --- a/services/distributed/include/soft_bus/distributed_bundle_service.h +++ b/services/distributed/include/soft_bus/distributed_bundle_service.h @@ -34,6 +34,7 @@ public: void GenerateBundleIconSync(const DistributedDeviceInfo& device); void HandleBundleRemoved(const std::string& bundleName); void HandleBundleChanged(const std::string& bundleName, bool updatedExit); + void SetDeviceBundleList(const std::shared_ptr& boxMessage); private: int32_t UpdateBundlesIcon(const std::unordered_map& icons, const DistributedDeviceInfo peerDevice); @@ -42,6 +43,9 @@ private: std::vector& updateDeviceList); #else void ReportBundleIconList(const DistributedDeviceInfo peerDevice); + void SyncInstalledBundles(const DistributedDeviceInfo& peerDevice, bool isForce); + void SendInstalledBundles(const DistributedDeviceInfo& peerDevice, const std::string& localDeviceId, + const std::vector& bundles, int32_t type); #endif private: diff --git a/services/distributed/include/soft_bus/distributed_device_service.h b/services/distributed/include/soft_bus/distributed_device_service.h index dca01cbd7f865120c10d487851ffb276c519f4ae..1a52e937d7c185a8b408ce17cecc665a2264bda1 100644 --- a/services/distributed/include/soft_bus/distributed_device_service.h +++ b/services/distributed/include/soft_bus/distributed_device_service.h @@ -24,14 +24,26 @@ namespace OHOS { namespace Notification { class DistributedDeviceService { public: + static constexpr int32_t STATE_TYPE_BOTH = 3; + static constexpr int32_t STATE_TYPE_SWITCH = 2; + static constexpr int32_t STATE_TYPE_LOCKSCREEN = 1; + static constexpr int32_t SYNC_BUNDLE_ICONS = 1; + static constexpr int32_t SYNC_LIVE_VIEW = 2; + static constexpr int32_t SYNC_INSTALLED_BUNDLE = 3; + static constexpr int32_t DEVICE_USAGE = 4; + static DistributedDeviceService& GetInstance(); + static std::string DeviceTypeToTypeString(uint16_t deviceType); + bool IsReportDataByHa(); void InitLocalDevice(const std::string &deviceId, uint16_t deviceType); DistributedDeviceInfo GetLocalDevice(); - bool IsDeviceSyncData(const std::string& deviceId); + bool IsSyncLiveView(const std::string& deviceId, bool forceSync); + bool IsSyncIcons(const std::string& deviceId, bool forceSync); + bool IsSyncInstalledBundle(const std::string& deviceId, bool forceSync); bool GetDeviceInfo(const std::string& deviceId, DistributedDeviceInfo& device); void SetDeviceState(const std::string& deviceId, int32_t state); - void SetDeviceSyncData(const std::string& deviceId, bool syncData); + void SetDeviceSyncData(const std::string& deviceId, int32_t type, bool syncData); bool CheckDeviceExist(const std::string& deviceId); bool CheckDeviceNeedSync(const std::string& deviceId); void IncreaseDeviceSyncCount(const std::string& deviceId); @@ -43,7 +55,7 @@ public: void SetDeviceStatus(const std::shared_ptr& boxMessage); #else void InitCurrentDeviceStatus(); - void SyncDeviceStatus(int32_t status); + void SyncDeviceStatus(int32_t type, int32_t status, bool notificationEnable, bool liveViewEnable); #endif private: diff --git a/services/distributed/include/soft_bus/distributed_service.h b/services/distributed/include/soft_bus/distributed_service.h index a14e533dad4e2087037cd3e1ee0f6ad2aa910db1..e165673a73a4d9deacb4b35966bf2b77e89769f5 100644 --- a/services/distributed/include/soft_bus/distributed_service.h +++ b/services/distributed/include/soft_bus/distributed_service.h @@ -40,6 +40,7 @@ public: int32_t InitService(const std::string &deviceId, uint16_t deviceType); void AddDevice(DistributedDeviceInfo device); void ReleaseDevice(const std::string &deviceId, uint16_t deviceType); + void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo); void OnConsumed(const std::shared_ptr &request, const DistributedDeviceInfo& device); void OnApplicationInfnChanged(const std::string& bundleName); @@ -53,6 +54,7 @@ public: void HandleBundlesEvent(const std::string& bundleName, const std::string& action); #else void SyncDeviceStatus(int32_t status); + void SyncInstalledBundle(const std::string& bundleName, bool isAdd); #endif std::string GetNotificationKey(const std::shared_ptr& notification); private: diff --git a/services/distributed/include/soft_bus/distributed_subscribe_service.h b/services/distributed/include/soft_bus/distributed_subscribe_service.h index 058111c7d03a74a7df94705dc9c7bacaa4634282..37ab4d4defb10a85691009154ad151741b69a34e 100644 --- a/services/distributed/include/soft_bus/distributed_subscribe_service.h +++ b/services/distributed/include/soft_bus/distributed_subscribe_service.h @@ -24,6 +24,7 @@ namespace Notification { class DistributedSubscribeService { public: static DistributedSubscribeService& GetInstance(); + static int32_t GetCurrentActiveUserId(); void UnSubscribeAllNotification(); void SubscribeNotification(const DistributedDeviceInfo peerDevice); void UnSubscribeNotification(const std::string &deviceId, uint16_t deviceType); diff --git a/services/distributed/include/tlv_box/bundle_icon_box.h b/services/distributed/include/tlv_box/bundle_icon_box.h index 4a1129c79dc11fd975595633625e2305dd4251fe..b7ba5e3c256f5079529b463e2d5ec83fea47039f 100644 --- a/services/distributed/include/tlv_box/bundle_icon_box.h +++ b/services/distributed/include/tlv_box/bundle_icon_box.h @@ -33,8 +33,11 @@ enum IconSyncType { class BundleIconBox : public BoxBase { public: const static int32_t MAX_ICON_NUM = 10; + const static int32_t MAX_BUNDLE_NUM = 30; + BundleIconBox(); BundleIconBox(std::shared_ptr box); + bool SetMessageType(int32_t messageType); bool SetIconSyncType(int32_t type); bool SetDataLength(int32_t length); bool SetBundleList(const std::vector& bundleList); diff --git a/services/distributed/include/tlv_box/state_box.h b/services/distributed/include/tlv_box/state_box.h index 19cdb9ed1a0aa89160ad655f76ff7bc2eaaac957..2b0cf6dc16d445686aa69a556611495fd581890c 100644 --- a/services/distributed/include/tlv_box/state_box.h +++ b/services/distributed/include/tlv_box/state_box.h @@ -30,10 +30,14 @@ public: bool GetDeviceType(std::string& deviceType); bool GetDeviceId(std::string& deviceId); bool GetState(int32_t& state); + bool GetLiveViewEnable(bool& enable); + bool GetNotificationEnable(bool& enable); #else bool SetDeviceType(const std::string& deviceType); bool SetDeviceId(const std::string& deviceId); bool SetState(int32_t state); + bool SetLiveViewEnable(bool enable); + bool SetNotificationEnable(bool enable); #endif }; } // namespace Notification diff --git a/services/distributed/include/tlv_box/tlv_box.h b/services/distributed/include/tlv_box/tlv_box.h index 37a39ce56fc8001cff981dbc4a2fe4f9691744b5..4aace3a5a2f1997cd7cc61fc16a203368b286716 100644 --- a/services/distributed/include/tlv_box/tlv_box.h +++ b/services/distributed/include/tlv_box/tlv_box.h @@ -36,6 +36,7 @@ enum NotificationEventType : int32_t { NOTIFICATION_RESPONSE_SYNC = 9, SYNC_NOTIFICATION = 10, NOTIFICATION_RESPONSE_REPLY_SYNC = 11, + INSTALLED_BUNDLE_SYNC = 12, }; enum TlvType : int32_t { @@ -62,6 +63,8 @@ enum TlvType : int32_t { NOTIFICATION_LONG_TITLE = 22, ALL_LINES_LENGTH = 23, NOTIFICATION_APP_MESSAGE_ID = 24, + LIVEVIEW_SYNC_ENABLE = 987, + NOTIFICATION_SYNC_ENABLE = 988, RESULT_CODE = 989, OPERATION_TYPE = 990, OPERATION_EVENT_ID = 991, diff --git a/services/distributed/src/helper/bundle_resource_helper.cpp b/services/distributed/src/helper/bundle_resource_helper.cpp index a9e4594284004532af5bd87e232d800d722137ea..d9f12f4ae8a585a84b582a5294f0d26805579710 100644 --- a/services/distributed/src/helper/bundle_resource_helper.cpp +++ b/services/distributed/src/helper/bundle_resource_helper.cpp @@ -94,5 +94,83 @@ ErrCode BundleResourceHelper::GetBundleInfo(const std::string &bundleName, IPCSkeleton::SetCallingIdentity(identity); return result; } + +ErrCode BundleResourceHelper::GetAllBundleInfos(int32_t flags, std::vector &bundleInfos, + int32_t userId) +{ + ErrCode result = 0; + std::lock_guard lock(connectionMutex_); + Connect(); + if (bundleMgr_ == nullptr) { + ANS_LOGE("GetBundleInfo bundle proxy failed."); + return -1; + } + + std::string identity = IPCSkeleton::ResetCallingIdentity(); + result = bundleMgr_->GetBundleInfosV9(flags, bundleInfos, userId); + IPCSkeleton::SetCallingIdentity(identity); + return result; +} + +ErrCode BundleResourceHelper::GetAllInstalledBundles(std::vector &bundlesName, int32_t userId) +{ + std::vector bundleInfos; + int32_t flags = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); + ErrCode result = GetAllBundleInfos(flags, bundleInfos, userId); + if (result != ERR_OK) { + ANS_LOGE("Get installed bundle failed %{public}d.", result); + return result; + } + + for (auto& bundle : bundleInfos) { + if (bundle.applicationInfo.bundleType != AppExecFwk::BundleType::APP) { + ANS_LOGD("Get not app %{public}s", bundle.applicationInfo.bundleName.c_str()); + continue; + } + if (!bundle.applicationInfo.isSystemApp) { + ANS_LOGI("Get bundle app %{public}s", bundle.applicationInfo.bundleName.c_str()); + bundlesName.emplace_back(bundle.applicationInfo.bundleName); + } + } + + ANS_LOGI("Get installed bundle size %{public}zu.", bundlesName.size()); + return ERR_OK; +} + +ErrCode BundleResourceHelper::GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, + AppExecFwk::ApplicationInfo &appInfo) +{ + ErrCode result = 0; + std::lock_guard lock(connectionMutex_); + Connect(); + if (bundleMgr_ == nullptr) { + ANS_LOGE("GetBundleInfo bundle proxy failed."); + return -1; + } + + std::string identity = IPCSkeleton::ResetCallingIdentity(); + result = bundleMgr_->GetApplicationInfoV9(appName, flags, userId, appInfo); + IPCSkeleton::SetCallingIdentity(identity); + return result; +} + +bool BundleResourceHelper::CheckSystemApp(const std::string& bundleName, int32_t userId) +{ + AppExecFwk::ApplicationInfo appInfo; + int32_t flags = static_cast(AppExecFwk::GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT); + ErrCode result = GetApplicationInfo(bundleName, flags, userId, appInfo); + if (result != ERR_OK) { + ANS_LOGE("Get installed bundle failed %{public}d.", result); + return false; + } + + if (appInfo.bundleType != AppExecFwk::BundleType::APP) { + ANS_LOGD("Get not app %{public}s %{public}d", bundleName.c_str(), appInfo.bundleType); + return true; + } + + ANS_LOGI("Get installed bundle %{public}s %{public}d.", bundleName.c_str(), appInfo.isSystemApp); + return appInfo.isSystemApp; +} } } diff --git a/services/distributed/src/soft_bus/distributed_bundle_service.cpp b/services/distributed/src/soft_bus/distributed_bundle_service.cpp index 7c47be0630c30ee610b959a362a2267fbc9dd465..b98ce0779bcac4fea08d2ffacd7e07eb9874315b 100644 --- a/services/distributed/src/soft_bus/distributed_bundle_service.cpp +++ b/services/distributed/src/soft_bus/distributed_bundle_service.cpp @@ -24,6 +24,7 @@ #include "bundle_resource_helper.h" #include "distributed_device_service.h" #include "distributed_preference.h" +#include "distributed_subscribe_service.h" namespace OHOS { namespace Notification { @@ -70,12 +71,7 @@ void DistributedBundleService::HandleBundleIconSync(const std::shared_ptr& boxMessage) +{ + int32_t operatorType = 0; + std::string deviceId; + BundleIconBox iconBox = BundleIconBox(boxMessage); + if (!iconBox.GetLocalDeviceId(deviceId)) { + ANS_LOGW("Dans bundle get deviceid failed."); + return; + } + + DistributedDeviceInfo device; + if (!DistributedDeviceService::GetInstance().GetDeviceInfo(deviceId, device)) { + ANS_LOGW("Dans bundle get device info failed %{public}s.", StringAnonymous(deviceId).c_str()); + return; + } + + if (!iconBox.GetIconSyncType(operatorType)) { + ANS_LOGI("Dans handle bundle icon sync failed."); + return; + } + + std::vector bundleList; + if (!iconBox.GetBundleList(bundleList)) { + ANS_LOGI("Dans handle bundle list failed."); + return; + } + + std::string deviceType = DistributedDeviceService::DeviceTypeToTypeString(device.deviceType_); + if (deviceType.empty()) { + ANS_LOGW("Dans handle bundle invalid %{public}s %{public}u.", StringAnonymous(deviceId).c_str(), + device.deviceType_); + return; + } + auto ret = NotificationHelper::SetTargetDeviceBundleList(deviceType, deviceId, operatorType, bundleList); + ANS_LOGI("SetDeviceBundleList %{public}s %{public}s %{public}d %{public}zu %{public}d", deviceType.c_str(), + StringAnonymous(deviceId).c_str(), operatorType, bundleList.size(), ret); +} #else void DistributedBundleService::HandleBundleIconSync(const std::shared_ptr& boxMessage) { @@ -325,6 +361,64 @@ void DistributedBundleService::ReportBundleIconList(const DistributedDeviceInfo ANS_LOGI("Dans ReportBundleIconList %{public}s %{public}d.", StringAnonymous(peerDevice.deviceId_).c_str(), peerDevice.deviceType_); } + +void DistributedBundleService::SyncInstalledBundles(const DistributedDeviceInfo& peerDevice, bool isForce) +{ + auto localDevice = DistributedDeviceService::GetInstance().GetLocalDevice(); + if (localDevice.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD && + 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); + return; + } + + std::vector bundlesName; + int32_t userId = DistributedSubscribeService::GetCurrentActiveUserId(); + int32_t result = DelayedSingleton::GetInstance()->GetAllInstalledBundles( + bundlesName, userId); + if (result != ERR_OK) { + ANS_LOGW("Dans get bundls failed."); + return; + } + + std::vector bundles; + for (auto& bundle : bundlesName) { + bundles.push_back(bundle); + if (bundles.size() >= BundleIconBox::MAX_BUNDLE_NUM) { + SendInstalledBundles(peerDevice, localDevice.deviceId_, bundles, + BunleListOperationType::ADD_BUNDLES); + bundles.clear(); + } + } + + if (!bundles.empty()) { + SendInstalledBundles(peerDevice, localDevice.deviceId_, bundles, BunleListOperationType::ADD_BUNDLES); + } + DistributedDeviceService::GetInstance().SetDeviceSyncData(peerDevice.deviceId_, + DistributedDeviceService::SYNC_INSTALLED_BUNDLE, true); +} + +void DistributedBundleService::SendInstalledBundles(const DistributedDeviceInfo& peerDevice, + const std::string& localDeviceId, const std::vector& bundles, int32_t type) +{ + std::shared_ptr iconBox = std::make_shared(); + iconBox->SetMessageType(INSTALLED_BUNDLE_SYNC); + iconBox->SetLocalDeviceId(localDeviceId); + iconBox->SetIconSyncType(type); + iconBox->SetBundleList(bundles); + + DistributedClient::GetInstance().SendMessage(iconBox, TransDataType::DATA_TYPE_MESSAGE, + peerDevice.deviceId_, MODIFY_ERROR_EVENT_CODE); + ANS_LOGI("Dans send bundle %{public}s %{public}d.", + StringAnonymous(peerDevice.deviceId_).c_str(), peerDevice.deviceType_); +} #endif } diff --git a/services/distributed/src/soft_bus/distributed_device_service.cpp b/services/distributed/src/soft_bus/distributed_device_service.cpp index 47ac0ecbb1657423c68a65472c28c473bdf7c900..c1172d002a81d3649abae40ffbb6716bc7a5896e 100644 --- a/services/distributed/src/soft_bus/distributed_device_service.cpp +++ b/services/distributed/src/soft_bus/distributed_device_service.cpp @@ -35,7 +35,7 @@ DistributedDeviceService& DistributedDeviceService::GetInstance() return distributedDeviceService; } -std::string DeviceTypeToTypeString(uint16_t deviceType) +std::string DistributedDeviceService::DeviceTypeToTypeString(uint16_t deviceType) { switch (deviceType) { case DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH: { @@ -68,24 +68,76 @@ bool DistributedDeviceService::IsReportDataByHa() return localDevice_.deviceType_ != DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH; } -bool DistributedDeviceService::IsDeviceSyncData(const std::string& deviceId) +bool DistributedDeviceService::IsSyncLiveView(const std::string& deviceId, bool forceSync) { auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device is data %{public}s.", StringAnonymous(deviceId).c_str()); - return true; + return false; + } + if (iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD || + iter->second.deviceType_ == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { + if (!iter->second.deviceUsage || iter->second.peerState_ != DeviceState::STATE_SYNC) { + return false; + } + } + + if (!forceSync && iter->second.liveViewSync) { + ANS_LOGI("Dans live view sync %{public}d %{public}d.", forceSync, iter->second.liveViewSync); + return false; + } + return true; +} + +bool DistributedDeviceService::IsSyncIcons(const std::string& deviceId, bool forceSync) +{ + 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 (!forceSync && iter->second.iconSync) { + ANS_LOGI("Dans icon sync %{public}d %{public}d.", forceSync, iter->second.iconSync); + return false; } - return iter->second.isSync; + return true; } -void DistributedDeviceService::SetDeviceSyncData(const std::string& deviceId, bool syncData) +bool DistributedDeviceService::IsSyncInstalledBundle(const std::string& deviceId, bool forceSync) +{ + 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 (!forceSync && iter->second.installedBunlesSync) { + ANS_LOGI("Dans bundle sync %{public}d %{public}d.", forceSync, iter->second.installedBunlesSync); + return false; + } + return true; +} + +void DistributedDeviceService::SetDeviceSyncData(const std::string& deviceId, int32_t type, bool syncData) { auto iter = peerDevice_.find(deviceId); if (iter == peerDevice_.end()) { ANS_LOGE("Dans unknown device set data %{public}s.", StringAnonymous(deviceId).c_str()); return; } - iter->second.isSync = syncData; + if (type == SYNC_BUNDLE_ICONS) { + iter->second.iconSync = syncData; + } + if (type == SYNC_LIVE_VIEW) { + iter->second.liveViewSync = syncData; + } + if (type == SYNC_INSTALLED_BUNDLE) { + iter->second.installedBunlesSync = syncData; + } + if (type == DEVICE_USAGE) { + iter->second.deviceUsage = syncData; + } } void DistributedDeviceService::SetDeviceState(const std::string& deviceId, int32_t state) @@ -190,34 +242,60 @@ int32_t DistributedDeviceService::SyncDeviceMatch(const DistributedDeviceInfo pe #ifdef DISTRIBUTED_FEATURE_MASTER void DistributedDeviceService::SetDeviceStatus(const std::shared_ptr& boxMessage) { - int32_t status; + std::string deviceId; std::string deviceName; NotifticationStateBox stateBox = NotifticationStateBox(boxMessage); - if (!stateBox.GetDeviceType(deviceName) || !stateBox.GetState(status)) { - ANS_LOGW("Dans unbox state failed."); + if (!stateBox.GetDeviceId(deviceId) || !stateBox.GetDeviceType(deviceName)) { + ANS_LOGW("Dans unbox deviceId and name failed."); return; } - std::string deviceId; - if (!stateBox.GetDeviceId(deviceId)) { - ANS_LOGW("Dans unbox deviceId failed."); + + int32_t status; + if (stateBox.GetState(status)) { + int32_t result = NotificationHelper::SetTargetDeviceStatus(deviceName, status, + DEFAULT_LOCK_SCREEN_FLAG, deviceId); + ANS_LOGI("Dans set state %{public}s %{public}s %{public}d %{public}d.", deviceName.c_str(), + StringAnonymous(deviceId).c_str(), status, result); + } + + bool liveViewEnable; + bool notificationEnable; + if (stateBox.GetLiveViewEnable(liveViewEnable) && stateBox.GetNotificationEnable(notificationEnable)) { + int32_t result = NotificationHelper::SetTargetDeviceSwitch(deviceName, deviceId, + notificationEnable, liveViewEnable); + ANS_LOGI("Dans set enable %{public}s %{public}s %{public}d %{public}d %{public}d.", deviceName.c_str(), + StringAnonymous(deviceId).c_str(), liveViewEnable, notificationEnable, result); } - int32_t result = NotificationHelper::SetTargetDeviceStatus(deviceName, status, - DEFAULT_LOCK_SCREEN_FLAG, deviceId); - ANS_LOGI("Dans set state %{public}s %{public}d.", deviceName.c_str(), status); } #else void DistributedDeviceService::InitCurrentDeviceStatus() { + bool notificationEnable = true; + bool liveViewEnable = false; + std::string localType = DeviceTypeToTypeString(localDevice_.deviceType_); int32_t status = OberverService::GetInstance().IsScreenLocked(); - SyncDeviceStatus(status); + auto result = NotificationHelper::IsDistributedEnabledBySlot(NotificationConstant::SlotType::LIVE_VIEW, + localType, liveViewEnable); + if (result != ERR_OK) { + ANS_LOGW("Dans get live view enable failed."); + } + SyncDeviceStatus(STATE_TYPE_BOTH, status, notificationEnable, liveViewEnable); } -void DistributedDeviceService::SyncDeviceStatus(int32_t status) +void DistributedDeviceService::SyncDeviceStatus(int32_t type, int32_t status, + bool notificationEnable, bool liveViewEnable) { std::shared_ptr stateBox = std::make_shared(); - stateBox->SetState(status); stateBox->SetDeviceType(DeviceTypeToTypeString(localDevice_.deviceType_)); stateBox->SetDeviceId(localDevice_.deviceId_); + if (type == STATE_TYPE_LOCKSCREEN || type == STATE_TYPE_BOTH) { + stateBox->SetState(status); + } + if (type == STATE_TYPE_SWITCH || type == STATE_TYPE_BOTH) { + stateBox->SetLiveViewEnable(liveViewEnable); + stateBox->SetNotificationEnable(notificationEnable); + } + if (!stateBox->Serialize()) { ANS_LOGW("Dans SyncDeviceState serialize failed."); return; @@ -232,3 +310,4 @@ void DistributedDeviceService::SyncDeviceStatus(int32_t status) #endif } } + diff --git a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp index 85471cb3ab36c01deb7c526e9f5c1702d8b76bd9..34fa2a94733f7bf701af2e44a9c91e8e87f3698a 100644 --- a/services/distributed/src/soft_bus/distributed_extern_intferface.cpp +++ b/services/distributed/src/soft_bus/distributed_extern_intferface.cpp @@ -48,6 +48,13 @@ SYMBOL_EXPORT void AddDevice(const std::string &deviceId, uint16_t deviceType, DistributedService::GetInstance().AddDevice(peerDevice); } +SYMBOL_EXPORT void DeviceStatusChange(const DeviceStatueChangeInfo& changeInfo) +{ + ANS_LOGI("Device StatusChange %{public}s %{public}d.", StringAnonymous(changeInfo.deviceId).c_str(), + changeInfo.changeType); + DistributedService::GetInstance().DeviceStatusChange(changeInfo); +} + SYMBOL_EXPORT void ReleaseDevice(const std::string &deviceId, uint16_t deviceType) { ANS_LOGI("ReleaseDevice %{public}s %{public}d.", StringAnonymous(deviceId).c_str(), (int32_t)(deviceType)); diff --git a/services/distributed/src/soft_bus/distributed_observer_service.cpp b/services/distributed/src/soft_bus/distributed_observer_service.cpp index 2976ded7719ecb4b8ea2ad2de29ff749b54525b3..79e88b6e8df0178f688fe500182f4a93e8114949 100644 --- a/services/distributed/src/soft_bus/distributed_observer_service.cpp +++ b/services/distributed/src/soft_bus/distributed_observer_service.cpp @@ -57,6 +57,19 @@ void DistributedEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData DistributedService::GetInstance().SyncDeviceStatus(SCREEN_ON); return; } + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || + action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) { + OHOS::AppExecFwk::ElementName ele = want.GetElement(); + std::string bundleName = ele.GetBundleName(); + if (bundleName.empty()) { + ANS_LOGE("Illegal bundle name."); + return; + } + bool isAddBundle = + (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) ? true : false; + DistributedService::GetInstance().SyncInstalledBundle(bundleName, isAddBundle); + return; + } #endif } @@ -74,6 +87,11 @@ void OberverService::Init(uint16_t deviceType) matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); #else + if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD || + deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_PC) { + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); + } matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED); #endif 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 10a2db6aaea372c278b717009c22e775df8b996e..ad75c80b43979570a8be858b73c3ec4f45628399 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp @@ -148,12 +148,7 @@ void DistributedPublishService::OnRemoveNotifications(const DistributedDeviceInf #ifdef DISTRIBUTED_FEATURE_MASTER void DistributedPublishService::SyncLiveViewNotification(const DistributedDeviceInfo peerDevice, bool isForce) { - if (!DistributedDeviceService::GetInstance().CheckDeviceExist(peerDevice.deviceId_)) { - return; - } - bool sync = DistributedDeviceService::GetInstance().IsDeviceSyncData(peerDevice.deviceId_); - if (!isForce && sync) { - ANS_LOGI("Dans %{public}d %{public}d.", isForce, sync); + if (!DistributedDeviceService::GetInstance().IsSyncLiveView(peerDevice.deviceId_, isForce)) { return; } @@ -185,6 +180,8 @@ void DistributedPublishService::SyncLiveViewNotification(const DistributedDevice std::shared_ptr sharedNotification = std::make_shared(*notification); SendNotifictionRequest(sharedNotification, peerDevice, true); } + DistributedDeviceService::GetInstance().SetDeviceSyncData(peerDevice.deviceId_, + DistributedDeviceService::SYNC_LIVE_VIEW, true); } void DistributedPublishService::SyncNotifictionList(const DistributedDeviceInfo& peerDevice, diff --git a/services/distributed/src/soft_bus/distributed_service.cpp b/services/distributed/src/soft_bus/distributed_service.cpp index dbab00a712ff4f656e4f0252a9614bf76af1b2c3..f0d99273291cea67b6f9a580b23553fa5855fb84 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 "bundle_resource_helper.h" namespace OHOS { namespace Notification { @@ -151,6 +152,37 @@ void DistributedService::ReleaseDevice(const std::string &deviceId, uint16_t dev serviceQueue_->submit(subscribeTask); } +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); +#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); + } + } + + if (changeInfo.changeType == DeviceStatueChangeType::ALL_CONNECT_STATUS_CHANGE) { + } +#else + if (changeInfo.changeType == DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE) { + DistributedDeviceService::GetInstance().SyncDeviceStatus(DistributedDeviceService::STATE_TYPE_SWITCH, + false, changeInfo.enableChange, changeInfo.liveViewChange); + } +#endif + }); + serviceQueue_->submit(task); +} + void DistributedService::OnCanceled(const std::shared_ptr& notification, const DistributedDeviceInfo& peerDevice) { @@ -271,7 +303,39 @@ void DistributedService::SyncDeviceStatus(int32_t status) } status = (static_cast(status) << 1); std::function task = std::bind([&, status]() { - DistributedDeviceService::GetInstance().SyncDeviceStatus(status); + DistributedDeviceService::GetInstance().SyncDeviceStatus(DistributedDeviceService::STATE_TYPE_LOCKSCREEN, + status, false, false); + }); + serviceQueue_->submit(task); +} + +void DistributedService::SyncInstalledBundle(const std::string& bundleName, bool isAdd) +{ + if (serviceQueue_ == nullptr) { + ANS_LOGE("Check handler is null."); + return; + } + std::function task = std::bind([&, bundleName, isAdd]() { + std::vector bundles = { bundleName }; + auto localDevice = DistributedDeviceService::GetInstance().GetLocalDevice(); + auto peerDevices = DistributedDeviceService::GetInstance().GetDeviceList(); + if (!isAdd) { + for (auto& device : peerDevices) { + DistributedBundleService::GetInstance().SendInstalledBundles(device.second, localDevice.deviceId_, + bundles, BunleListOperationType::REMOVE_BUNDLES); + } + ANS_LOGI("Sync bundle remove %{public}s %{public}zu.", bundleName.c_str(), peerDevices.size()); + return; + } + + int32_t userId = DistributedSubscribeService::GetCurrentActiveUserId(); + if (!DelayedSingleton::GetInstance()->CheckSystemApp(bundleName, userId)) { + for (auto device : peerDevices) { + DistributedBundleService::GetInstance().SendInstalledBundles(device.second, localDevice.deviceId_, + bundles, BunleListOperationType::ADD_BUNDLES); + } + ANS_LOGI("Sync bundle add %{public}s %{public}zu.", bundleName.c_str(), peerDevices.size()); + } }); serviceQueue_->submit(task); } @@ -313,13 +377,14 @@ void DistributedService::HandleMatchSync(const std::shared_ptr& boxMessa DistributedSubscribeService::GetInstance().SubscribeNotification(peerDevice); DistributedPublishService::GetInstance().SyncLiveViewNotification(peerDevice, false); } - DistributedDeviceService::GetInstance().SetDeviceSyncData(peerDevice.deviceId_, true); #else if (matchType == MatchType::MATCH_SYN) { DistributedDeviceService::GetInstance().SyncDeviceMatch(peerDevice, MatchType::MATCH_ACK); + DistributedBundleService::GetInstance().SyncInstalledBundles(peerDevice, true); } else if (matchType == MatchType::MATCH_ACK) { DistributedDeviceService::GetInstance().InitCurrentDeviceStatus(); DistributedSubscribeService::GetInstance().SubscribeNotification(peerDevice); + DistributedBundleService::GetInstance().SyncInstalledBundles(peerDevice, false); } #endif } @@ -358,6 +423,9 @@ void DistributedService::OnHandleMsg(std::shared_ptr& box) case NotificationEventType::NOTIFICATION_STATE_SYNC: DistributedDeviceService::GetInstance().SetDeviceStatus(box); break; + case NotificationEventType::INSTALLED_BUNDLE_SYNC: + DistributedBundleService::GetInstance().SetDeviceBundleList(box); + break; #else case NotificationEventType::PUBLISH_NOTIFICATION: DistributedPublishService::GetInstance().PublishNotification(box); @@ -367,7 +435,6 @@ void DistributedService::OnHandleMsg(std::shared_ptr& box) break; #endif default: - ANS_LOGW("Dans receive msg %{public}d %{public}d.", type, box->bytesLength_); break; } }); 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 0f2e9f2fc2804b485fe0534a80ea8e17571d602f..a11344b1f8a022858e15192f25fbca17cba07786 100644 --- a/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_subscribe_service_v2.cpp @@ -41,7 +41,7 @@ static std::string SubscribeTransDeviceType(uint16_t deviceType) } } -static int32_t GetCurrentActiveUserId() +int32_t DistributedSubscribeService::GetCurrentActiveUserId() { int32_t userId = DEFAULT_USER_ID; int32_t ret = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(userId); diff --git a/services/distributed/src/tlv_box/bundle_icon_box.cpp b/services/distributed/src/tlv_box/bundle_icon_box.cpp index db16a8dbcf2215db11ba2168622c46e21d8fec93..0d72c9053d438f2d879c38b25fdd280730b98868 100644 --- a/services/distributed/src/tlv_box/bundle_icon_box.cpp +++ b/services/distributed/src/tlv_box/bundle_icon_box.cpp @@ -25,6 +25,7 @@ const int32_t BUNDLE_NAME_TYPE = 1; const int32_t ICON_TYPE = 2; const int32_t LENGTH_TYPE = 3; const int32_t ICON_START_INDEX = 10; +const int32_t BUNDLE_START_INDEX = 2000; } BundleIconBox::BundleIconBox() @@ -39,6 +40,14 @@ BundleIconBox::BundleIconBox(std::shared_ptr box) : BoxBase(box) { } +bool BundleIconBox::SetMessageType(int32_t messageType) +{ + if (box_ == nullptr) { + return false; + } + return box_->SetMessageType(messageType); +} + bool BundleIconBox::SetIconSyncType(int32_t type) { if (box_ == nullptr) { @@ -60,9 +69,13 @@ bool BundleIconBox::SetBundleList(const std::vector& bundleList) if (box_ == nullptr) { return false; } - int32_t index = 0; + int32_t messageType; + int32_t index = ICON_START_INDEX; + if (box_->GetMessageType(messageType)) { + index = (messageType == BUNDLE_ICON_SYNC) ? ICON_START_INDEX : BUNDLE_START_INDEX; + } for (auto& bundleName : bundleList) { - if (box_->PutValue(std::make_shared(ICON_START_INDEX + index, bundleName))) { + if (box_->PutValue(std::make_shared(index, bundleName))) { index++; } } @@ -120,9 +133,14 @@ bool BundleIconBox::GetBundleList(std::vector& bundleList) if (!GetDataLength(length)) { return false; } + int32_t messageType; + int32_t index = ICON_START_INDEX; + if (box_->GetMessageType(messageType)) { + index = (messageType == BUNDLE_ICON_SYNC) ? ICON_START_INDEX : BUNDLE_START_INDEX; + } for (int i = 0; i < length; i++) { std::string bundleName; - if (box_->GetStringValue(ICON_START_INDEX + i, bundleName)) + if (box_->GetStringValue(index + i, bundleName)) bundleList.push_back(bundleName); } return true; diff --git a/services/distributed/src/tlv_box/state_box.cpp b/services/distributed/src/tlv_box/state_box.cpp index b6a0690eca626444ced8fd1509ba05a7692ecba4..c763252c4d93acc1a3850f0797b2fd4d634d399f 100644 --- a/services/distributed/src/tlv_box/state_box.cpp +++ b/services/distributed/src/tlv_box/state_box.cpp @@ -54,6 +54,22 @@ bool NotifticationStateBox::GetState(int32_t& state) } return box_->GetInt32Value(LOCAL_DEVICE_STATUS, state); } + +bool NotifticationStateBox::GetLiveViewEnable(bool& enable) +{ + if (box_ == nullptr) { + return false; + } + return box_->GetBoolValue(LIVEVIEW_SYNC_ENABLE, enable); +} + +bool NotifticationStateBox::GetNotificationEnable(bool& enable) +{ + if (box_ == nullptr) { + return false; + } + return box_->GetBoolValue(NOTIFICATION_SYNC_ENABLE, enable); +} #else bool NotifticationStateBox::SetDeviceType(const std::string& deviceType) { @@ -78,6 +94,22 @@ bool NotifticationStateBox::SetState(int32_t state) } return box_->PutValue(std::make_shared(LOCAL_DEVICE_STATUS, state)); } + +bool NotifticationStateBox::SetLiveViewEnable(bool enable) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(LIVEVIEW_SYNC_ENABLE, enable)); +} + +bool NotifticationStateBox::SetNotificationEnable(bool enable) +{ + if (box_ == nullptr) { + return false; + } + return box_->PutValue(std::make_shared(NOTIFICATION_SYNC_ENABLE, enable)); +} #endif } } diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index 15f69d257efc4ffefd8ef7e7f5c8bf2c35bfe88e..887a6da932e9a52ff27a4fd498132496fdc06bcf 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -187,7 +187,7 @@ namespace OHOS { uint32_t status = fuzzData->ConsumeIntegral(); uint32_t controlFlag = fuzzData->ConsumeIntegral(); service->SetTargetDeviceStatus(deviceType, status, stringData); - service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData, userId); service->ClearAllNotificationGroupInfo(localSwitch); service->SetSlotFlagsAsBundle(bundleOption, fuzzData->ConsumeIntegral()); diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index 758fd77f1d3759137f02013a77c6872525582154..aa17b3ad4902ec6964a28fe544b6b43ddf6e4536 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -198,7 +198,7 @@ namespace OHOS { service->GetAllNotificationsBySlotType(notificationsVector, slotType); service->AllowUseReminder(bundleName, allowed); service->SetTargetDeviceStatus(deviceType, status, stringData); - service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData, userId); service->SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); service->SetSmartReminderEnabled(deviceType, enabled); diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index cf18bd29bbc72262d9029624329ce3e4e6230f0f..1ea099a647fa400b866ceb625d73f7c7a3841be4 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -201,7 +201,7 @@ namespace OHOS { service->GetAllNotificationsBySlotType(notificationsVector, slotType); service->AllowUseReminder(bundleName, allowed); service->SetTargetDeviceStatus(deviceType, status, stringData); - service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData); + service->SetTargetDeviceStatus(deviceType, status, controlFlag, stringData, userId); service->SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); service->SetSmartReminderEnabled(deviceType, enabled); diff --git a/tools/test/mock/mock_ans_manager_stub.h b/tools/test/mock/mock_ans_manager_stub.h index 3db72225618c62c9ce6b77ed21feb845317e58e3..2b1a7b37bac8716894fd1a24b42e077622671ff2 100644 --- a/tools/test/mock/mock_ans_manager_stub.h +++ b/tools/test/mock/mock_ans_manager_stub.h @@ -584,8 +584,20 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode SetTargetDeviceStatus( - const std::string& deviceType, uint32_t status, uint32_t controlFlag, const std::string& deveiceId) override + ErrCode SetTargetDeviceStatus(const std::string& deviceType, uint32_t status, uint32_t controlFlag, + const std::string& deveiceId, int32_t userId) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId, + int operatorType, const std::vector& bundleList) override + { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId, + bool notificaitonEnable, bool liveViewEnable) override { return ERR_ANS_INVALID_PARAM; }