diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 3f84be477cfa9ea18395d5b43945476254b37832..c9652dd32de622ba2db2e9300db875e35c644b0a 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -650,5 +650,10 @@ ErrCode NotificationHelper::SetHashCodeRule(const uint32_t type) { return DelayedSingleton::GetInstance()->SetHashCodeRule(type); } + +ErrCode NotificationHelper::GetOverlayIconScaleSize(uint32_t& scaleSize) +{ + return DelayedSingleton::GetInstance()->GetOverlayIconScaleSize(scaleSize); +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index b5bb444a076f619278473cf4a200f6d5882a91c7..03cb93dd9ff55c14d8fb91d7179c28c0f9fb7a42 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -328,6 +328,11 @@ void NotificationRequest::SetOverlayIcon(const std::shared_ptr overlayIcon_ = overlayIcon; } +void NotificationRequest::ResetOverlayIcon() const +{ + overlayIcon_ = nullptr; +} + const std::shared_ptr NotificationRequest::GetOverlayIcon() const { return overlayIcon_; diff --git a/frameworks/core/include/ans_image_util.h b/frameworks/core/include/ans_image_util.h index 350bdd187f059e2c6d8dca7ac7300c4d1e74f3aa..987d92756d6280bfa9c75961d233218bc3dade07 100644 --- a/frameworks/core/include/ans_image_util.h +++ b/frameworks/core/include/ans_image_util.h @@ -76,6 +76,7 @@ public: static bool ImageScale(const std::shared_ptr &pixelMap, int32_t width, int32_t height); + static bool HandleOverSizeOverlayIcon(const std::shared_ptr &pixelMap); /** * @brief Converts a binary string to a hexadecimal string. * diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 4907a4a87b8214a04a2702ddec4e65fdc1f815bf..e70d81fce1332df4cf7d8f8d5b23cfdcccd5d470 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -1024,6 +1024,8 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual ErrCode SetHashCodeRule(const uint32_t type) = 0; + + virtual ErrCode GetOverlayIconScaleSize(uint32_t& scaleSize) = 0; }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 5112f229dda205b2b4e086d3fbbcc89bcfb6f775..d6940411f0afe682ef114a7292bf09ff9d30d9dc 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -1007,6 +1007,8 @@ public: */ ErrCode SetHashCodeRule(const uint32_t type) override; + ErrCode GetOverlayIconScaleSize(uint32_t &scaleSize) override; + private: ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index cca1b132e64d2da244c3d26f7b813676e6893b61..f9c769edd0020e5fad6b922d4c51560c24466ca1 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -1119,6 +1119,7 @@ private: ErrCode HandleGetNotificationRequest(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetHashCodeRule(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetAllNotificationsBySlotType(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetOverlayIconScaleSize(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 092897c5feda7b32ec3d7dc1b46dbce90051dca4..cd15b460272c2cd9767b4c5d399ec9f4eb94126b 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -1247,6 +1247,8 @@ public: */ ErrCode SetHashCodeRule(const uint32_t type); + ErrCode GetOverlayIconScaleSize(uint32_t &scaleSize); + private: /** * @brief Gets Ans Manager proxy. diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 3117c42dce8ae2b02f87945a48a5e04572d25b40..186b6480cefccc0a386526c20da21c94495e5baf 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -159,6 +159,7 @@ namespace Notification { GET_NOTIFICATION_REQUEST_BY_HASHCODE, Set_HASH_CODE_RULE, GET_ALL_NOTIFICATIONS_BY_SLOTTYPE, + GET_OVERLAY_ICON_SCALE_SIZE, }; } } diff --git a/frameworks/core/src/ans_image_util.cpp b/frameworks/core/src/ans_image_util.cpp index 601168f1c9f9b7ba30bf7460798f86557798cbc0..d0a600d8a3aa0e26bf06145c3c7f2d759a6665f2 100644 --- a/frameworks/core/src/ans_image_util.cpp +++ b/frameworks/core/src/ans_image_util.cpp @@ -16,6 +16,7 @@ #include "ans_log_wrapper.h" #include "image_packer.h" #include "image_source.h" +#include "notification_helper.h" namespace OHOS { namespace Notification { @@ -262,5 +263,29 @@ std::string AnsImageUtil::HexToBin(const std::string &strHex) return strBin; } + +bool AnsImageUtil::HandleOverSizeOverlayIcon(const std::shared_ptr &pixelMap) +{ + uint32_t ccmScaleSize = 0; + + ErrCode code = NotificationHelper::GetOverlayIconScaleSize(ccmScaleSize); + if (code != ERR_OK || ccmScaleSize == 0) { + ANS_LOGW("get overlayIcon scale size failed."); + return false; + } + ANS_LOGD("overlayIcon size before scale: %{public}d", pixelMap->GetByteCount()); + auto icon = AnsImageUtil::ImageScale(pixelMap, ccmScaleSize, ccmScaleSize); + if (!icon) { + ANS_LOGE("overlayIcon is null after scale."); + return false; + } + ANS_LOGD("overlayIcon size after scale: %{public}d", pixelMap->GetByteCount()); + auto size = static_cast(pixelMap->GetByteCount()); + if (size > MAX_ICON_SIZE) { + ANS_LOGW("overlayIcon oversize after scale."); + return false; + } + return true; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 9c55dd970b8e2a269afec9a5905402d20e9f304c..e7cdf44106564046564f618dea13858bbf4b5278 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -26,6 +26,7 @@ #include "notification_local_live_view_subscriber.h" #include "system_ability_definition.h" #include "unique_fd.h" +#include "ans_image_util.h" #include #include @@ -1454,7 +1455,10 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) auto overlayIcon = request.GetOverlayIcon(); if (overlayIcon && NotificationRequest::CheckImageOverSizeForPixelMap(overlayIcon, MAX_ICON_SIZE)) { ANS_LOGE("The size of overlay icon exceeds limit"); - return ERR_ANS_ICON_OVER_SIZE; + if (!AnsImageUtil::HandleOverSizeOverlayIcon(overlayIcon)) { + ANS_LOGE("HandleOverSizeOverlayIcon failed."); + request.ResetOverlayIcon(); + } } ErrCode err = request.CheckImageSizeForContent(); @@ -2127,5 +2131,18 @@ ErrCode AnsNotification::GetAllNotificationsBySlotType(std::vectorGetAllNotificationsBySlotType(notifications, slotType); } +ErrCode AnsNotification::GetOverlayIconScaleSize(uint32_t& scale) +{ + ANS_LOGI("GetOverlayIconScaleSize proxy called."); + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetOverlayIconScaleSize(scale); +} + } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/listener/ans_subscriber_proxy.cpp b/frameworks/core/src/listener/ans_subscriber_proxy.cpp index a2fa1276c3ebe331f7e650aa1cd3c0ad23c75277..c50fad5490ba75d8c65c653793badd43b578aee0 100644 --- a/frameworks/core/src/listener/ans_subscriber_proxy.cpp +++ b/frameworks/core/src/listener/ans_subscriber_proxy.cpp @@ -101,6 +101,11 @@ void AnsSubscriberProxy::OnConsumed( ANS_LOGE("[OnConsumed] fail: set max capacity failed."); return; } + } else { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_COMMON_SIZE)) { + ANS_LOGE("[OnConsumed] fail: set common max capacity failed."); + return; + } } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnConsumed] fail: write interface token failed."); @@ -191,6 +196,11 @@ void AnsSubscriberProxy::OnCanceled( ANS_LOGE("[OnCanceled] fail: set max capacity failed."); return; } + } else { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_COMMON_SIZE)) { + ANS_LOGE("[OnConsumed] fail: set common max capacity failed."); + return; + } } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnCanceled] fail: write interface token failed."); diff --git a/frameworks/core/src/manager/ans_manager_proxy.cpp b/frameworks/core/src/manager/ans_manager_proxy.cpp index 3a4b887b75fa17b1db5451a404df391457ea43c8..cb5cc05c4e0fa0b626b9453cad95a43d3534f1db 100644 --- a/frameworks/core/src/manager/ans_manager_proxy.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy.cpp @@ -46,6 +46,10 @@ ErrCode AnsManagerProxy::Publish(const std::string &label, const sptr &overlayIcon); + void ResetOverlayIcon() const; + /** * @brief Obtains the overlay icon of this notification. * @@ -1603,7 +1605,7 @@ private: std::shared_ptr littleIcon_ {}; std::string littleIconType_ {}; mutable std::shared_ptr bigIcon_ {}; - std::shared_ptr overlayIcon_ {}; + mutable std::shared_ptr overlayIcon_ {}; std::shared_ptr notificationContent_ {}; std::vector> actionButtons_ {}; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 72fdee1ae82b72695a05ba2e738430ef7390e221..f47607cd63f217b4bf11769844088e44ba03f6b6 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1163,6 +1163,8 @@ public: */ ErrCode SetHashCodeRule(const uint32_t type) override; + ErrCode GetOverlayIconScaleSize(uint32_t& scaleSize) override; + protected: /** * @brief Query whether there is a agent relationship between the two apps. diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h index d55ddd22677c43df4e0e65a5f80d5f28476c46fb..de4b481cb7eae149f848f2e8e87ab63a0fe98bd0 100644 --- a/services/ans/include/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -59,6 +59,7 @@ public: void GetCollaborationFilter(); bool IsInCollaborationFilter(const std::string &bundleName, int32_t uid) const; uint32_t GetStartAbilityTimeout(); + uint32_t GetOverlayIconScaleSize() const; private: std::map defaultCurrentSlotReminder_; @@ -92,6 +93,7 @@ public: #endif constexpr static const char* CFG_KEY_COLLABORATIVE_DELETE_TYPES = "collaborativeDeleteTypes"; constexpr static const char* CFG_KEY_START_ABILITY_TIMEOUT = "startAbilityTimeout"; + constexpr static const char* CFG_KEY_OVERLAYICON_SCALE_SIZE = "overlayIconScaleSize"; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_dialog_manager.h b/services/ans/include/notification_dialog_manager.h index 2d8b6387723dc14f33af1c7140a9e6b777a81575..2b3ef129f5c5f48f5b2ff335aafb83c4635dec59 100644 --- a/services/ans/include/notification_dialog_manager.h +++ b/services/ans/include/notification_dialog_manager.h @@ -39,7 +39,8 @@ enum class DialogStatus { DENY_CLICKED, DIALOG_CRASHED, DIALOG_SERVICE_DESTROYED, - REMOVE_BUNDLE + REMOVE_BUNDLE, + DIALOG_OPEN }; class NotificationDialogEventSubscriber : public EventFwk::CommonEventSubscriber { @@ -128,6 +129,7 @@ private: bool HandleOneDialogClosed(sptr bundleOption, EnabledDialogStatus status); bool HandleAllDialogsClosed(); + bool OnDialogOpen(const std::string& bundleName, const int32_t& uid); std::shared_ptr dialogEventSubscriber = nullptr; AdvancedNotificationService& ans_; diff --git a/services/ans/include/notification_extension_wrapper.h b/services/ans/include/notification_extension_wrapper.h index af1a6e457d61380635d3c47b4b475538f16c6c15..2fc4f6ce98e8ea9927a9028b600d88b452aca04d 100644 --- a/services/ans/include/notification_extension_wrapper.h +++ b/services/ans/include/notification_extension_wrapper.h @@ -42,6 +42,8 @@ public: typedef void (*UPDATE_BY_BUNDLE)(const std::string bundleName, int deleteType); typedef int32_t (*REMINDER_CONTROL)(const std::string &bundleName); typedef int32_t (*BANNER_CONTROL)(const std::string &bundleName); + typedef bool (*GET_PRIVILEGE_DIALOG_POPPED)(const std::string bundleName, const int32_t &userId); + typedef bool (*SET_DIALOG_OPENSUCCESS_INFO)(const std::string bundleName, const int32_t &userId); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER typedef bool (*MODIFY_REMINDER_FLAGS)(const sptr &request); @@ -57,6 +59,8 @@ public: void UpdateByBundle(const std::string bundleName, int deleteType); int32_t ReminderControl(const std::string &bundleName); int32_t BannerControl(const std::string &bundleName); + bool GetPrivilegeDialogPopped(const std::string bundleName, const int32_t &userId); + bool SetDialogOpenSuccessInfo(const std::string &bundleName, const int32_t &userId); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER bool ModifyReminderFlags(const sptr &request); @@ -75,6 +79,8 @@ private: UPDATE_BY_BUNDLE updateByBundle_ = nullptr; REMINDER_CONTROL reminderControl_ = nullptr; BANNER_CONTROL bannerControl_ = nullptr; + GET_PRIVILEGE_DIALOG_POPPED getPrivilegeDialogPopped_ = nullptr; + SET_DIALOG_OPENSUCCESS_INFO setDialogOpenSuccessInfo_ = nullptr; bool isRegisterDataSettingObserver = false; #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 65220340101c8ef70f7d1d855d6e62099b15eb95..629989d78aaa6a5dc7a89e5303cf0c64f859770a 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -402,6 +402,7 @@ public: int32_t SetKvToDb(const std::string &key, const std::string &value, const int32_t &userId); int32_t SetByteToDb(const std::string &key, const std::vector &value, const int32_t &userId); int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId); + int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId, int32_t &retCode); int32_t GetByteFromDb(const std::string &key, std::vector &value, const int32_t &userId); int32_t GetBatchKvsFromDb( const std::string &key, std::unordered_map &values, const int32_t &userId); diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 5e7f0623073aca9b984f2c3a8e7f929f6d621d09..88109d626762237b744dd0f929e7b0e6cd273831 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -261,6 +261,7 @@ public: int32_t SetKvToDb(const std::string &key, const std::string &value, const int32_t &userId); int32_t SetByteToDb(const std::string &key, const std::vector &value, const int32_t &userId); int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId); + int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId, int32_t &retCode); int32_t GetByteFromDb(const std::string &key, std::vector &value, const int32_t &userId); int32_t GetBatchKvsFromDb( const std::string &key, std::unordered_map &values, const int32_t &userId); diff --git a/services/ans/libans.map b/services/ans/libans.map index fde762ab00015c1b2f029e550705f6e54fd8acd3..7433ff4b766d80d7c8182e49b46664c39404d85c 100644 --- a/services/ans/libans.map +++ b/services/ans/libans.map @@ -52,6 +52,9 @@ *Subscribe*; *UpdateSlots*; *VerifyShellToken*; + *GetAdditionalConfig*; + *SetKvToDb*; + *GetKvFromDb*; local: *; }; diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 81f3ae201d5557136dab160813ccf3cc03954a11..a59707871debdf25471f35062d0ff2f1532e05ef 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -56,6 +56,7 @@ #include "datashare_predicates.h" #include "notification_config_parse.h" #include "advanced_notification_flow_control_service.h" +#include "notification_extension_wrapper.h" namespace OHOS { namespace Notification { @@ -1041,10 +1042,14 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string return ERROR_INTERNAL_ERROR; } if (hasPopped) { - ANS_LOGE("Has popped is true."); - message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has popped"); - NotificationAnalyticsUtil::ReportModifyEvent(message); - return ERR_ANS_NOT_ALLOWED; + int32_t userId = -1; + OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(userId); + if (!EXTENTION_WRAPPER->GetPrivilegeDialogPopped(bundleOption->GetBundleName(), userId)) { + ANS_LOGE("Has popped is true."); + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has popped"); + NotificationAnalyticsUtil::ReportModifyEvent(message); + return ERR_ANS_NOT_ALLOWED; + } } if (!CreateDialogManager()) { @@ -2538,6 +2543,13 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrGetOverlayIconScaleSize(); + return ERR_OK; +} + ErrCode AdvancedNotificationService::GetTargetDeviceStatus(const std::string &deviceType, int32_t &status) { ANS_LOGD("%{public}s", __FUNCTION__); diff --git a/services/ans/src/ans_manager_stub.cpp b/services/ans/src/ans_manager_stub.cpp index 4c71264986f86cdcb0bb69fe0ee8621367d91c4a..9911ac542b9483ad8401e8c85da55db9914f93ea 100644 --- a/services/ans/src/ans_manager_stub.cpp +++ b/services/ans/src/ans_manager_stub.cpp @@ -457,6 +457,10 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess result = HandleGetAllNotificationsBySlotType(data, reply); break; } + case static_cast(NotificationInterfaceCode::GET_OVERLAY_ICON_SCALE_SIZE): { + result = HandleGetOverlayIconScaleSize(data, reply); + break; + } default: { ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); @@ -2630,5 +2634,16 @@ ErrCode AnsManagerStub::HandleGetAllNotificationsBySlotType(MessageParcel &data, } return ERR_OK; } + +ErrCode AnsManagerStub::HandleGetOverlayIconScaleSize(MessageParcel &data, MessageParcel &reply) +{ + uint32_t scaleSize; + uint32_t errCode = GetOverlayIconScaleSize(scaleSize); + if (!reply.WriteUint32(scaleSize)) { + ANS_LOGE("[HandleGetOverlayIconScaleSize] fail: write result failed, ErrCode=%{public}d", scaleSize); + return ERR_ANS_PARCELABLE_FAILED; + } + return errCode; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/common/notification_config_parse.cpp b/services/ans/src/common/notification_config_parse.cpp index 038a28a2c96dba300c33a2ed8e2c19007389c05d..0da1d4970335c9c714da0e909ab2ec3a2083c4d2 100644 --- a/services/ans/src/common/notification_config_parse.cpp +++ b/services/ans/src/common/notification_config_parse.cpp @@ -466,6 +466,30 @@ void NotificationConfigParse::GetReportTrustListConfig() return; } +uint32_t NotificationConfigParse::GetOverlayIconScaleSize() const +{ + uint32_t ret = 0; + nlohmann::json root; + std::string JsonPoint = "/"; + JsonPoint.append(CFG_KEY_NOTIFICATION_SERVICE); + if (!GetConfigJson(JsonPoint, root)) { + ANS_LOGE("Fail to get JsonPoint CCM config file."); + return 0; + } + if (!root.contains(CFG_KEY_NOTIFICATION_SERVICE)) { + ANS_LOGW("GetOverlayIconScaleSize not found jsonKey"); + return 0; + } + nlohmann::json affects = root[CFG_KEY_NOTIFICATION_SERVICE]; + if (affects.is_null() || affects.empty()) { + ANS_LOGE("GetOverlayIconScaleSize failed as invalid json value.") + return 0; + } + if (affects.contains(CFG_KEY_OVERLAYICON_SCALE_SIZE)) { + return affects[CFG_KEY_OVERLAYICON_SCALE_SIZE]; + } + return 0; +} bool NotificationConfigParse::IsReportTrustList(const std::string& bundleName) const { diff --git a/services/ans/src/notification_dialog_manager.cpp b/services/ans/src/notification_dialog_manager.cpp index ad69e94423175369dce95fd121d0443020ee0a2e..b93b442804dc06602a890905659bcb928716f9ae 100644 --- a/services/ans/src/notification_dialog_manager.cpp +++ b/services/ans/src/notification_dialog_manager.cpp @@ -24,6 +24,8 @@ #include "notification_bundle_option.h" #include "notification_dialog.h" #include "notification_preferences.h" +#include "os_account_manager_helper.h" +#include "notification_extension_wrapper.h" #include #include @@ -133,6 +135,9 @@ ErrCode NotificationDialogManager::OnBundleEnabledStatusChanged( case DialogStatus::REMOVE_BUNDLE: result = onRemoveBundle(bundleName, uid); break; + case DialogStatus::DIALOG_OPEN: + result = OnDialogOpen(bundleName, uid); + break; default: result = false; } @@ -312,4 +317,12 @@ bool NotificationDialogManager::HandleAllDialogsClosed() return true; } +bool NotificationDialogManager::OnDialogOpen(const std::string& bundleName, const int32_t& uid) +{ + ANS_LOGD("enter"); + int32_t userId; + OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId); + return EXTENTION_WRAPPER->SetDialogOpenSuccessInfo(bundleName, userId); +} + } // namespace OHOS::Notification diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index ac27c03ec1205c3afd994660937b2dbd71349cc5..ce23c215ef593e12736a0fc4cf357e577aa5dceb 100644 --- a/services/ans/src/notification_extension_wrapper.cpp +++ b/services/ans/src/notification_extension_wrapper.cpp @@ -25,6 +25,10 @@ #include "common_event_subscriber.h" #include "system_event_observer.h" +#ifndef SYMBOL_EXPORT +#define SYMBOL_EXPORT __attribute__ ((visibility("default"))) +#endif + namespace OHOS::Notification { const std::string EXTENTION_WRAPPER_PATH = "libans_ext.z.so"; const int32_t ACTIVE_DELETE = 0; @@ -45,6 +49,22 @@ void UpdateUnifiedGroupInfo(const std::string &key, std::shared_ptrUpdateUnifiedGroupInfo(key, groupInfo); } +SYMBOL_EXPORT void GetAdditionalConfig(const std::string &key, std::string &value) +{ + value = NotificationPreferences::GetInstance()->GetAdditionalConfig(key); + ANS_LOGD("GetAdditionalConfig SYMBOL_EXPORT valiue %{public}s", value.c_str()); +} + +SYMBOL_EXPORT int32_t SetKvToDb(const std::string &key, const std::string &value, const int32_t &userId) +{ + return NotificationPreferences::GetInstance()->SetKvToDb(key, value, userId); +} + +SYMBOL_EXPORT int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId, int32_t& retCode) +{ + return NotificationPreferences::GetInstance()->GetKvFromDb(key, value, userId, retCode); +} + #ifdef __cplusplus } #endif @@ -92,6 +112,16 @@ void ExtensionWrapper::InitExtentionWrapper() initSummary_(UpdateUnifiedGroupInfo); } #endif + getPrivilegeDialogPopped_ = (GET_PRIVILEGE_DIALOG_POPPED)dlsym(extensionWrapperHandle_, "GetPrivilegeDialogPopped"); + if (getPrivilegeDialogPopped_ == nullptr) { + ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); + return; + } + setDialogOpenSuccessInfo_ = (SET_DIALOG_OPENSUCCESS_INFO)dlsym(extensionWrapperHandle_, "SetDialogOpenSuccessInfo"); + if (setDialogOpenSuccessInfo_ == nullptr) { + ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); + return; + } ANS_LOGD("extension wrapper init success"); } @@ -179,6 +209,24 @@ int32_t ExtensionWrapper::BannerControl(const std::string &bundleName) return bannerControl_(bundleName); } +bool ExtensionWrapper::GetPrivilegeDialogPopped(const std::string bundleName, const int32_t &userId) +{ + if (getPrivilegeDialogPopped_ == nullptr) { + ANS_LOGE("GetPrivilegeDialogPopped wrapper symbol failed."); + return -1; + } + return getPrivilegeDialogPopped_(bundleName, userId); +} + +bool ExtensionWrapper::SetDialogOpenSuccessInfo(const std::string& bundleName, const int32_t &userId) +{ + if (setDialogOpenSuccessInfo_ == nullptr) { + ANS_LOGE("SetDialogOpenSuccessInfo wrapper symbol failed."); + return -1; + } + return setDialogOpenSuccessInfo_(bundleName, userId); +} + #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER bool ExtensionWrapper::ModifyReminderFlags(const sptr &request) { diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 8940321bf275eb50388e593d2b2165a836f49ac1..519b5094b9146214725bfa0ca53c368f58490c6d 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -1264,6 +1264,15 @@ int32_t NotificationPreferences::GetKvFromDb( return preferncesDB_->GetKvFromDb(key, value, userId); } +int32_t NotificationPreferences::GetKvFromDb( + const std::string &key, std::string &value, const int32_t &userId, int32_t &retCode) +{ + if (preferncesDB_ == nullptr) { + return ERR_ANS_SERVICE_NOT_READY; + } + return preferncesDB_->GetKvFromDb(key, value, userId, retCode); +} + int32_t NotificationPreferences::GetByteFromDb( const std::string &key, std::vector &value, const int32_t &userId) { diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 7d472327ff29ef8efb580989c8bc2f65d3026be5..2a06a68491046e592a8f0ac89bbaa7e781e4cf5c 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -1869,6 +1869,18 @@ int32_t NotificationPreferencesDatabase::GetKvFromDb( return NativeRdb::E_OK; } +int32_t NotificationPreferencesDatabase::GetKvFromDb( + const std::string &key, std::string &value, const int32_t &userId, int32_t &retCode) +{ + if (!CheckRdbStore()) { + ANS_LOGE("RdbStore is nullptr."); + return NativeRdb::E_ERROR; + } + + retCode = rdbDataManager_->QueryData(key, value, userId); + return retCode; +} + int32_t NotificationPreferencesDatabase::GetByteFromDb( const std::string &key, std::vector &value, const int32_t &userId) {