From 30347d74465a59c984db1809692fdf7b0851098b Mon Sep 17 00:00:00 2001 From: songbao1 Date: Thu, 22 Aug 2024 19:41:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BC=93=E5=AD=98=E5=92=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../moduletest/mock/mock_bundle_manager_helper.cpp | 5 +++++ services/ans/include/bundle_manager_helper.h | 9 +++++++++ .../ans/include/notification_preferences_database.h | 1 + .../src/advanced_notification_publish_service.cpp | 4 ++-- services/ans/src/bundle_manager_helper.cpp | 11 ++++++++--- .../ans/src/notification_preferences_database.cpp | 12 ++++++++++++ .../unittest/mock/mock_bundle_manager_helper.cpp | 5 +++++ 7 files changed, 42 insertions(+), 5 deletions(-) diff --git a/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp b/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp index 80609a098..e8c09b9b4 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 f4ecb94f3..ba9445671 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 a45cee1fa..633cb1406 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 bb5fafbdf..cbb79e370 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 e80541632..de9616557 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 501bf9e10..563a7478d 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