From 4c7f36ff10b448d8df84b305d8e43c51277dfb51 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Thu, 16 Sep 2021 21:53:11 +0800 Subject: [PATCH] fixed eaf720a from https://gitee.com/skyblackleon/notification_ans_standard/pulls/30 fix codex Signed-off-by: zhaoyuan17 --- .../ans/core/include/ans_manager_interface.h | 4 +-- .../ans/core/include/ans_manager_proxy.h | 4 +-- .../ans/core/include/ans_manager_stub.h | 5 +-- frameworks/ans/core/src/ans_manager_proxy.cpp | 4 +-- frameworks/ans/core/src/ans_manager_stub.cpp | 4 +-- .../native/include/notification_subscriber.h | 1 + .../include/advanced_notification_service.h | 4 +-- .../notification_preferences_database.h | 2 ++ .../ans/src/advanced_notification_service.cpp | 4 +-- .../src/notification_preferences_database.cpp | 34 +++++++++++++++++-- .../notification_preferences_test.cpp | 6 ++-- 11 files changed, 52 insertions(+), 20 deletions(-) diff --git a/frameworks/ans/core/include/ans_manager_interface.h b/frameworks/ans/core/include/ans_manager_interface.h index c6fe562d8..9f71a1a09 100644 --- a/frameworks/ans/core/include/ans_manager_interface.h +++ b/frameworks/ans/core/include/ans_manager_interface.h @@ -45,10 +45,10 @@ public: virtual ErrCode CancelAll() = 0; virtual ErrCode AddSlotByType(NotificationConstant::SlotType slotType) = 0; virtual ErrCode AddSlots(const std::vector> &slots) = 0; - virtual ErrCode RemoveSlotByType(NotificationConstant::SlotType slotType) = 0; + virtual ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) = 0; virtual ErrCode RemoveAllSlots() = 0; virtual ErrCode AddSlotGroups(std::vector> groups) = 0; - virtual ErrCode GetSlotByType(NotificationConstant::SlotType slotType, sptr &slot) = 0; + virtual ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) = 0; virtual ErrCode GetSlots(std::vector> &slots) = 0; virtual ErrCode GetSlotGroup(const std::string &groupId, sptr &group) = 0; virtual ErrCode GetSlotGroups(std::vector> &groups) = 0; diff --git a/frameworks/ans/core/include/ans_manager_proxy.h b/frameworks/ans/core/include/ans_manager_proxy.h index c09e7b818..80214ca52 100644 --- a/frameworks/ans/core/include/ans_manager_proxy.h +++ b/frameworks/ans/core/include/ans_manager_proxy.h @@ -34,10 +34,10 @@ public: ErrCode CancelAll() override; ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override; ErrCode AddSlots(const std::vector> &slots) override; - ErrCode RemoveSlotByType(NotificationConstant::SlotType slotType) override; + ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override; ErrCode RemoveAllSlots() override; ErrCode AddSlotGroups(std::vector> groups) override; - ErrCode GetSlotByType(NotificationConstant::SlotType slotType, sptr &slot) override; + ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) override; ErrCode GetSlots(std::vector> &slots) override; ErrCode GetSlotGroup(const std::string &groupId, sptr &group) override; ErrCode GetSlotGroups(std::vector> &groups) override; diff --git a/frameworks/ans/core/include/ans_manager_stub.h b/frameworks/ans/core/include/ans_manager_stub.h index 45006dc32..f85ab6050 100644 --- a/frameworks/ans/core/include/ans_manager_stub.h +++ b/frameworks/ans/core/include/ans_manager_stub.h @@ -40,10 +40,11 @@ public: virtual ErrCode CancelAll() override; virtual ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override; virtual ErrCode AddSlots(const std::vector> &slots) override; - virtual ErrCode RemoveSlotByType(NotificationConstant::SlotType slotType) override; + virtual ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override; virtual ErrCode RemoveAllSlots() override; virtual ErrCode AddSlotGroups(std::vector> groups) override; - virtual ErrCode GetSlotByType(NotificationConstant::SlotType slotType, sptr &slot) override; + virtual ErrCode GetSlotByType( + const NotificationConstant::SlotType &slotType, sptr &slot) override; virtual ErrCode GetSlots(std::vector> &slots) override; virtual ErrCode GetSlotGroup(const std::string &groupId, sptr &group) override; virtual ErrCode GetSlotGroups(std::vector> &groups) override; diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index c4e3742a9..ae493cd9d 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -235,7 +235,7 @@ ErrCode AnsManagerProxy::AddSlots(const std::vector> &slo return result; } -ErrCode AnsManagerProxy::RemoveSlotByType(NotificationConstant::SlotType slotType) +ErrCode AnsManagerProxy::RemoveSlotByType(const NotificationConstant::SlotType &slotType) { MessageParcel data; if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { @@ -328,7 +328,7 @@ ErrCode AnsManagerProxy::AddSlotGroups(std::vector> return result; } -ErrCode AnsManagerProxy::GetSlotByType(NotificationConstant::SlotType slotType, sptr &slot) +ErrCode AnsManagerProxy::GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) { MessageParcel data; if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 7f97ff1db..551024700 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -1241,7 +1241,7 @@ ErrCode AnsManagerStub::AddSlots(const std::vector> &slot return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RemoveSlotByType(NotificationConstant::SlotType slotType) +ErrCode AnsManagerStub::RemoveSlotByType(const NotificationConstant::SlotType &slotType) { ANS_LOGW("AnsManagerStub::RemoveSlotByType called!"); return ERR_INVALID_OPERATION; @@ -1259,7 +1259,7 @@ ErrCode AnsManagerStub::AddSlotGroups(std::vector> g return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::GetSlotByType(NotificationConstant::SlotType slotType, sptr &slot) +ErrCode AnsManagerStub::GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) { ANS_LOGW("AnsManagerStub::GetSlotByType called!"); return ERR_INVALID_OPERATION; diff --git a/interfaces/innerkits/ans/native/include/notification_subscriber.h b/interfaces/innerkits/ans/native/include/notification_subscriber.h index 7cbac600d..ebe13aac9 100644 --- a/interfaces/innerkits/ans/native/include/notification_subscriber.h +++ b/interfaces/innerkits/ans/native/include/notification_subscriber.h @@ -125,6 +125,7 @@ private: public: SubscriberImpl(NotificationSubscriber &subscriber); + ~SubscriberImpl(){}; void OnSubscribeResult(NotificationConstant::SubscribeResult result) override; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 60cfff6ba..ef5a068b1 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -50,10 +50,10 @@ public: ErrCode CancelAll() override; ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override; ErrCode AddSlots(const std::vector> &slots) override; - ErrCode RemoveSlotByType(const NotificationConstant::SlotType slotType) override; + ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override; ErrCode RemoveAllSlots() override; ErrCode AddSlotGroups(std::vector> groups) override; - ErrCode GetSlotByType(const NotificationConstant::SlotType slotType, sptr &slot) override; + ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr &slot) override; ErrCode GetSlots(std::vector> &slots) override; ErrCode GetSlotGroup(const std::string &groupId, sptr &group) override; ErrCode GetSlotGroups(std::vector> &groups) override; diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index ef1f360a7..b88bafbf2 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -87,6 +87,8 @@ private: std::string VectorToString(const std::vector &data) const; void StringToVector(const std::string &str, std::vector &data) const; int StringToInt(const std::string &str) const; + bool IsSlotKey(const std::string &bundleKey, const std::string &key) const; + bool IsGroupKey(const std::string &bundleKey, const std::string &key) const; std::string GenerateSlotKey( const std::string &bundleKey, const std::string &type = "", const std::string &subType = "") const; std::string GenerateGroupKey(const std::string &bundleKey, const std::string &subType = "") const; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 9305c21b5..56bf45d3c 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1025,7 +1025,7 @@ ErrCode AdvancedNotificationService::Unsubscribe( } ErrCode AdvancedNotificationService::GetSlotByType( - const NotificationConstant::SlotType slotType, sptr &slot) + const NotificationConstant::SlotType &slotType, sptr &slot) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -1040,7 +1040,7 @@ ErrCode AdvancedNotificationService::GetSlotByType( return result; } -ErrCode AdvancedNotificationService::RemoveSlotByType(const NotificationConstant::SlotType slotType) +ErrCode AdvancedNotificationService::RemoveSlotByType(const NotificationConstant::SlotType &slotType) { ANS_LOGD("%{public}s", __FUNCTION__); diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index c31741877..f46776fb7 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -833,9 +833,9 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( ANS_LOGD("Bundle key is %{public}s.", GenerateBundleKey(bundleKey).c_str()); NotificationPreferencesInfo::BundleInfo bunldeInfo; for (auto bundleEntry : bundleEntries) { - if (bundleEntry.key.ToString().find(KEY_SLOT) != std::string::npos) { + if (IsSlotKey(bundleKey, bundleEntry.key.ToString())) { ParseSlotFromDisturbeDB(bunldeInfo, bundleKey, bundleEntry); - } else if (bundleEntry.key.ToString().find(KEY_GROUP) != std::string::npos) { + } else if (IsGroupKey(bundleKey, bundleEntry.key.ToString())) { ParseGroupFromDisturbeDB(bunldeInfo, bundleKey, bundleEntry); } else { ParseBundlePropertyFromDisturbeDB(bunldeInfo, bundleKey, bundleEntry); @@ -962,6 +962,34 @@ int NotificationPreferencesDatabase::StringToInt(const std::string &str) const return value; } +bool NotificationPreferencesDatabase::IsSlotKey(const std::string &bundleKey, const std::string &key) const +{ + std::string tempStr = FindLastString(bundleKey, key); + size_t pos = tempStr.find_first_of(KEY_UNDER_LINE); + std::string slotStr; + if (pos != std::string::npos) { + slotStr = tempStr.substr(0, pos); + } + if (!slotStr.compare(KEY_SLOT)) { + return true; + } + return false; +} + +bool NotificationPreferencesDatabase::IsGroupKey(const std::string &bundleKey, const std::string &key) const +{ + std::string tempStr = FindLastString(bundleKey, key); + size_t pos = tempStr.find_first_of(KEY_UNDER_LINE); + std::string slotStr; + if (pos != std::string::npos) { + slotStr = tempStr.substr(0, pos); + } + if (!slotStr.compare(KEY_GROUP)) { + return true; + } + return false; +} + std::string NotificationPreferencesDatabase::GenerateSlotKey( const std::string &bundleKey, const std::string &type, const std::string &subType) const { @@ -1206,4 +1234,4 @@ void NotificationPreferencesDatabase::ParseSlotEnableBypassDnd( slot->EnableBypassDnd(enable); } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index 79f406980..510034cfa 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -843,7 +843,7 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00100, Function | SmallTest { int importance = 1; EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(bundleOption_, importance), (int)ERR_OK); - int getImportance; + int getImportance = 0;; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(bundleOption_, getImportance), (int)ERR_OK); EXPECT_EQ(getImportance, 1); @@ -856,7 +856,7 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00100, Function | SmallTest */ HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest | Level1) { - int getImportance; + int getImportance = 0;; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(bundleEmptyOption_, getImportance), (int)ERR_ANS_INVALID_PARAM); } @@ -905,7 +905,7 @@ HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00100, Function | SmallT */ HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00200, Function | SmallTest | Level1) { - int totalBadgeNum; + int totalBadgeNum = 0; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(bundleEmptyOption_, totalBadgeNum), (int)ERR_ANS_INVALID_PARAM); } -- Gitee