diff --git a/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp b/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp index 80609a098ce58685710f404b77d52614d26334c0..178cc27a452cf87e9d24fdee9c36874614d9f87e 100644 --- a/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp +++ b/frameworks/test/moduletest/mock/mock_bundle_manager_helper.cpp @@ -65,5 +65,10 @@ void BundleManagerHelper::Connect() void BundleManagerHelper::Disconnect() {} + +bool BundleManagerHelper::CheckApiCompatibility(const std::string &bundleName, const int32_t &uid) +{ + return true; +} } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index ea71a8b83916d264a4a5608a719e62f5207e93de..669694027a42f364f3d7a526d4ab48652f042cf9 100644 --- a/services/ans/include/bundle_manager_helper.h +++ b/services/ans/include/bundle_manager_helper.h @@ -108,6 +108,15 @@ public: bool GetBundleInfos( const AppExecFwk::BundleFlag flag, std::vector &bundleInfos, int32_t userId); + /** + * @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); + private: void Connect(); void Disconnect(); @@ -124,4 +133,4 @@ private: } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_BUNDLE_MANAGER_HELPER_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_BUNDLE_MANAGER_HELPER_H diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index aafa057b2ebe70baad8186d8586d407b0f2e0dc9..2c7b755dd87d72e2d2141bac78449a03ee674921 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 f30d7e6aee8c3c74f6d9e1ec1ca94b50d684dd53..03a1821ed96a177d011da0801e52a244c873ad1b 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -702,7 +702,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); @@ -728,7 +728,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 71ff872a248753bd5f6f1125252e8f8468033381..5ea086ca1496212c55b1dbf46c4ac35ef5894863 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -78,13 +78,22 @@ bool BundleManagerHelper::IsSystemApp(int32_t uid) } bool BundleManagerHelper::CheckApiCompatibility(const sptr &bundleOption) +{ + if (bundleOption == nullptr) { + ANS_LOGE("bundleOption is nullptr"); + return false; + } + 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 1b56290412a5c07d187a0641ecf76190673764bf..421ef1f5d89912aa969e35c99e1fa34472972244 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; } @@ -1978,5 +1980,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/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 5eb12e21859582ad47e153e2989fdad617c89486..e626898bfcd353089b2f80af4ddfdce8736d7db8 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -1014,6 +1014,7 @@ ohos_unittest("notification_preferences_database_branch_test") { ] sources = [ + "${services_path}/ans/src/bundle_manager_helper.cpp", "${services_path}/ans/src/common/notification_config_parse.cpp", "${services_path}/ans/src/notification_preferences_database.cpp", "${services_path}/ans/src/notification_preferences_info.cpp", 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..f03a0287d07c38f6797096e42109bd2897865f61 100644 --- a/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp +++ b/services/ans/test/unittest/mock/mock_bundle_manager_helper.cpp @@ -73,5 +73,10 @@ bool BundleManagerHelper::GetDistributedNotificationEnabled(const std::string &b return true; } #endif + +bool BundleManagerHelper::CheckApiCompatibility(const std::string &bundleName, const int32_t &uid) +{ + return true; +} } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/test/moduletest/mock/mock_bundle_manager_helper.cpp b/services/test/moduletest/mock/mock_bundle_manager_helper.cpp index 080c28ec373d34c42a69bb3bc304403ffabf923a..16c66878978cc80d97d56de510b971dc95adcfa9 100644 --- a/services/test/moduletest/mock/mock_bundle_manager_helper.cpp +++ b/services/test/moduletest/mock/mock_bundle_manager_helper.cpp @@ -65,5 +65,10 @@ void BundleManagerHelper::Connect() void BundleManagerHelper::Disconnect() {} + +bool BundleManagerHelper::CheckApiCompatibility(const std::string &bundleName, const int32_t &uid) +{ + return true; +} } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/bechmarktest/notification_services_test/mock/mock_bundle_manager_helper.cpp b/test/bechmarktest/notification_services_test/mock/mock_bundle_manager_helper.cpp index e0d31ddac910268673f2f3f4bbc8f0bed9c060d2..127129e1b0ab2b91b86edcd72a0b7c6b89b32f6a 100644 --- a/test/bechmarktest/notification_services_test/mock/mock_bundle_manager_helper.cpp +++ b/test/bechmarktest/notification_services_test/mock/mock_bundle_manager_helper.cpp @@ -68,5 +68,10 @@ bool BundleManagerHelper::GetDistributedNotificationEnabled(const std::string &b return true; } #endif + +bool BundleManagerHelper::CheckApiCompatibility(const std::string &bundleName, const int32_t &uid) +{ + return true; +} } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS