diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index c8203b8843b0fed2999a98c9832a45fbc2683d34..2d9169f66eb850342f1e5f413b66ec6269371603 100644 --- a/frameworks/ans/IAnsManager.idl +++ b/frameworks/ans/IAnsManager.idl @@ -293,4 +293,6 @@ interface OHOS.Notification.IAnsManager { 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 34dce1c8468455a29cafd62e9ad9d8e274401559..c3caeb74e2546672374e5a5c231252ddc6251fb3 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -680,5 +680,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 de6a313a2c3df71ca5d744a97570aa893a910e0a..d3370c1481625ef64c2393d6456d7bd26bf9759a 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -333,6 +333,11 @@ const std::shared_ptr NotificationRequest::GetOverlayIcon() con return overlayIcon_; } +void NotificationRequest::ResetOverlayIcon() const +{ + overlayIcon_ = nullptr; +} + void NotificationRequest::SetClassification(const std::string &classification) { classification_ = classification; diff --git a/frameworks/core/include/ans_image_util.h b/frameworks/core/include/ans_image_util.h index 350bdd187f059e2c6d8dca7ac7300c4d1e74f3aa..e87db21651a8de0643a579f91ea6be2824bd24cb 100644 --- a/frameworks/core/include/ans_image_util.h +++ b/frameworks/core/include/ans_image_util.h @@ -76,6 +76,8 @@ 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_notification.h b/frameworks/core/include/ans_notification.h index 1685a8d036536fca3ecabcb9e1a17b38979617af..1d24fbead6eb482463ab5e954b9b726e457ce12a 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -1280,6 +1280,14 @@ public: */ ErrCode SetHashCodeRule(const uint32_t type); + /** + * @brief get the scale size of overlay icon. + * + * @param scaleSize the scale size of overlay icon. + * @return Returns ERR_OK on success, others on failure. + */ + 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 36d02911b985557da4b5e340dbb62d33d89f6606..594551260ddd09d0915973ae001203a66dfc2040 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -111,6 +111,7 @@ namespace Notification { REGISTER_PUSH_CALLBACK, UNREGISTER_PUSH_CALLBACK, DISTRIBUTE_OPERATION, + GET_OVERLAY_ICON_SCALE_SIZE, // ans_subscriber_interface ON_CONNECTED, ON_DISCONNECTED, diff --git a/frameworks/core/src/ans_image_util.cpp b/frameworks/core/src/ans_image_util.cpp index f5c2458bbae60e7d27ff957b8607eed600609c3f..1fba0c829ebbcf32ad1948ca3116f8190e007544 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 { @@ -183,6 +184,30 @@ bool AnsImageUtil::ImageScale(const std::shared_ptr &pixelMap, return true; } +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; +} + std::shared_ptr AnsImageUtil::CreatePixelMapByString(const std::string &imagedata) { if (imagedata.empty()) { diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index ec0355a05fdfb7424bfc7deab68120da170db5ff..296a4a5b6d0450ab43b016bacc33d5757f0e31dc 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 @@ -1587,7 +1588,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(); @@ -2241,6 +2245,19 @@ ErrCode AnsNotification::DisableNotificationFeature(const NotificationDisable &n return proxy->DisableNotificationFeature(reqPtr); } +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); +} + ErrCode AnsNotification::DistributeOperation(sptr& operationInfo, const sptr &callback) { diff --git a/frameworks/js/napi/src/manager/napi_sync_config.cpp b/frameworks/js/napi/src/manager/napi_sync_config.cpp index b023048fe97c18f5efe66e9fadfabea783ec4e2b..0959947da6c3848c596c325b9c98add544065d79 100644 --- a/frameworks/js/napi/src/manager/napi_sync_config.cpp +++ b/frameworks/js/napi/src/manager/napi_sync_config.cpp @@ -26,6 +26,7 @@ namespace { constexpr char KEY_NAME[] = "AGGREGATE_CONFIG"; constexpr char RING_LIST_KEY_NAME[] = "RING_TRUSTLIST_PKG"; constexpr char CTRL_LIST_KEY_NAME[] = "NOTIFICATION_CTL_LIST_PKG"; + constexpr char CAMPAIGN_NOTIFICATION_SWITCH_LIST_PKG[] = "CAMPAIGN_NOTIFICATION_SWITCH_LIST_PKG"; } struct ConfigParams { @@ -70,7 +71,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, params.key = keyStr; if (std::strlen(keyStr) == 0 || (strcmp(keyStr, KEY_NAME) != 0 && strcmp(keyStr, RING_LIST_KEY_NAME) != 0 - && strcmp(keyStr, CTRL_LIST_KEY_NAME) != 0)) { + && strcmp(keyStr, CTRL_LIST_KEY_NAME) != 0 && strcmp(keyStr, CAMPAIGN_NOTIFICATION_SWITCH_LIST_PKG) != 0)) { ANS_LOGE("Argument type error. String expected."); std::string msg = "Incorrect parameter types.The type of param must be string."; Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index fc9bd295b3191c08770a0892a95e1bb38da51671..aab4a33b7b6715f1f40a70670e3286847e6f1564 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -1249,6 +1249,14 @@ public: * @return Returns ERR_OK on success, others on failure. */ static ErrCode SetHashCodeRule(const uint32_t type); + + /** + * @brief get scale size of the overlay icon. + * + * @param scaleSize the scale size of the overlay icon.. + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode GetOverlayIconScaleSize(uint32_t& scaleSize); }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 4788f2fc6c5c75702ee174ad1a59ee4adcbb9dc2..94bfacde50e8897efd10058a6e4417bcfab957e6 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -553,6 +553,12 @@ public: */ void SetOverlayIcon(const std::shared_ptr &overlayIcon); + /** + * @brief reset the overlay icon of this notification. + * + */ + void ResetOverlayIcon() const; + /** * @brief Obtains the overlay icon of this notification. * @@ -1608,7 +1614,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 15043b053466e5c67526c81caac8f2bbd88c9813..e5c7194d448ead403b53ed174373304e46ebfebc 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1279,6 +1279,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 77b9f77450eee8045099742a594fa6dd6f1c358d..b8ba792a4e0fd985796bac31a95bf65886b65b1b 100644 --- a/services/ans/include/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -61,6 +61,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_; @@ -95,6 +96,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 2b9d7d67975afc76e753df8fbfe588e8cad738d1..e96d11ee782915a53dd8d8f04ab46ebdd5774b15 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 { @@ -131,6 +132,9 @@ private: bool HandleOneDialogClosed(sptr bundleOption, EnabledDialogStatus status); bool HandleAllDialogsClosed(); +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + bool OnDialogOpen(const std::string& bundleName, const int32_t& uid); +#endif 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..10df227560853ca72d3db6a43cb5e2ec0c142f2b 100644 --- a/services/ans/include/notification_extension_wrapper.h +++ b/services/ans/include/notification_extension_wrapper.h @@ -45,6 +45,8 @@ public: #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER typedef bool (*MODIFY_REMINDER_FLAGS)(const sptr &request); + 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); #endif ErrCode SyncAdditionConfig(const std::string& key, const std::string& value); @@ -60,6 +62,8 @@ public: #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER bool ModifyReminderFlags(const sptr &request); + bool GetPrivilegeDialogPopped(const std::string bundleName, const int32_t &userId); + bool SetDialogOpenSuccessInfo(const std::string bundleName, const int32_t &userId); #endif private: @@ -79,6 +83,8 @@ private: #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER MODIFY_REMINDER_FLAGS modifyReminderFlags_ = nullptr; + GET_PRIVILEGE_DIALOG_POPPED getPrivilegeDialogPopped_ = nullptr; + SET_DIALOG_OPENSUCCESS_INFO setDialogOpenSuccessInfo_ = nullptr; #endif }; diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 97eed85dcc1d2badb5e88c03b8e1a43e8a0b2140..8f7df07c3544b655256afc90ae97a9b5b1bdd711 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -402,6 +402,9 @@ 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); +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId, int32_t &retCode); +#endif 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 b0ad444f1c44abb5e25b0d519682eba8540f3888..f446f3cc6756e24424bc83016ce5d7daf7550fa5 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 4169be73283abd7fec622f3b7b7864b1485f83d3..b21d5fd7e1d2b0aa05d027725b6ef939d2094be6 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -58,6 +58,7 @@ #include "advanced_notification_flow_control_service.h" #include "notification_operation_info.h" #include "notification_operation_service.h" +#include "notification_extension_wrapper.h" namespace OHOS { namespace Notification { @@ -1152,10 +1153,18 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: 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; +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + int32_t userId = -1; + OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(userId); + if (!EXTENTION_WRAPPER->GetPrivilegeDialogPopped(bundleOption->GetBundleName(), userId)) { +#endif + ANS_LOGE("Has popped is true."); + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has popped"); + NotificationAnalyticsUtil::ReportModifyEvent(message); + return ERR_ANS_NOT_ALLOWED; +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + } +#endif } if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { return ERR_ANS_NOT_ALLOWED; @@ -2704,6 +2713,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/common/notification_config_parse.cpp b/services/ans/src/common/notification_config_parse.cpp index 1f28fe0184ced14ccfaa63959ca79671440eb4ca..2863c12edee4bb6288b5ca5fa11aa88cbd6f0254 100644 --- a/services/ans/src/common/notification_config_parse.cpp +++ b/services/ans/src/common/notification_config_parse.cpp @@ -477,6 +477,30 @@ void NotificationConfigParse::GetReportTrustListConfig() return; } +uint32_t NotificationConfigParse::GetOverlayIconScaleSize() const +{ + uint32_t ret; + 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 key."); + 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 2e2f4e23bada6d5a88f003fe02d586d26d0f683f..eba19565660afc5e0711070a8d9c0fe65170e5e9 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 @@ -134,6 +136,11 @@ ErrCode NotificationDialogManager::OnBundleEnabledStatusChanged( case DialogStatus::REMOVE_BUNDLE: result = onRemoveBundle(bundleName, uid); break; +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + case DialogStatus::DIALOG_OPEN: + result = OnDialogOpen(bundleName, uid); + break; +#endif default: result = false; } @@ -284,6 +291,16 @@ bool NotificationDialogManager::onRemoveBundle(const std::string bundleName, con return true; } +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER +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); +} +#endif + bool NotificationDialogManager::HandleOneDialogClosed( sptr bundleOption, EnabledDialogStatus status) diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index 228d15d355d355b550fa96820a127572032710da..16c1605ec4b2d46ba5a1b02585c41fd416b4e2ca 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; @@ -48,6 +52,24 @@ 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()); +} + +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER +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); +} +#endif + #ifdef __cplusplus } #endif @@ -85,6 +107,16 @@ void ExtensionWrapper::InitExtentionWrapper() ANS_LOGE("extension wrapper modifyReminderFlags symbol failed, error: %{public}s", dlerror()); return; } + 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; + } #endif #ifdef ENABLE_ANS_AGGREGATION std::string aggregateConfig = NotificationPreferences::GetInstance()->GetAdditionalConfig("AGGREGATE_CONFIG"); @@ -191,6 +223,24 @@ bool ExtensionWrapper::ModifyReminderFlags(const sptr &requ } return modifyReminderFlags_(request); } + +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 &undleName, const int32_t &userId) +{ + if (setDialogOpenSuccessInfo_ == nullptr) { + ANS_LOGE("SetDialogOpenSuccessInfo wrapper symbol failed."); + return -1; + } + return setDialogOpenSuccessInfo_(bundleName, userId); +} #endif __attribute__((no_sanitize("cfi"))) int32_t ExtensionWrapper::LocalControl(const sptr &request) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 488a956cb122c106c6de5fc10255683b32b5303b..1b00247ec3ffcaa8eb28ab424ba4fbfcfe6b84bb 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -1268,6 +1268,17 @@ int32_t NotificationPreferences::GetByteFromDb( return preferncesDB_->GetByteFromDb(key, value, userId); } +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER +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); +} +#endif + int32_t NotificationPreferences::GetBatchKvsFromDb( const std::string &key, std::unordered_map &values, const int32_t &userId) { diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 81a380ec890ed5138f4c290492bf15249c671525..e9bc0f50bbc22199344aa8009064da22078f161a 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -1891,6 +1891,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) {