diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index deb8d179dc9a4a32cf47429e6a2f83156ac80bab..4aad26fc33ef2f811a8d5739df93f2a0c7a49c8e 100644 --- a/frameworks/ans/IAnsManager.idl +++ b/frameworks/ans/IAnsManager.idl @@ -295,4 +295,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_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 a9b33ef4303694fc77b55ad3ee9c4a5d9ad91108..5b9060fda73ad180ec047d9533b4dbe9d607732e 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -1287,6 +1287,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 1738c062cb69c5e410a8cf32299fb418ce5d8b22..787a3a29c7b822153c341db814fe3a4586a33a20 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..c9a4504842228d47b1fb1b2150ce5102c9af777d 100644 --- a/frameworks/core/src/ans_image_util.cpp +++ b/frameworks/core/src/ans_image_util.cpp @@ -16,6 +16,8 @@ #include "ans_log_wrapper.h" #include "image_packer.h" #include "image_source.h" +#include "ans_notification.h" +#include "singleton.h" namespace OHOS { namespace Notification { @@ -183,6 +185,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 = DelayedSingleton::GetInstance()->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 95c914fbb0f548aafcffb44d0934ddfa776e46b8..3b29981986d8492f862f527a5f3d92bbbd8202d7 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 @@ -1598,7 +1599,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(); @@ -2252,6 +2256,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/core/test/unittest/ans_image_util_test/BUILD.gn b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn index ce61789ec22b8cc9c956389a3f20bf481e92327a..ef82e6858a99bad6a7bcfc8a8d156356cf3f1f11 100644 --- a/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn @@ -23,6 +23,7 @@ ohos_unittest("ans_image_util_test") { include_dirs = [ "${core_path}/include", "${core_path}/common/include", + "${interfaces_path}/kits/native", "../mock", ] @@ -34,7 +35,7 @@ ohos_unittest("ans_image_util_test") { "ans_image_util_unit_test.cpp", ] - deps = [] + deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] external_deps = [ "ability_base:want", 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 981bebe5121e92d4a27f56efe7377e5bd9437fd1..70d38ff1003ea8f9867911d15fb4fe5a04d73622 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 @@ -680,6 +680,11 @@ public: { return ERR_ANS_INVALID_PARAM; } + + ErrCode GetOverlayIconScaleSize(uint32_t& scaleSize) + { + return ERR_ANS_INVALID_PARAM; + } }; class AnsNotificationBranchTest : public testing::Test { 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_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 e8003e2db5a3d54883b726339c83df31a9781824..2829068e5b19d28ccb728c0124eb7aba802aa5ef 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1287,6 +1287,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. @@ -1577,6 +1579,9 @@ private: void PublishSubscriberExistFlagEvent(bool headsetExistFlag, bool wearableExistFlag); void SetClassificationWithVoip(const sptr &request); void UpdateCollaborateTimerInfo(const std::shared_ptr &record); +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + void SetDialogPoppedUnEnableTime(const sptr &bundleOption); +#endif ErrCode CommonRequestEnableNotification(const std::string &deviceId, const sptr &callback, const sptr &callerToken, 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..2239991a5a3997b066e33a15128493213dea287e 100644 --- a/services/ans/include/notification_dialog_manager.h +++ b/services/ans/include/notification_dialog_manager.h @@ -39,7 +39,7 @@ enum class DialogStatus { DENY_CLICKED, DIALOG_CRASHED, DIALOG_SERVICE_DESTROYED, - REMOVE_BUNDLE + REMOVE_BUNDLE, }; class NotificationDialogEventSubscriber : public EventFwk::CommonEventSubscriber { @@ -131,6 +131,9 @@ private: bool HandleOneDialogClosed(sptr bundleOption, EnabledDialogStatus status); bool HandleAllDialogsClosed(); +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + void SetDialogPoppedTimeInterVal(const sptr &bundleOption); +#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 2620bd8c0d50d35bcbca52baba61c16a9df949c1..b8d3cf1f789b3c343158e379cd50fbb3ee98c164 100644 --- a/services/ans/include/notification_extension_wrapper.h +++ b/services/ans/include/notification_extension_wrapper.h @@ -46,6 +46,12 @@ public: #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER typedef bool (*MODIFY_REMINDER_FLAGS)(const sptr &request); + typedef bool (*GET_PRIVILEGE_DIALOG_POPPED)(const sptr& bundleOption, + const int32_t &userId); + typedef bool (*SET_DIALOG_OPENSUCCESS_TIMESTAMP)(const sptr& bundleOption, + const int32_t &userId); + typedef bool (*SET_DIALOG_OPENSUCCESS_TIMEINTERVAL)(const sptr& bundleOption, + const int32_t &userId); #endif ErrCode SyncAdditionConfig(const std::string& key, const std::string& value); @@ -62,6 +68,9 @@ public: #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER bool ModifyReminderFlags(const sptr &request); + bool GetPrivilegeDialogPopped(const sptr& bundleOption, const int32_t &userId); + bool SetDialogOpenSuccessTimeStamp(const sptr& bundleOption, const int32_t &userId); + bool SetDialogOpenSuccessTimeInterval(const sptr& bundleOption, const int32_t &userId); #endif private: @@ -82,6 +91,9 @@ private: #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER MODIFY_REMINDER_FLAGS modifyReminderFlags_ = nullptr; + GET_PRIVILEGE_DIALOG_POPPED getPrivilegeDialogPopped_ = nullptr; + SET_DIALOG_OPENSUCCESS_TIMESTAMP setDialogOpenSuccessTimeStamp_ = nullptr; + SET_DIALOG_OPENSUCCESS_TIMEINTERVAL setDialogOpenSuccessTimeInterval_ = nullptr; #endif }; diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index cfce6f59c81baba4dc87cd6c6551e955f6e70489..ec1dfc7e1d9b425df74e87621f0ac347a1169a07 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -404,6 +404,9 @@ public: int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId); int32_t GetBatchKvsFromDbContainsKey( const std::string &key, std::unordered_map &values, 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 198e4af45fa11dc80635d57f1360e2085fdd4432..427f2ef8beb0a0f960b6f091b65a782fb6ee3cb0 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 11685b714d5a19c67175f999fd835d85d3c6ca9e..918387de0ae56a725e26d146dcf33f541f34ddbc 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -1096,5 +1096,12 @@ ErrCode AdvancedNotificationService::SetHashCodeRule(const uint32_t type) return result; } + +ErrCode AdvancedNotificationService::GetOverlayIconScaleSize(uint32_t& scaleSize) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + scaleSize = NotificationConfigParse::GetInstance()->GetOverlayIconScaleSize(); + return ERR_OK; +} } // 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 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/enable_manager/enable_manager.cpp b/services/ans/src/enable_manager/enable_manager.cpp index b2e3a5d8ee90d27cb4e26f3624f3cf95b7c5f17f..7a5aa7677cb66d83c3746c01fbd38895031a36ec 100644 --- a/services/ans/src/enable_manager/enable_manager.cpp +++ b/services/ans/src/enable_manager/enable_manager.cpp @@ -138,10 +138,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().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); + if (!EXTENTION_WRAPPER->GetPrivilegeDialogPopped(bundleOption, 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 (!EXTENTION_WRAPPER->NotificationDialogControl()) { return ERR_ANS_NOT_ALLOWED; @@ -265,6 +273,9 @@ ErrCode AdvancedNotificationService::SetNotificationsEnabledForSpecialBundle( if (result == ERR_OK) { if (!enabled) { result = RemoveAllNotificationsForDisable(bundle); +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + SetDialogPoppedUnEnableTime(bundleOption); +#endif } SetSlotFlagsTrustlistsAsBundle(bundle); NotificationSubscriberManager::GetInstance()->NotifyEnabledNotificationChanged(bundleData); diff --git a/services/ans/src/notification_dialog_manager.cpp b/services/ans/src/notification_dialog_manager.cpp index 2e2f4e23bada6d5a88f003fe02d586d26d0f683f..1634fb469d4ecbbb8b8d0e6940706ea50dd5f9f0 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 @@ -240,6 +242,11 @@ bool NotificationDialogManager::OnDialogButtonClicked(const std::string& bundleN ErrCode result = ans_.SetNotificationsEnabledForSpecialBundle( NotificationDialogManager::DEFAULT_DEVICE_ID, bundleOption, enabled); +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + if (!enabled) { + SetDialogPoppedTimeInterVal(bundleOption); + } +#endif if (result != ERR_OK) { ANS_LOGE("SetNotificationsEnabledForSpecialBundle Failed, code is %{public}d", result); // Do not return here, need to clear the data @@ -313,4 +320,14 @@ bool NotificationDialogManager::HandleAllDialogsClosed() return true; } +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER +void NotificationDialogManager::SetDialogPoppedTimeInterVal(const sptr &bundleOption) +{ + ANS_LOGD("SetDialogPoppedTimeInterVal called."); + int32_t userId = SUBSCRIBE_USER_INIT; + OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); + EXTENTION_WRAPPER->SetDialogOpenSuccessTimeInterval(bundleOption, userId); + ANS_LOGD("SetDialogPoppedTimeInterVal end."); +} +#endif } // namespace OHOS::Notification diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index bf162c82c7e556a5cae878d0e957faf0b3f6ce70..c8405b6e181cad98243a7b298a1395612990050b 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,24 @@ 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; + } + setDialogOpenSuccessTimeStamp_ = + (SET_DIALOG_OPENSUCCESS_TIMESTAMP)dlsym(extensionWrapperHandle_, "SetDialogOpenSuccessTimeStamp"); + if (setDialogOpenSuccessTimeStamp_ == nullptr) { + ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); + return; + } + + setDialogOpenSuccessTimeInterval_ = + (SET_DIALOG_OPENSUCCESS_TIMEINTERVAL)dlsym(extensionWrapperHandle_, "SetDialogOpenSuccessTimeInterval"); + if (setDialogOpenSuccessTimeInterval_ == 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"); @@ -196,6 +236,36 @@ bool ExtensionWrapper::ModifyReminderFlags(const sptr &requ } return modifyReminderFlags_(request); } + +bool ExtensionWrapper::GetPrivilegeDialogPopped(const sptr& bundleOption, + const int32_t &userId) +{ + if (getPrivilegeDialogPopped_ == nullptr) { + ANS_LOGE("GetPrivilegeDialogPopped wrapper symbol failed."); + return -1; + } + return getPrivilegeDialogPopped_(bundleOption, userId); +} + +bool ExtensionWrapper::SetDialogOpenSuccessTimeStamp(const sptr& bundleOption, + const int32_t &userId) +{ + if (setDialogOpenSuccessTimeStamp_ == nullptr) { + ANS_LOGE("SetDialogOpenSuccessTimeStamp wrapper symbol failed."); + return -1; + } + return setDialogOpenSuccessTimeStamp_(bundleOption, userId); +} + +bool ExtensionWrapper::SetDialogOpenSuccessTimeInterval(const sptr& bundleOption, + const int32_t &userId) +{ + if (setDialogOpenSuccessTimeInterval_ == nullptr) { + ANS_LOGE("SetDialogOpenSuccessTimeInterval wrapper symbol failed."); + return -1; + } + return setDialogOpenSuccessTimeInterval_(bundleOption, 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 63c5142632a9c8ba6c6e622389c03d4d29b2dc55..761cd7ba0820ef7d9cb274009ace2ea75b9532bd 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -1277,6 +1277,17 @@ int32_t NotificationPreferences::GetBatchKvsFromDbContainsKey( return preferncesDB_->GetBatchKvsFromDbContainsKey(key, values, 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 dc104ed8afc0758bad6e3afa5e196cbc040799f1..c4dbf4dc692d0f0ebeceec62ec1424303377738c 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) { diff --git a/tools/test/mock/mock_ans_manager_stub.h b/tools/test/mock/mock_ans_manager_stub.h index 4552c1b49af14627b95a4521138fef814908fd84..3db72225618c62c9ce6b77ed21feb845317e58e3 100644 --- a/tools/test/mock/mock_ans_manager_stub.h +++ b/tools/test/mock/mock_ans_manager_stub.h @@ -662,6 +662,11 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode GetOverlayIconScaleSize(uint32_t &scaleSize) override + { + return ERR_ANS_INVALID_PARAM; + } + private: std::string cmd_; std::string bundle_;