slot enable modify

Signed-off-by: fangJinliang1 <fangjinliang1@huawei.com>
Change-Id: Ice554eb8bec505e4642fcc1715d28d123fa4ec7b
Signed-off-by: fangJinliang1 <fangjinliang1@huawei.com>
This commit is contained in:
fangJinliang1
2022-05-11 20:52:56 +08:00
parent e2f3f46b57
commit 2dfe15259d
5 changed files with 18 additions and 14 deletions
+1 -1
View File
@@ -1796,7 +1796,7 @@ ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, Messa
NotificationConstant::SlotType slotType = static_cast<NotificationConstant::SlotType>(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;
@@ -1638,7 +1638,7 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl
}
if (jsonObject.find("creatorUid") != jsonEnd) {
target->creatorUid_ = jsonObject.at("creatorUid").get<int32_t>();
target->creatorUid_ = jsonObject.at("creatorUid").get<uint32_t>();
}
if (jsonObject.find("creatorPid") != jsonEnd) {
@@ -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);
@@ -219,7 +219,7 @@ ErrCode AdvancedNotificationService::PrepareNotificationRequest(const sptr<Notif
}
std::shared_ptr<BundleManagerHelper> 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<BundleManagerHelper> 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<NotificationBundleOption> bundleOption = new NotificationBundleOption(representativeBundle, uid);
sptr<NotificationBundleOption> 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<NotificationSlot> 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<sptr<NotificationSlot>> 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<NotificationSlot> 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;
}
@@ -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);