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 b080b4d64c64982bdfd15f8e03f784a3198f2dff..812f4c147b4827956da40bbe68de52bab1b1ca7f 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 @@ -454,6 +454,11 @@ ErrCode AdvancedNotificationService::SetTargetDeviceStatus(const std::string &de return ERR_ANS_NON_SYSTEM_APP; } + if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + ANS_LOGD("Check permission is false."); + return ERR_ANS_PERMISSION_DENIED; + } + if (deviceType == NotificationConstant::PAD_DEVICE_TYPE || deviceType == NotificationConstant::PC_DEVICE_TYPE) { return DelayedSingleton::GetInstance()->SetDeviceStatus(deviceType, status, controlFlag, deviceId, userId); diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp index a5a37bd7320c9936bab39472bd89c916781730aa..52719436a6fb545ea3b18e5c2091d4f9f26098ea 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_distributed_manager_service_test.cpp @@ -370,7 +370,7 @@ HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_400, Func auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId); - ASSERT_EQ(ret, (int)ERR_OK); + ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED); } /** diff --git a/services/distributed/include/tlv_box/request_box.h b/services/distributed/include/tlv_box/request_box.h index 2946f12cf78ed7d246d984d853e0d8311b9fba1b..d64422b3d1a07d244206d066a7e39ebce1d4e5e9 100644 --- a/services/distributed/include/tlv_box/request_box.h +++ b/services/distributed/include/tlv_box/request_box.h @@ -53,10 +53,8 @@ public: 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 SetReceiverUserId(const int32_t& userId); + bool SetBoxExtendInfo(const std::string& extendInfo); bool SetDeviceUserId(const int32_t& userId); bool SetDeviceId(const std::string& deviceId); bool SetActionButtonsLength(const int32_t length); @@ -86,10 +84,8 @@ public: 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 GetReceiverUserId(int32_t& userId) const; + bool GetBoxExtendInfo(std::string& extendInfo) const; bool GetDeviceUserId(int32_t& userId) const; bool GetDeviceId(std::string& deviceId) const; bool GetActionButtonsLength(int32_t& length) const; diff --git a/services/distributed/include/tlv_box/tlv_box.h b/services/distributed/include/tlv_box/tlv_box.h index 4e47ca1e85a11dbf7778b31cac9e749e62b9f884..88fb1275c1c6419f5d7d996046accd3bcc35e02e 100644 --- a/services/distributed/include/tlv_box/tlv_box.h +++ b/services/distributed/include/tlv_box/tlv_box.h @@ -64,12 +64,9 @@ enum TlvType : int32_t { NOTIFICATION_LONG_TITLE = 22, ALL_LINES_LENGTH = 23, NOTIFICATION_APP_MESSAGE_ID = 24, - NOTIFICATION_USERID = 981, - DEVICE_USERID = 982, - APP_ICON = 983, - APP_INDEX = 984, - APP_LABEL = 985, - APP_NAME = 986, + NOTIFICATION_EXTENDINFO = 25, + NOTIFICATION_RECEIVE_USERID = 26, + LOCAL_DEVICE_USERID = 986, LIVEVIEW_SYNC_ENABLE = 987, NOTIFICATION_SYNC_ENABLE = 988, RESULT_CODE = 989, 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 a58a02945fcbbe3bc7e1128989d48ccd414fe5a5..966adec562b6900477c570bd5dc6463c807c1758 100644 --- a/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp +++ b/services/distributed/src/soft_bus/distributed_publish_service_v2.cpp @@ -35,6 +35,7 @@ #include "bool_wrapper.h" #include "int_wrapper.h" #include "string_wrapper.h" +#include "want_params_wrapper.h" #include "distributed_subscribe_service.h" #include "remove_all_distributed_box.h" #include "bundle_resource_helper.h" @@ -538,28 +539,24 @@ void DistributedPublishService::SetNotificationExtendInfo(const sptrGetStringParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_NAME); if (!content.empty()) { - requestBox->SetAppName(content); - if (notificationRequest->GetLittleIcon() == nullptr) { - AppExecFwk::BundleResourceInfo resourceInfo; - if (DelayedSingleton::GetInstance()->GetBundleInfo(content, resourceInfo) != 0) { - ANS_LOGW("Dans get bundle icon failed %{public}s.", content.c_str()); - return; - } - std::shared_ptr iconPixelmap = AnsImageUtil::CreatePixelMapByString(resourceInfo.icon); - requestBox->SetSmallIcon(iconPixelmap); - ANS_LOGI("Dans self get bundle icon."); + AppExecFwk::BundleResourceInfo resourceInfo; + if (DelayedSingleton::GetInstance()->GetBundleInfo(content, resourceInfo) != 0) { + ANS_LOGW("Dans get bundle icon failed %{public}s.", content.c_str()); + return; } + std::shared_ptr icon = AnsImageUtil::CreatePixelMapByString(resourceInfo.icon); + requestBox->SetSmallIcon(icon); } - content = params->GetStringParam(EXTENDINFO_INFO_PRE + EXTENDINFO_APP_LABEL); - if (!content.empty()) { - requestBox->SetAppLabel(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); + int32_t userId = params->GetIntParam(key, -1); + if (userId != -1) { + requestBox->SetReceiverUserId(userId); + } + params->DumpInfo(0); + AAFwk::WantParamWrapper wantWrapper(*params); + requestBox->SetBoxExtendInfo(wantWrapper.ToString()); requestBox->SetDeviceUserId(DistributedSubscribeService::GetCurrentActiveUserId()); } @@ -743,23 +740,23 @@ void DistributedPublishService::MakeNotificationReminderFlag(const NotificationR void DistributedPublishService::MakeExtendInfo(const NotificationRequestBox& box, sptr& request) { - std::string info; + std::string contentInfo; std::shared_ptr extendInfo = std::make_shared(); + if (box.GetBoxExtendInfo(contentInfo)) { + if (!contentInfo.empty()) { + AAFwk::WantParams extendInfoParams = AAFwk::WantParamWrapper::ParseWantParams(contentInfo); + extendInfo = std::make_shared(extendInfoParams); + } + } 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)) { + if (box.GetDeviceId(contentInfo)) { DistributedDeviceInfo peerDevice; - if (DistributedDeviceService::GetInstance().GetDeviceInfo(info, peerDevice)) { + if (DistributedDeviceService::GetInstance().GetDeviceInfo(contentInfo, peerDevice)) { std::string deviceType = DistributedDeviceService::DeviceTypeToTypeString(peerDevice.deviceType_); extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_DEVICETYPE, AAFwk::String::Box(deviceType)); extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_DEVICE_ID, AAFwk::String::Box(peerDevice.udid_)); @@ -767,15 +764,11 @@ void DistributedPublishService::MakeExtendInfo(const NotificationRequestBox& box } std::string localType = DistributedDeviceService::DeviceTypeToTypeString(local.deviceType_); extendInfo->SetParam(EXTENDINFO_INFO_PRE + EXTENDINFO_LOCALTYPE, AAFwk::String::Box(localType)); - 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)) { + if (box.GetReceiverUserId(userId)) { request->SetReceiverUserId(userId); } } diff --git a/services/distributed/src/tlv_box/request_box.cpp b/services/distributed/src/tlv_box/request_box.cpp index f7ac47a5dba00881636520ed8c25014e4ced58ce..015c11b35ca35b2a7b7b3a24a135ba099ddba134 100644 --- a/services/distributed/src/tlv_box/request_box.cpp +++ b/services/distributed/src/tlv_box/request_box.cpp @@ -267,36 +267,21 @@ 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) +bool NotificationRequestBox::SetReceiverUserId(const int32_t& userId) { if (box_ == nullptr) { return false; } - return box_->PutValue(std::make_shared(APP_INDEX, appIndex)); + return box_->PutValue(std::make_shared(NOTIFICATION_RECEIVE_USERID, userId)); } -bool NotificationRequestBox::SetNotificationUserId(const int32_t& userId) +bool NotificationRequestBox::SetBoxExtendInfo(const std::string& extendInfo) { if (box_ == nullptr) { return false; } - return box_->PutValue(std::make_shared(NOTIFICATION_USERID, userId)); + return box_->PutValue(std::make_shared(NOTIFICATION_EXTENDINFO, extendInfo)); } bool NotificationRequestBox::SetDeviceUserId(const int32_t& userId) @@ -304,7 +289,7 @@ bool NotificationRequestBox::SetDeviceUserId(const int32_t& userId) if (box_ == nullptr) { return false; } - return box_->PutValue(std::make_shared(DEVICE_USERID, userId)); + return box_->PutValue(std::make_shared(LOCAL_DEVICE_USERID, userId)); } bool NotificationRequestBox::SetDeviceId(const std::string& deviceId) @@ -557,36 +542,20 @@ 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 +bool NotificationRequestBox::GetBoxExtendInfo(std::string& extendInfo) const { if (box_ == nullptr) { return false; } - return box_->GetInt32Value(APP_INDEX, appIndex); + return box_->GetStringValue(NOTIFICATION_EXTENDINFO, extendInfo); } -bool NotificationRequestBox::GetNotificationUserId(int32_t& userId) const +bool NotificationRequestBox::GetReceiverUserId(int32_t& userId) const { if (box_ == nullptr) { return false; } - return box_->GetInt32Value(NOTIFICATION_USERID, userId); + return box_->GetInt32Value(NOTIFICATION_RECEIVE_USERID, userId); } bool NotificationRequestBox::GetDeviceUserId(int32_t& userId) const @@ -594,7 +563,7 @@ bool NotificationRequestBox::GetDeviceUserId(int32_t& userId) const if (box_ == nullptr) { return false; } - return box_->GetInt32Value(DEVICE_USERID, userId); + return box_->GetInt32Value(LOCAL_DEVICE_USERID, userId); } bool NotificationRequestBox::GetDeviceId(std::string& deviceId) const