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/interfaces/kits/napi/wantagent/napi_want_agent.cpp b/interfaces/kits/napi/wantagent/napi_want_agent.cpp index aeb4f5fc151ddcd2a100662b8d94f1ae8a0f31e0..3c8bf1e0e5f1202fd7404338cfe7598604b480d0 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.cpp +++ b/interfaces/kits/napi/wantagent/napi_want_agent.cpp @@ -589,28 +589,10 @@ napi_value NAPI_GetWant(napi_env env, napi_callback_info info) return ((callBackMode) ? (NapiGetNull(env)) : (ret)); } -void DeleteRecordByCode(const int32_t code) -{ - std::lock_guard guard(g_mutex); - for (const auto &item : g_WantAgentMap) { - auto code_ = item.second; - auto record = item.first; - if (code_ == code) { - g_WantAgentMap.erase(record); - if (record != nullptr) { - delete record; - record = nullptr; - } - } - } -} - auto NAPI_CancelWrapExecuteCallBack = [](napi_env env, void *data) { HILOG_INFO("Cancel called(CallBack Mode)..."); AsyncCancelCallbackInfo *asyncCallbackInfo = static_cast(data); - int32_t code = WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); WantAgentHelper::Cancel(asyncCallbackInfo->wantAgent); - DeleteRecordByCode(code); }; auto NAPI_CancelWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { @@ -1033,7 +1015,7 @@ auto NAPI_GetWantAgentWrapExecuteCallBack = [](napi_env env, void *data) { } int32_t code = Notification::WantAgent::WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); std::lock_guard guard(g_mutex); - g_WantAgentMap.emplace(asyncCallbackInfo, code); + g_WantAgentMap->emplace(asyncCallbackInfo, code); }; auto NAPI_GetWantAgentWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.h b/interfaces/kits/napi/wantagent/napi_want_agent.h index 9b92bc02b16d7f83fdea0e1f6974549afaa7deae..8c73f0d15dbde73c2291ac604addcc22989370cf 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.h +++ b/interfaces/kits/napi/wantagent/napi_want_agent.h @@ -178,8 +178,23 @@ napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info); napi_value GetCallbackErrorResult(napi_env env, int errCode); napi_value NapiGetNull(napi_env env); -void DeleteRecordByCode(const int32_t code); -static std::map g_WantAgentMap; +static void WantAgentDeleter(std::map *map) +{ + if (map == nullptr) { + return; + } + + for (auto &item : *map) { + if (item.first != nullptr) { + delete item.first; + } + } + map->clear(); + delete map; +} +static std::unique_ptr, + std::function *)>> + g_WantAgentMap(new std::map, WantAgentDeleter); static std::recursive_mutex g_mutex; } // namespace OHOS #endif // NAPI_WANT_AGENT_H 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; }