diff --git a/frameworks/ans/core/include/ans_manager_interface.h b/frameworks/ans/core/include/ans_manager_interface.h index c6fe562d80dc7d6b9ddf316751e6fd9b96387a8f..9f71a1a09577848b01d207cf34740fbe5d78ff1e 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 c09e7b81804c8426719dd6e103220f61f34c36ea..80214ca52d69ff6b41e7a4684657eb58f1c7449f 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 45006dc32a3a34982888f90198855d55f6448057..f85ab605042ceddcd5ed8e3a27b2b71cea86ba39 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 c4e3742a9bc37ea672e7410b41d401b836f8e692..ae493cd9da4650a7e9b8d16dc5557db6d359d2ce 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 7f97ff1db2d4c1ba6a4d381118140c5f52537c2b..55102470072ff600b6f2046ebacfe5222bb91235 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 7cbac600d704b5def985abae02a67d2467a2e523..ebe13aac993630a354e40f1d81bedf72bbd554a6 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 60cfff6ba1fd54de3d85271d73f571ceab7d550f..ef5a068b1d971c26339838723017af8f45915adf 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 ef1f360a741798d29e136cf7a949aeaec001a572..b88bafbf29173db024538d1b4ddceae2b9ee74da 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 9305c21b5b071f791f98fa911986d8214759c57b..56bf45d3c0ba54ef6ddbbd7969f4b363e2f6375e 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 c3174187713531793f068de0874487a091bc148d..f46776fb702e180c2027b57a8c5a7c28fcd20a27 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 79f4069800385a32e53f203b0a48932bb071865d..510034cfa2efa726b2df99dfa80dc76ba088f6e5 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); }