From d0828008cc3b206e86feef88730a7ea9025170dd Mon Sep 17 00:00:00 2001 From: z00454238 Date: Thu, 29 May 2025 15:33:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9overlay=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E5=BC=B9=E6=A1=86?= =?UTF-8?q?=E6=8F=90=E9=86=92=E6=9C=BA=E5=88=B6=20Signed-off-by:=20z004542?= =?UTF-8?q?38=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/ans/IAnsManager.idl | 2 + frameworks/ans/src/notification_request.cpp | 5 ++ frameworks/core/include/ans_image_util.h | 2 + frameworks/core/include/ans_notification.h | 8 +++ ..._notification_service_ipc_interface_code.h | 1 + frameworks/core/src/ans_image_util.cpp | 26 +++++++ frameworks/core/src/ans_notification.cpp | 19 ++++- .../unittest/ans_image_util_test/BUILD.gn | 3 +- .../ans_notification_branch_test.cpp | 5 ++ .../js/napi/src/manager/napi_sync_config.cpp | 3 +- interfaces/inner_api/notification_request.h | 8 ++- .../include/advanced_notification_service.h | 5 ++ .../ans/include/notification_config_parse.h | 2 + .../ans/include/notification_dialog_manager.h | 5 +- .../include/notification_extension_wrapper.h | 12 ++++ .../ans/include/notification_preferences.h | 3 + .../notification_preferences_database.h | 1 + services/ans/libans.map | 3 + .../advanced_notification_publish_service.cpp | 7 ++ .../src/common/notification_config_parse.cpp | 24 +++++++ .../ans/src/enable_manager/enable_manager.cpp | 19 +++-- .../ans/src/notification_dialog_manager.cpp | 17 +++++ .../src/notification_extension_wrapper.cpp | 70 +++++++++++++++++++ services/ans/src/notification_preferences.cpp | 11 +++ .../src/notification_preferences_database.cpp | 12 ++++ tools/test/mock/mock_ans_manager_stub.h | 5 ++ 26 files changed, 269 insertions(+), 9 deletions(-) diff --git a/frameworks/ans/IAnsManager.idl b/frameworks/ans/IAnsManager.idl index deb8d179d..4aad26fc3 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 de6a313a2..d3370c148 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 350bdd187..e87db2165 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 a9b33ef43..5b9060fda 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 1738c062c..787a3a29c 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 f5c2458bb..c9a450484 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 95c914fbb..3b2998198 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 ce61789ec..ef82e6858 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 981bebe51..70d38ff10 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 b023048fe..0959947da 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 4788f2fc6..94bfacde5 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 e8003e2db..2829068e5 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 77b9f7745..b8ba792a4 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 2b9d7d679..2239991a5 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 2620bd8c0..b8d3cf1f7 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 cfce6f59c..ec1dfc7e1 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 198e4af45..427f2ef8b 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 fde762ab0..7433ff4b7 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 11685b714..918387de0 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 1f28fe018..2863c12ed 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 b2e3a5d8e..7a5aa7677 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 2e2f4e23b..1634fb469 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 bf162c82c..c8405b6e1 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 63c514263..761cd7ba0 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 dc104ed8a..c4dbf4dc6 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 4552c1b49..3db722256 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_; -- Gitee