diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 4fc86a2e1813f596ef24fa95439d5d5584bfc28d..a4de9d3c9c898633273f76a88c0a89d4177d9c22 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -168,6 +168,16 @@ const std::shared_ptr NotificationRequest::GetAdditionalData( return additionalParams_; } +void NotificationRequest::SetExtendInfo(const std::shared_ptr &extendInfo) +{ + extendInfo_ = extendInfo; +} + +const std::shared_ptr NotificationRequest::GetExtendInfo() const +{ + return extendInfo_; +} + void NotificationRequest::SetDeliveryTime(int64_t deliveryTime) { deliveryTime_ = deliveryTime; @@ -813,6 +823,7 @@ std::string NotificationRequest::Dump() ", removalWantAgent = " + (removalWantAgent_ ? "not null" : "null") + ", maxScreenWantAgent = " + (maxScreenWantAgent_ ? "not null" : "null") + ", additionalParams = " + (additionalParams_ ? "not null" : "null") + + ", extendInfo = " + (extendInfo_ ? "not null" : "null") + ", littleIcon = " + (littleIcon_ ? "not null" : "null") + ", bigIcon = " + (bigIcon_ ? "not null" : "null") + ", overlayIcon = " + (overlayIcon_ ? "not null" : "null") + @@ -947,6 +958,14 @@ NotificationRequest *NotificationRequest::FromJson(const nlohmann::json &jsonObj } } + if (jsonObject.find("extendInfo") != jsonEnd && jsonObject.at("extendInfo").is_string()) { + auto extendInfoStr = jsonObject.at("extendInfo").get(); + if (!extendInfoStr.empty()) { + AAFwk::WantParams extendInfoParams = AAFwk::WantParamWrapper::ParseWantParams(extendInfoStr); + pRequest->extendInfo_ = std::make_shared(extendInfoParams); + } + } + ConvertJsonToPixelMap(pRequest, jsonObject); if (!ConvertJsonToNotificationDistributedOptions(pRequest, jsonObject)) { @@ -1309,6 +1328,19 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const } } + valid = extendInfo_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether extendInfo is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(extendInfo_.get())) { + ANS_LOGE("Failed to write extendInfo"); + return false; + } + } + valid = littleIcon_ ? true : false; if (!parcel.WriteBool(valid)) { ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null"); @@ -1721,6 +1753,15 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) } } + valid = parcel.ReadBool(); + if (valid) { + extendInfo_ = std::shared_ptr(parcel.ReadParcelable()); + if (!extendInfo_) { + ANS_LOGE("Failed to read extendInfo"); + return false; + } + } + valid = parcel.ReadBool(); if (valid) { littleIcon_ = std::shared_ptr(parcel.ReadParcelable()); @@ -2065,6 +2106,7 @@ void NotificationRequest::CopyOther(const NotificationRequest &other) this->removalWantAgent_ = other.removalWantAgent_; this->maxScreenWantAgent_ = other.maxScreenWantAgent_; this->additionalParams_ = other.additionalParams_; + this->extendInfo_ = other.extendInfo_; this->littleIcon_ = other.littleIcon_; this->bigIcon_ = other.bigIcon_; this->overlayIcon_ = other.overlayIcon_; @@ -2122,6 +2164,14 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const extraInfoStr = wWrapper.ToString(); } jsonObject["extraInfo"] = extraInfoStr; + + std::string extendInfoStr; + if (extendInfo_) { + AAFwk::WantParamWrapper wWrapper(*extendInfo_); + extendInfoStr = wWrapper.ToString(); + } + jsonObject["extendInfo"] = extendInfoStr; + jsonObject["smallIcon"] = AnsImageUtil::PackImage(littleIcon_); jsonObject["largeIcon"] = AnsImageUtil::PackImage(bigIcon_); jsonObject["overlayIcon"] = overlayIcon_ ? AnsImageUtil::PackImage(overlayIcon_) : ""; diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 914bc78cfa68bb8d2fc7b1769afb1e3e35a71fb4..b1c4785782f9946e093ba632550269e897852a83 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -396,9 +396,9 @@ 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"}; + constexpr static const char* PAD_DEVICE_TYPE = "pad"; + constexpr static const char* PC_DEVICE_TYPE = "pc"; + constexpr static const char* DEVICESTYPES[] = {"headset", "liteWearable", "wearable", "pc", "pad"}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index c98dfbfdacac2ee58a41ecb79a7d91d4597dc5e6..21b6e8a32bb780536742e215e7fda1ae66510e3d 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -334,6 +334,20 @@ public: */ const std::shared_ptr GetAdditionalData() const; + /** + * @brief Sets extendInfo that are stored as key-value pairs for the notification. + * + * @param extras Indicates the WantParams object containing the extendInfo in key-value pair format. + */ + void SetExtendInfo(const std::shared_ptr &extendInfo); + + /** + * @brief Obtains the WantParams object set in the notification. + * + * @return Returns the WantParams object. + */ + const std::shared_ptr GetExtendInfo() const; + /** * @brief Sets the time to deliver a notification. * @@ -1618,6 +1632,7 @@ private: std::shared_ptr removalWantAgent_ {}; std::shared_ptr maxScreenWantAgent_ {}; std::shared_ptr additionalParams_ {}; + std::shared_ptr extendInfo_ {}; std::shared_ptr littleIcon_ {}; std::string littleIconType_ {}; mutable std::shared_ptr bigIcon_ {}; diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index 65d07cf44a4effa0362f53c2020e26e86847041b..e96a34e7f2cfa5db2bf616bc92eb63fb1ad777dc 100644 --- a/services/ans/include/bundle_manager_helper.h +++ b/services/ans/include/bundle_manager_helper.h @@ -145,6 +145,25 @@ public: bool GetBundleInfoV9(const std::string bundle, const int32_t flag, AppExecFwk::BundleInfo &bundleInfo, const int32_t userId); + /** + * @brief CheckSystemApp. + * @param bundleName bundle name. + * @param userId userId. + * @return Returns the query result. if systemapp, retrun true. + */ + bool CheckSystemApp(const std::string& bundleName, int32_t userId); + + /** + * @brief GetApplicationInfo. + * @param bundleName bundle name. + * @param flag query condation. + * @param userId userId. + * @param appInfo application info. + * @return Returns the query result. if succeed, retrun 0. + */ + ErrCode GetApplicationInfo(const std::string &bundleName, int32_t flags, int32_t userId, + AppExecFwk::ApplicationInfo &appInfo); + private: void Connect(); void Disconnect(); diff --git a/services/ans/include/distributed_device_status.h b/services/ans/include/distributed_device_status.h index 40e6f36df8c15e33973dade8d127a954a972dc56..34946459f6f2be7d63847e31e3f8604d47311c8d 100644 --- a/services/ans/include/distributed_device_status.h +++ b/services/ans/include/distributed_device_status.h @@ -46,6 +46,9 @@ public: const uint32_t controlFlag, const std::string deveiceId, int32_t userId); uint32_t GetDeviceStatus(const std::string &deviceType); + + DeviceStatus GetMultiDeviceStatus(const std::string &deviceType, const uint32_t status); + private: std::mutex mapLock_; std::vector deviceInfo_; diff --git a/services/ans/include/smart_reminder_center.h b/services/ans/include/smart_reminder_center.h index 47f1bd2f9af32da8b5f6ede2dd4989f7be07c3b6..cab44d153cc488d32d40718a7bc5fcc1da69ad54 100644 --- a/services/ans/include/smart_reminder_center.h +++ b/services/ans/include/smart_reminder_center.h @@ -89,6 +89,12 @@ private: void InitValidDevices(set &syncDevices, set &smartDevices, map> &statusMap, const sptr &request) const; + void InitPcPadDevices(const string &deviceType, + set &syncDevices, set &smartDevices, + map> &statusMap, + const sptr &request) const; + void FillRequestExtendInfo(const string &deviceType, DeviceStatus &deviceStatus, + const sptr &request) const; bool IsCollaborationAllowed(const sptr &request) const; map> currentReminderMethods_; map>>> reminderMethods_; @@ -104,6 +110,14 @@ private: constexpr static const char* SPLIT_FLAG = "|"; constexpr static const char* STATUS_UNUSED = "xxx0"; constexpr static const char* STATUS_UNLOCK_OWNER = "x01x"; + constexpr static const uint32_t STATUS_USED_FLAG = 1; + const std::string EXTEND_INFO_PRE = "notification_collaboration"; + const std::string EXTEND_INFO_APP_NAME = "app_name"; + const std::string EXTEND_INFO_APP_LABEL = "app_label"; + const std::string EXTEND_INFO_APP_ICON = "app_icon"; + const std::string EXTEND_INFO_APP_INDEX = "app_index"; + const std::string EXTEND_INFO_DEVICE_ID = "deviceId"; + const std::string EXTEND_INFO_USER_ID = "userId"; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index 3a86b24bd0801bd73aed9b345b74b10a34d888e1..0ad74dde2c66ea754f66749cd7f4a5579a9e012e 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -279,5 +279,41 @@ bool BundleManagerHelper::GetBundleInfoV9( IPCSkeleton::SetCallingIdentity(identity); return ret; } + +ErrCode BundleManagerHelper::GetApplicationInfo(const std::string &bundleName, 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(bundleName, flags, userId, appInfo); + IPCSkeleton::SetCallingIdentity(identity); + return result; +} + +bool BundleManagerHelper::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; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/distributed_device_status.cpp b/services/ans/src/distributed_device_status.cpp index 52a93bd7fcf914d529893df244efdf74a9963ecb..dbd2d66415b38ab74182ae5c810d59c96c2fcdab 100644 --- a/services/ans/src/distributed_device_status.cpp +++ b/services/ans/src/distributed_device_status.cpp @@ -108,5 +108,17 @@ uint32_t DistributedDeviceStatus::GetDeviceStatus(const std::string &deviceType) std::lock_guard lock(mapLock_); return deviceStatus_.ReadVal(deviceType); } + +DeviceStatus DistributedDeviceStatus::GetMultiDeviceStatus( + const std::string &deviceType, const uint32_t status) +{ + std::lock_guard lock(mapLock_); + for (DeviceStatus device : deviceInfo_) { + if (device.deviceType == deviceType && (device.status & status) > 0) { + return device; + } + } + return DeviceStatus("", ""); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp b/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp index 047cee1a2d0fc1c5424318c1097967f357a946f9..63e52c7be38f2ccd82a70aaf5d3661f275027649 100644 --- a/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp +++ b/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp @@ -25,6 +25,10 @@ #include "os_account_manager.h" #include "screenlock_manager.h" #include "string_utils.h" +#include "distributed_device_data_service.h" +#include "bundle_manager_helper.h" +#include "int_wrapper.h" +#include "string_wrapper.h" namespace OHOS { namespace Notification { @@ -307,6 +311,12 @@ void SmartReminderCenter::InitValidDevices( ANS_LOGI("not afford consume, deviceType = %{public}s", deviceType.c_str()); continue; } + + if (NotificationConstant::PC_DEVICE_TYPE == deviceType || NotificationConstant::PAD_DEVICE_TYPE == deviceType) { + InitPcPadDevices(deviceType, syncDevices, smartDevices, statusMap, request); + continue; + } + if (NotificationConstant::SlotType::LIVE_VIEW == request->GetSlotType()) { bool isEnable = false; std::string queryDeviceType = deviceType; @@ -364,6 +374,93 @@ void SmartReminderCenter::InitValidDevices( return; } +void SmartReminderCenter::InitPcPadDevices(const string &deviceType, + set &syncDevices, set &smartDevices, + map> &statusMap, + const sptr &request) const +{ + if (NotificationConstant::SlotType::LIVE_VIEW == request->GetSlotType() && + NotificationConstant::PC_DEVICE_TYPE == deviceType) { + ANS_LOGI("PC/PAD init, pc not support liveView"); + return; + } + // used device + DeviceStatus deviceStatus = DelayedSingleton::GetInstance()-> + GetMultiDeviceStatus(deviceType, STATUS_USED_FLAG); + if (deviceStatus.deviceType.empty()) { + ANS_LOGI("PC/PAD init, not get any used device, type = %{public}s", deviceType.c_str()); + return; + } + // switch + string deviceId = deviceStatus.deviceId; + if (NotificationConstant::SlotType::LIVE_VIEW == request->GetSlotType()) { + if (!DistributedDeviceDataService::GetInstance().GetDeviceLiveViewEnable(deviceType, deviceId)) { + ANS_LOGI("PC/PAD init, liveView switch is closed , type = %{public}s", deviceType.c_str()); + return; + } + } else { + if (!DistributedDeviceDataService::GetInstance().GetDeviceNotificationEnable(deviceType, deviceId)) { + ANS_LOGI("PC/PAD init, notification switch is closed , type = %{public}s", deviceType.c_str()); + return; + } + } + // application list + std::string bundleName = request->GetOwnerBundleName(); + int32_t userId = request->GetOwnerUserId(); + if (DistributedDeviceDataService::GetInstance().CheckDeviceBundleExist( + deviceType, deviceId, bundleName)) { + ANS_LOGI("PC/PAD init, application has installed, type = %{public}s, bundleName = %{public}s", + deviceType.c_str(), bundleName.c_str()); + return; + } + // system app + std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); + if (bundleManager != nullptr) { + if (bundleManager->CheckSystemApp(bundleName, userId)) { + ANS_LOGI("PC/PAD init, application is systemApp, type = %{public}s, bundleName = %{public}s", + deviceType.c_str(), bundleName.c_str()); + return; + } + } else { + ANS_LOGE("get bundleManager fail"); + } + FillRequestExtendInfo(deviceType, deviceStatus, request); + statusMap.insert(pair>( + deviceType, bitset(deviceStatus.status))); + syncDevices.insert(deviceType); + smartDevices.insert(deviceType); + return; +} + +void SmartReminderCenter::FillRequestExtendInfo(const string &deviceType, DeviceStatus &deviceStatus, + const sptr &request) const +{ + std::string bundleName = request->GetOwnerBundleName(); + int32_t userId = request->GetOwnerUserId(); + std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); + if (bundleManager != nullptr) { + int32_t flags = static_cast(AppExecFwk::GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT); + AppExecFwk::ApplicationInfo appInfo; + if (bundleManager->GetApplicationInfo(bundleName, flags, userId, appInfo) != ERR_OK) { + ANS_LOGI("FillRequestExtendInfo, get GetApplicationInfo error, type = %{public}s, bundleName = %{public}s", + deviceType.c_str(), bundleName.c_str()); + return; + } + std::shared_ptr extendInfo = request->GetExtendInfo(); + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_APP_NAME, AAFwk::String::Box(appInfo.name)); + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_APP_LABEL, AAFwk::String::Box(appInfo.label)); + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_APP_ICON, AAFwk::String::Box(appInfo.icon)); + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + EXTEND_INFO_APP_INDEX, AAFwk::Integer::Box(appInfo.appIndex)); + + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + deviceType + "_" + EXTEND_INFO_DEVICE_ID, + AAFwk::String::Box(deviceStatus.deviceId)); + extendInfo->SetParam(EXTEND_INFO_PRE + "_" + deviceType + "_" + EXTEND_INFO_USER_ID, + AAFwk::Integer::Box(deviceStatus.userId)); + return; + } + ANS_LOGE("get bundleManager fail"); +} + void SmartReminderCenter::HandleReminderMethods( const string &deviceType, const map>> &reminderFilterDevice,