From e450de7083283a0d5b66b46cec417b330407927d Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Wed, 29 Sep 2021 18:39:20 +0000 Subject: [PATCH] fixed f2b9b5b from https://gitee.com/skyblackleon/notification_ans_standard/pulls/46 match type and level Signed-off-by: zhaoyuan --- .../ans/native/src/notification_slot.cpp | 21 +++++++++++++++++++ .../native/src/notification_slot_group.cpp | 14 ++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/native/src/notification_slot.cpp b/frameworks/ans/native/src/notification_slot.cpp index cf83dbca4..5c5748005 100644 --- a/frameworks/ans/native/src/notification_slot.cpp +++ b/frameworks/ans/native/src/notification_slot.cpp @@ -98,24 +98,28 @@ void NotificationSlot::SetType(NotificationConstant::SlotType type) SetName("SOCIAL_COMMUNICATION"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); SetEnableVibration(true); + SetLevel(LEVEL_HIGH); break; case NotificationConstant::SlotType::SERVICE_REMINDER: id_ = "SERVICE_REMINDER"; SetName("SERVICE_REMINDER"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); SetEnableVibration(true); + SetLevel(LEVEL_DEFAULT); break; case NotificationConstant::SlotType::CONTENT_INFORMATION: id_ = "CONTENT_INFORMATION"; SetName("CONTENT_INFORMATION"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::SECRET); SetEnableVibration(false); + SetLevel(LEVEL_LOW); break; case NotificationConstant::SlotType::OTHER: id_ = "OTHER"; SetName("OTHER"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::SECRET); SetEnableVibration(false); + SetLevel(LEVEL_MIN); break; default: break; @@ -214,67 +218,83 @@ std::string NotificationSlot::Dump() const bool NotificationSlot::Marshalling(Parcel &parcel) const { if (!parcel.WriteString(id_)) { + ANS_LOGE("Failed to write id"); return false; } if (!parcel.WriteString(name_)) { + ANS_LOGE("Failed to write name"); return false; } if (!parcel.WriteBool(isLightEnabled_)) { + ANS_LOGE("Failed to write isLightEnabled"); return false; } if (!parcel.WriteBool(isVibrationEnabled_)) { + ANS_LOGE("Failed to write isVibrationEnabled"); return false; } if (!parcel.WriteBool(isShowBadge_)) { + ANS_LOGE("Failed to write isShowBadge"); return false; } if (!parcel.WriteBool(isBypassDnd_)) { + ANS_LOGE("Failed to write isBypassDnd"); return false; } if (!parcel.WriteString(description_)) { + ANS_LOGE("Failed to write description"); return false; } if (!parcel.WriteInt32(lightColor_)) { + ANS_LOGE("Failed to write lightColor"); return false; } if (!parcel.WriteInt32(static_cast(level_))) { + ANS_LOGE("Failed to write level"); return false; } if (!parcel.WriteInt32(static_cast(type_))) { + ANS_LOGE("Failed to write type"); return false; } if (!parcel.WriteInt32(static_cast(lockScreenVisibleness_))) { + ANS_LOGE("Failed to write lockScreenVisibleness"); return false; } if (!parcel.WriteString(groupId_)) { + ANS_LOGE("Failed to write groupId"); return false; } if (sound_.ToString().empty()) { if (!parcel.WriteInt32(VALUE_NULL)) { + ANS_LOGE("Failed to write int"); return false; } } else { if (!parcel.WriteInt32(VALUE_OBJECT)) { + ANS_LOGE("Failed to write int"); return false; } if (!parcel.WriteString((sound_.ToString()))) { + ANS_LOGE("Failed to write sound"); return false; } } if (!parcel.WriteInt64Vector(vibrationValues_)) { + ANS_LOGE("Failed to write vibrationValues"); return false; } @@ -298,6 +318,7 @@ bool NotificationSlot::ReadFromParcel(Parcel &parcel) int empty = VALUE_NULL; if (!parcel.ReadInt32(empty)) { + ANS_LOGE("Failed to read int"); return false; } diff --git a/frameworks/ans/native/src/notification_slot_group.cpp b/frameworks/ans/native/src/notification_slot_group.cpp index 8146d3435..5f06ffc53 100644 --- a/frameworks/ans/native/src/notification_slot_group.cpp +++ b/frameworks/ans/native/src/notification_slot_group.cpp @@ -14,7 +14,7 @@ */ #include "notification_slot_group.h" - +#include "ans_log_wrapper.h" #include "string_ex.h" namespace OHOS { @@ -88,33 +88,40 @@ std::string NotificationSlotGroup::Dump() const bool NotificationSlotGroup::Marshalling(Parcel &parcel) const { if (!parcel.WriteString(id_)) { + ANS_LOGE("Failed to write id"); return false; } if (!parcel.WriteString(name_)) { + ANS_LOGE("Failed to write name"); return false; } if (!parcel.WriteString(description_)) { + ANS_LOGE("Failed to write description"); return false; } if (slots_.size() == 0) { if (!parcel.WriteInt32(0)) { + ANS_LOGE("Failed to write the size of slots"); return false; } } else { if (!parcel.WriteInt32(slots_.size())) { + ANS_LOGE("Failed to write the size of slots"); return false; } - for (auto it = slots_.begin(); it != slots_.end(); ++it) { - if (!it->Marshalling(parcel)) { + for (size_t it = 0; it < slots_.size(); ++it) { + if (!parcel.WriteParcelable(&slots_.at(it))) { + ANS_LOGE("Failed to write slots"); return false; } } } if (!parcel.WriteBool(isDisabled_)) { + ANS_LOGE("Failed to write isDisabled"); return false; } @@ -131,6 +138,7 @@ bool NotificationSlotGroup::ReadFromParcel(Parcel &parcel) for (int32_t i = 0; i < size; ++i) { auto slot = parcel.ReadParcelable(); if (nullptr == slot) { + ANS_LOGE("Failed to read slot"); return false; } slots_.emplace_back(*slot); -- Gitee