diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index 17bcd58326fdd0cfbb049482de22e1e8df942926..ace3fefc313e264d2d6b7f4a59d386602b4de402 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -120,6 +120,8 @@ public: static napi_value NapiGetNull(napi_env env); + static napi_value NapiGetUndefined(napi_env env); + static napi_value GetCallbackErrorValue(napi_env env, int errCode); static void PaddingCallbackPromiseInfo( diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index a73195283ec68cbcd0372cb6f69c3f8d7da7bd5a..45f69f2e8a33e14495e5cf8ced977de093cee4c2 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -98,6 +98,13 @@ napi_value Common::NapiGetNull(napi_env env) return result; } +napi_value Common::NapiGetUndefined(napi_env env) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + napi_value Common::GetCallbackErrorValue(napi_env env, int errCode) { napi_value result = nullptr; @@ -2824,6 +2831,9 @@ bool Common::ContentTypeJSToC(const enum ContentType &inType, enum NotificationC case ContentType::NOTIFICATION_CONTENT_MULTILINE: outType = NotificationContent::Type::MULTILINE; break; + case ContentType::NOTIFICATION_CONTENT_PICTURE: + outType = NotificationContent::Type::PICTURE; + break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; @@ -2843,6 +2853,9 @@ bool Common::ContentTypeCToJS(const enum NotificationContent::Type &inType, enum case NotificationContent::Type::MULTILINE: outType = ContentType::NOTIFICATION_CONTENT_MULTILINE; break; + case NotificationContent::Type::PICTURE: + outType = ContentType::NOTIFICATION_CONTENT_PICTURE; + break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index a73ec2d84a23ef0423967698c0793638b1167fd8..875112f77e009f61afabe4f21fd5427ad87944db 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1190,6 +1190,10 @@ ErrCode AdvancedNotificationService::IsSpecialBundleAllowedNotify( } } + if (targetBundle == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { allowed = false; diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index a937d90187c9d561067f420ecaac3374d79ce729..dc3ebcb9b7e32ff62def86d7468aab6312d15eff 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -41,7 +41,7 @@ ErrCode NotificationPreferences::AddNotificationSlots( { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty() || slots.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || slots.empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -67,7 +67,7 @@ ErrCode NotificationPreferences::AddNotificationSlotGroups( const sptr &bundleOption, const std::vector> &groups) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty() || groups.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || groups.empty()) { return ERR_ANS_INVALID_PARAM; } @@ -92,7 +92,7 @@ ErrCode NotificationPreferences::AddNotificationSlotGroups( ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr &bundleOption) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -113,7 +113,7 @@ ErrCode NotificationPreferences::RemoveNotificationSlot( const sptr &bundleOption, const NotificationConstant::SlotType &slotType) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -133,7 +133,7 @@ ErrCode NotificationPreferences::RemoveNotificationSlot( ErrCode NotificationPreferences::RemoveNotificationAllSlots(const sptr &bundleOption) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -159,7 +159,7 @@ ErrCode NotificationPreferences::RemoveNotificationSlotGroups( const sptr &bundleOption, const std::vector &groupIds) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty() || groupIds.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || groupIds.empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -183,7 +183,7 @@ ErrCode NotificationPreferences::RemoveNotificationSlotGroups( ErrCode NotificationPreferences::RemoveNotificationForBundle(const sptr &bundleOption) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -210,7 +210,7 @@ ErrCode NotificationPreferences::UpdateNotificationSlots( const sptr &bundleOption, const std::vector> &slots) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty() || slots.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || slots.empty()) { return ERR_ANS_INVALID_PARAM; } @@ -239,7 +239,7 @@ ErrCode NotificationPreferences::UpdateNotificationSlotGroups( { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty() || groups.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || groups.empty()) { return ERR_ANS_INVALID_PARAM; } @@ -266,7 +266,7 @@ ErrCode NotificationPreferences::GetNotificationSlot(const sptr &slot) { ANS_LOGD("%{public}s", __FUNCTION__); - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -286,7 +286,7 @@ ErrCode NotificationPreferences::GetNotificationSlot(const sptr &bundleOption, std::vector> &slots) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -305,7 +305,7 @@ ErrCode NotificationPreferences::GetNotificationAllSlots( ErrCode NotificationPreferences::GetNotificationSlotsNumForBundle( const sptr &bundleOption, int &num) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -322,7 +322,7 @@ ErrCode NotificationPreferences::GetNotificationSlotsNumForBundle( ErrCode NotificationPreferences::GetNotificationSlotGroup( const sptr &bundleOption, const std::string &groupId, sptr &group) { - if (bundleOption->GetBundleName().empty() || groupId.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || groupId.empty()) { return ERR_ANS_INVALID_PARAM; } @@ -342,7 +342,7 @@ ErrCode NotificationPreferences::GetNotificationSlotGroup( ErrCode NotificationPreferences::GetNotificationAllSlotGroups( const sptr &bundleOption, std::vector> &groups) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -360,7 +360,7 @@ ErrCode NotificationPreferences::GetNotificationAllSlotGroups( ErrCode NotificationPreferences::GetNotificationAllSlotInSlotGroup(const sptr &bundleOption, const std::string &groupId, std::vector> &slots) { - if (bundleOption->GetBundleName().empty() || groupId.empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || groupId.empty()) { return ERR_ANS_INVALID_PARAM; } @@ -377,7 +377,7 @@ ErrCode NotificationPreferences::GetNotificationAllSlotInSlotGroup(const sptr &bundleOption, bool &enable) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } return GetBundleProperty(bundleOption, BundleType::BUNDLE_SHOW_BADGE_TYPE, enable); @@ -385,7 +385,7 @@ ErrCode NotificationPreferences::IsShowBadge(const sptr &bundleOption, const bool enable) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -399,7 +399,7 @@ ErrCode NotificationPreferences::SetShowBadge(const sptr &bundleOption, int &importance) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -409,7 +409,7 @@ ErrCode NotificationPreferences::GetImportance(const sptr &bundleOption, const int &importance) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -423,7 +423,7 @@ ErrCode NotificationPreferences::SetImportance( ErrCode NotificationPreferences::GetTotalBadgeNums( const sptr &bundleOption, int &totalBadgeNum) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } return GetBundleProperty(bundleOption, BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE, totalBadgeNum); @@ -431,7 +431,7 @@ ErrCode NotificationPreferences::GetTotalBadgeNums( ErrCode NotificationPreferences::SetTotalBadgeNums(const sptr &bundleOption, const int num) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -445,7 +445,7 @@ ErrCode NotificationPreferences::SetTotalBadgeNums(const sptr &bundleOption, bool &allow) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } return GetBundleProperty(bundleOption, BundleType::BUNDLE_PRIVATE_ALLOWED_TYPE, allow); @@ -454,7 +454,7 @@ ErrCode NotificationPreferences::GetPrivateNotificationsAllowed( ErrCode NotificationPreferences::SetPrivateNotificationsAllowed( const sptr &bundleOption, const bool allow) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } NotificationPreferencesInfo preferencesInfo = preferencesInfo_; @@ -468,7 +468,7 @@ ErrCode NotificationPreferences::SetPrivateNotificationsAllowed( ErrCode NotificationPreferences::GetNotificationsEnabledForBundle( const sptr &bundleOption, bool &enabled) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } return GetBundleProperty(bundleOption, BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE, enabled); @@ -477,7 +477,7 @@ ErrCode NotificationPreferences::GetNotificationsEnabledForBundle( ErrCode NotificationPreferences::SetNotificationsEnabledForBundle( const sptr &bundleOption, const bool enabled) { - if (bundleOption->GetBundleName().empty()) { + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -535,15 +535,13 @@ ErrCode NotificationPreferences::SetDisturbMode(const NotificationConstant::Dist ErrCode NotificationPreferences::ClearNotificationInRestoreFactorySettings() { - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - preferencesInfo.ClearBundleInfo(); ErrCode result = ERR_OK; if (!preferncesDB_->RemoveAllDataFromDisturbeDB()) { result = ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } if (result == ERR_OK) { - preferencesInfo_ = preferencesInfo; + preferencesInfo_ = NotificationPreferencesInfo(); } return result; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 6064a270a3f2f8970596e0d69625babd5fc3ccdd..d9e16a85fef4f2eeeafe0a5f4a49e2f5c8e13dd6 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -956,7 +956,9 @@ void NotificationPreferencesDatabase::StringToVector(const std::string &str, std int NotificationPreferencesDatabase::StringToInt(const std::string &str) const { int value = 0; - value = stoi(str, nullptr); + if (!str.empty()) { + value = stoi(str, nullptr); + } return value; }