diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 3f1489e8a0d2ebea3439f33f5a7f519eaee29bdb..a35ad897c31b3f20e211da562cddbe7e77e05c56 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -1796,7 +1796,7 @@ ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, Messa NotificationConstant::SlotType slotType = static_cast(type); bool enabled = false; - ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ErrCode result = GetEnabledForBundleSlot(bundleOption, slotType, enabled); if (!reply.WriteInt32(result)) { ANS_LOGW("[HandleGetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index b7e0bdf8db709c8db896501dfa4e621b904136c8..3da864ac845906b5069ba533d9ec59e6ee623ae8 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -1638,7 +1638,7 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl } if (jsonObject.find("creatorUid") != jsonEnd) { - target->creatorUid_ = jsonObject.at("creatorUid").get(); + target->creatorUid_ = jsonObject.at("creatorUid").get(); } if (jsonObject.find("creatorPid") != jsonEnd) { diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp index 8dad0bdfd83ba6b40f700e8c8d73c30011872cb9..07139983f46b45fd3a35e0b7677ae5bead9d56dd 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -529,6 +529,7 @@ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 bool enable = true; NotificationBundleOption bo("bundleName", CALLING_UID); EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); + enable = false; EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); EXPECT_EQ(enable, true); @@ -549,6 +550,7 @@ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 bool enable = false; NotificationBundleOption bo("bundleName", CALLING_UID); EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + enable = true; EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); EXPECT_EQ(enable, false); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index d967168d3efa09712e9a2acce89e1d9b1763afd0..159369d2a6d58cac56dd250ddbcd31275a3cdb8f 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -219,7 +219,7 @@ ErrCode AdvancedNotificationService::PrepareNotificationRequest(const sptr bundleManager = BundleManagerHelper::GetInstance(); - uid_t uid = 0; + int32_t uid = -1; if (bundleManager != nullptr) { uid = bundleManager->GetDefaultUidByBundleName(request->GetOwnerBundleName(), request->GetOwnerUserId()); } @@ -406,7 +406,8 @@ ErrCode AdvancedNotificationService::PrepareNotificationInfo( } if (request->IsAgentNotification()) { - bundleOption = new NotificationBundleOption(request->GetOwnerBundleName(), request->GetOwnerUid()); + bundleOption = new (std::nothrow) NotificationBundleOption(request->GetOwnerBundleName(), + request->GetOwnerUid()); } else { bundleOption = GenerateBundleOption(); } @@ -628,7 +629,7 @@ ErrCode AdvancedNotificationService::CancelAsBundle( return ERR_ANS_PERMISSION_DENIED; } - uid_t uid = -1; + int32_t uid = -1; std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); if (bundleManager != nullptr) { uid = BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(representativeBundle, userId); @@ -636,7 +637,8 @@ ErrCode AdvancedNotificationService::CancelAsBundle( if (uid < 0) { return ERR_ANS_INVALID_UID; } - sptr bundleOption = new NotificationBundleOption(representativeBundle, uid); + sptr bundleOption = new (std::nothrow) NotificationBundleOption( + representativeBundle, uid); return CancelPreparedNotification(notificationId, "", bundleOption); } @@ -3450,7 +3452,7 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { sptr slot; - result = NotificationPreferences::GetInstance().GetNotificationSlot(bundleOption, slotType, slot); + result = NotificationPreferences::GetInstance().GetNotificationSlot(bundle, slotType, slot); if (result == ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST || result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { slot = new (std::nothrow) NotificationSlot(slotType); @@ -3463,7 +3465,7 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( if (slot->GetEnable() == enabled) { return; } - NotificationPreferences::GetInstance().RemoveNotificationSlot(bundleOption, slotType); + NotificationPreferences::GetInstance().RemoveNotificationSlot(bundle, slotType); } else { ANS_LOGE("Set enable slot: GetNotificationSlot failed"); return; @@ -3472,13 +3474,13 @@ ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( slot->SetEnable(enabled); std::vector> slots; slots.push_back(slot); - result = NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption, slots); + result = NotificationPreferences::GetInstance().AddNotificationSlots(bundle, slots); if (result != ERR_OK) { ANS_LOGE("Set enable slot: AddNotificationSlot failed"); return; } - PublishSlotChangeCommonEvent(bundleOption, slotType); + PublishSlotChangeCommonEvent(bundle, slotType); })); return result; } @@ -3504,7 +3506,7 @@ ErrCode AdvancedNotificationService::GetEnabledForBundleSlot( ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { sptr slot; - result = NotificationPreferences::GetInstance().GetNotificationSlot(bundleOption, slotType, slot); + result = NotificationPreferences::GetInstance().GetNotificationSlot(bundle, slotType, slot); if (result != ERR_OK) { ANS_LOGE("Get enable slot: GetNotificationSlot failed"); return; @@ -3533,7 +3535,7 @@ bool AdvancedNotificationService::PublishSlotChangeCommonEvent( want.SetParam("SlotType", slotType); want.SetAction("EventFwk::CommonEventSupport::COMMON_EVENT_SLOT_CHANGE"); EventFwk::CommonEventData commonData {want}; - if (EventFwk::CommonEventManager::PublishCommonEvent(commonData) != ERR_OK) { + if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData)) { ANS_LOGE("PublishCommonEvent failed"); return false; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index fde600c0f682b6e4a94607773eb00e30eb5f9cf8..a0e6e93a40b1e21ee433f0c7d50035eb727bc8ea 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -908,9 +908,9 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( ANS_LOGD("Bundle key is %{public}s.", GenerateBundleKey(bundleKey).c_str()); NotificationPreferencesInfo::BundleInfo bunldeInfo; for (auto bundleEntry : bundleEntries) { - if (IsSlotKey(bundleKey, bundleEntry.key.ToString())) { + if (IsSlotKey(GenerateBundleKey(bundleKey), bundleEntry.key.ToString())) { ParseSlotFromDisturbeDB(bunldeInfo, bundleKey, bundleEntry); - } else if (IsGroupKey(bundleKey, bundleEntry.key.ToString())) { + } else if (IsGroupKey(GenerateBundleKey(bundleKey), bundleEntry.key.ToString())) { ParseGroupFromDisturbeDB(bunldeInfo, bundleKey, bundleEntry); } else { ParseBundlePropertyFromDisturbeDB(bunldeInfo, bundleKey, bundleEntry);