diff --git a/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp b/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp index 80609a098ce58685710f404b77d52614d26334c0..e8c09b9b4acc2b93938c69cde614c9fa114607e5 100644 --- a/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp +++ b/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp @@ -60,6 +60,11 @@ bool BundleManagerHelper::CheckApiCompatibility(const sptr &bundleOption); + /** + * @brief Check API compatibility. + * + * @param bundleName Indicates the bundle name. + * @param uid Indicates the bundle uid. + * @return Returns the check result. + */ + bool CheckApiCompatibility(const std::string &bundleName, const int32_t &uid); + /** * @brief Obtains the default uid. * diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index f4ecb94f3d3dd78d88913968106e0004f3638477..ba94456711aea514fa4a81175328db79a0933bea 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -318,6 +318,7 @@ private: const std::string &findString, const int32_t &userId); void ExecuteDisturbeDB(sptr &slot, std::string &typeStr, std::string &valueStr, const std::string &findString, const int32_t &userId); + bool CheckApiCompatibility(const std::string &bundleName, const int32_t &uid); std::shared_ptr rdbDataManager_; }; } // namespace Notification diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index a45cee1faffea4176914501b3e6fcf5c65e015b6..633cb1406b574b4fb352098553e99fcd2966d668 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -722,7 +722,7 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabledForBundle( result = NotificationPreferences::GetInstance()->IsShowBadge(bundle, enabled); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; - enabled = false; + enabled = true; } })); notificationSvrQueue_->wait(handler); @@ -748,7 +748,7 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabled(bool &enabled) result = NotificationPreferences::GetInstance()->IsShowBadge(bundleOption, enabled); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { result = ERR_OK; - enabled = false; + enabled = true; } })); notificationSvrQueue_->wait(handler); diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index bb5fafbdfe82216e22678eb9914c31fa5465ba08..cbb79e370f8a1ecca9821e315feb982568459158 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -78,13 +78,18 @@ bool BundleManagerHelper::IsSystemApp(int32_t uid) } bool BundleManagerHelper::CheckApiCompatibility(const sptr &bundleOption) +{ + return CheckApiCompatibility(bundleOption->GetBundleName(), bundleOption->GetUid()); +} + +bool BundleManagerHelper::CheckApiCompatibility(const std::string &bundleName, const int32_t &uid) { AppExecFwk::BundleInfo bundleInfo; int32_t callingUserId; - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(bundleOption->GetUid(), callingUserId); - if (!GetBundleInfoByBundleName(bundleOption->GetBundleName(), callingUserId, bundleInfo)) { + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, callingUserId); + if (!GetBundleInfoByBundleName(bundleName, callingUserId, bundleInfo)) { ANS_LOGW("Failed to GetBundleInfoByBundleName, bundlename = %{public}s", - bundleOption->GetBundleName().c_str()); + bundleName.c_str()); return false; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index e805416323a5d21b30a5128c91d78ddb532e94e8..de9616557586883d740d7bce5e236a880465b7ee 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -25,6 +25,7 @@ #include "hitrace_meter_adapter.h" #include "os_account_manager.h" #include "ipc_skeleton.h" +#include "bundle_manager_helper.h" #include "uri.h" namespace OHOS { @@ -595,6 +596,7 @@ bool NotificationPreferencesDatabase::CheckBundle(const std::string &bundleName, NotificationPreferencesInfo::BundleInfo bundleInfo; bundleInfo.SetBundleName(bundleName); bundleInfo.SetBundleUid(bundleUid); + bundleInfo.SetEnableNotification(CheckApiCompatibility(bundleName, bundleUid)); result = PutBundleToDisturbeDB(bundleKeyStr, bundleInfo); break; } @@ -1973,5 +1975,15 @@ std::string NotificationPreferencesDatabase::GetAdditionalConfig(const std::stri ANS_LOGD("The additional config key is :%{public}s, value is :%{public}s.", key.c_str(), configValue.c_str()); return configValue; } + +bool NotificationPreferencesDatabase::CheckApiCompatibility(const std::string &bundleName, const int32_t &uid) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); + if (bundleManager == nullptr) { + return false; + } + return bundleManager->CheckApiCompatibility(bundleName, uid); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp index 501bf9e10e714341be801df9b7bd77e372f5021a..563a7478d88e5c6fa324399ec94d3e0fa7f5e791 100644 --- a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp +++ b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp @@ -55,6 +55,11 @@ bool BundleManagerHelper::CheckApiCompatibility(const sptr