From 2276a7261252a8a3d0eec2501cda376ec7404402 Mon Sep 17 00:00:00 2001 From: Ricky Date: Wed, 22 Jan 2025 16:22:51 +0800 Subject: [PATCH] support ipc max capacity is 100MB Signed-off-by: Ricky Change-Id: I05c55e4c7a9f057c9570ade07c1f2a60d6debb06 --- .../common/include/ans_ipc_common_utils.h | 212 ++++++++++++++++++ .../core/include/ans_subscriber_proxy.h | 19 +- frameworks/core/include/ans_subscriber_stub.h | 5 +- .../src/listener/ans_subscriber_proxy.cpp | 26 +-- .../core/src/listener/ans_subscriber_stub.cpp | 39 +--- .../core/src/manager/ans_manager_proxy.cpp | 55 ++--- .../core/src/manager/ans_manager_stub.cpp | 35 +-- .../ans_subscriber_proxy_branch_test.cpp | 42 +--- .../ans_subscriber_stub_unit_test.cpp | 6 - interfaces/inner_api/notification_constant.h | 8 +- services/ans/src/ans_manager_stub.cpp | 36 +-- 11 files changed, 301 insertions(+), 182 deletions(-) create mode 100644 frameworks/core/common/include/ans_ipc_common_utils.h diff --git a/frameworks/core/common/include/ans_ipc_common_utils.h b/frameworks/core/common/include/ans_ipc_common_utils.h new file mode 100644 index 000000000..4254a6f6e --- /dev/null +++ b/frameworks/core/common/include/ans_ipc_common_utils.h @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_CORE_IPC_COMMON_UTILS_H +#define BASE_NOTIFICATION_ANS_STANDARD_CORE_IPC_COMMON_UTILS_H + +#include + +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" +#include "iremote_broker.h" +#include "notification_constant.h" + +namespace OHOS { +namespace Notification { +static bool GetDataFromRawData(void *&buffer, size_t size, const void *data) +{ + if (data == nullptr) { + ANS_LOGE("GetData failed due to null data"); + return false; + } + if (size == 0 || size > NotificationConstant::NOTIFICATION_MAX_RAW_DATA_SIZE) { + ANS_LOGE("GetData failed due to zero size"); + return false; + } + buffer = malloc(size); + if (buffer == nullptr) { + ANS_LOGE("GetData failed due to malloc buffer failed"); + return false; + } + if (memcpy_s(buffer, size, data, size) != ERR_OK) { + free(buffer); + ANS_LOGE("GetData failed due to memcpy_s failed"); + return false; + } + return true; +} + +template +bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) +{ + if (!data.WriteInt32(parcelableVector.size())) { + ANS_LOGE("Failed to write ParcelableVector size."); + return false; + } + + for (auto &parcelable : parcelableVector) { + if (!data.WriteStrongParcelable(parcelable)) { + ANS_LOGE("Failed to write ParcelableVector"); + return false; + } + } + return true; +} + +template +bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) +{ + int32_t infoSize = 0; + if (!data.ReadInt32(infoSize)) { + ANS_LOGE("Failed to read Parcelable size."); + return false; + } + + parcelableInfos.clear(); + infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; + for (int32_t index = 0; index < infoSize; index++) { + sptr info = data.ReadStrongParcelable(); + if (info == nullptr) { + ANS_LOGE("Failed to read Parcelable infos."); + return false; + } + parcelableInfos.emplace_back(info); + } + + return true; +} + +static bool WriteParcelableIntoIPC(MessageParcel &data, MessageParcel &newData) +{ + data.PrintBuffer(__FUNCTION__, __LINE__); + size_t dataSize = data.GetDataSize(); + if (dataSize > NotificationConstant::NOTIFICATION_MAX_RAW_DATA_SIZE) { + ANS_LOGE("data is too large, cannot write!"); + return false; + } + if (!newData.WriteUint32(static_cast(dataSize))) { + ANS_LOGE("write dataSize failed"); + return false; + } + binder_size_t *objectOffsets = reinterpret_cast(data.GetObjectOffsets()); + std::vector offsets(objectOffsets, objectOffsets + data.GetOffsetsSize()); + if (!newData.WriteUInt64Vector(offsets)) { + ANS_LOGE("write offsets failed"); + return false; + } + if (!newData.WriteRawData(reinterpret_cast(data.GetData()), dataSize)) { + ANS_LOGE("write WriteRawData failed"); + return false; + } + + return true; +} + +static bool ReadParcelableFromIPC(MessageParcel &reply, MessageParcel &newReply) +{ + uint32_t dataSize = reply.ReadUint32(); + void *buffer = nullptr; + if (dataSize > NotificationConstant::NOTIFICATION_MAX_RAW_DATA_SIZE) { + ANS_LOGE("data is too large, cannot read!"); + return false; + } + std::vector offsets; + if (!reply.ReadUInt64Vector(&offsets)) { + ANS_LOGE("read offsets failed"); + return false; + } + if (!GetDataFromRawData(buffer, dataSize, reply.ReadRawData(dataSize))) { + ANS_LOGE("GetDataFromRawData failed dataSize : %{public}u", dataSize); + return false; + } + if (!newReply.ParseFrom(reinterpret_cast(buffer), dataSize)) { + free(buffer); + buffer = nullptr; + ANS_LOGE("ParseFrom failed"); + return false; + } + if (offsets.size() > 0) { + binder_size_t offsetsArr[offsets.size()]; + std::copy(offsets.begin(), offsets.end(), offsetsArr); + newReply.InjectOffsets(reinterpret_cast(offsetsArr), offsets.size()); + } + newReply.PrintBuffer(__FUNCTION__, __LINE__); + return true; +} + +template +static bool WriteLargeInfoIntoParcelable(MessageParcel &data, const sptr info, uint64_t maxSize) +{ + MessageParcel tempParcel; + tempParcel.SetMaxCapacity(maxSize); + if (!tempParcel.WriteStrongParcelable(info)) { + ANS_LOGE("Write info failed."); + return false; + } + if (!WriteParcelableIntoIPC(tempParcel, data)) { + return false; + } + return true; +} + +template +static bool WriteLargeInfoIntoParcelable(MessageParcel &data, const std::vector> &info, uint64_t maxSize) +{ + MessageParcel tempParcel; + tempParcel.SetMaxCapacity(maxSize); + if (!WriteParcelableVector(info, tempParcel)) { + ANS_LOGE("Write info into parcel failed."); + return false; + } + if (!WriteParcelableIntoIPC(tempParcel, data)) { + return false; + } + return true; +} + +template +static bool ReadLargeInfoFromParcelable(MessageParcel &data, sptr &info, uint64_t maxSize) +{ + MessageParcel tempParcel; + tempParcel.SetMaxCapacity(maxSize); + if (!ReadParcelableFromIPC(data, tempParcel)) { + return false; + } + info = tempParcel.ReadStrongParcelable(); + if (info == nullptr) { + ANS_LOGE("Read info from parcel failed"); + return false; + } + return true; +} + +template +static bool ReadLargeInfoFromParcelable(MessageParcel &data, std::vector> &info, uint64_t maxSize) +{ + MessageParcel tempParcel; + tempParcel.SetMaxCapacity(maxSize); + if (!ReadParcelableFromIPC(data, tempParcel)) { + return false; + } + if (!ReadParcelableVector(info, tempParcel)) { + ANS_LOGE("Read info from parcel failed"); + return false; + } + return true; +} +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_CORE_IPC_COMMON_UTILS_H diff --git a/frameworks/core/include/ans_subscriber_proxy.h b/frameworks/core/include/ans_subscriber_proxy.h index 435e0fb53..3ce35e4e3 100644 --- a/frameworks/core/include/ans_subscriber_proxy.h +++ b/frameworks/core/include/ans_subscriber_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -111,23 +111,6 @@ private: ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; - - template - bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) - { - if (!data.WriteInt32(parcelableVector.size())) { - ANS_LOGE("write ParcelableVector size failed"); - return false; - } - - for (auto &parcelable : parcelableVector) { - if (!data.WriteStrongParcelable(parcelable)) { - ANS_LOGE("write ParcelableVector failed"); - return false; - } - } - return true; - } }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/include/ans_subscriber_stub.h b/frameworks/core/include/ans_subscriber_stub.h index 35906d3b5..dc18a5de4 100644 --- a/frameworks/core/include/ans_subscriber_stub.h +++ b/frameworks/core/include/ans_subscriber_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -133,9 +133,6 @@ private: ErrCode HandleOnBadgeEnabledChanged(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnApplicationInfoNeedChanged(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnResponse(MessageParcel &data, MessageParcel &reply); - - template - bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data); }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/listener/ans_subscriber_proxy.cpp b/frameworks/core/src/listener/ans_subscriber_proxy.cpp index 77a3bdd4d..7ac6cf0c7 100644 --- a/frameworks/core/src/listener/ans_subscriber_proxy.cpp +++ b/frameworks/core/src/listener/ans_subscriber_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,7 @@ #include "ans_subscriber_proxy.h" #include "ans_inner_errors.h" +#include "ans_ipc_common_utils.h" #include "ans_log_wrapper.h" #include "message_option.h" #include "message_parcel.h" @@ -96,18 +97,12 @@ void AnsSubscriberProxy::OnConsumed( } MessageParcel data; - if (notification->GetNotificationRequestPoint()->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnConsumed] fail: set max capacity failed."); - return; - } - } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnConsumed] fail: write interface token failed."); return; } - if (!data.WriteParcelable(notification)) { + if (!WriteLargeInfoIntoParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[OnConsumed] fail: write notification failed."); return; } @@ -143,15 +138,12 @@ void AnsSubscriberProxy::OnConsumedList(const std::vector> &n } MessageParcel data; - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnConsumedList] fail: set max capacity failed."); - } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("Write interface token failed."); return; } - if (!WriteParcelableVector(notifications, data)) { + if (!WriteLargeInfoIntoParcelable(data, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("Write notifications failed"); return; } @@ -186,18 +178,12 @@ void AnsSubscriberProxy::OnCanceled( } MessageParcel data; - if (notification->GetNotificationRequestPoint()->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - ANS_LOGE("[OnCanceled] fail: set max capacity failed."); - return; - } - } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnCanceled] fail: write interface token failed."); return; } - if (!data.WriteParcelable(notification)) { + if (!WriteLargeInfoIntoParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[OnCanceled] fail: write notification failed."); return; } @@ -248,7 +234,7 @@ void AnsSubscriberProxy::OnCanceledList(const std::vector> &n notification->GetNotificationRequestPoint()->SetLittleIcon(nullptr); notification->GetNotificationRequestPoint()->SetOverlayIcon(nullptr); } - if (!WriteParcelableVector(notifications, data)) { + if (!WriteLargeInfoIntoParcelable(data, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("Write notifications failed"); return; } diff --git a/frameworks/core/src/listener/ans_subscriber_stub.cpp b/frameworks/core/src/listener/ans_subscriber_stub.cpp index 4381035a3..420815874 100644 --- a/frameworks/core/src/listener/ans_subscriber_stub.cpp +++ b/frameworks/core/src/listener/ans_subscriber_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" +#include "ans_ipc_common_utils.h" #include "ans_log_wrapper.h" #include "message_option.h" #include "message_parcel.h" @@ -113,8 +114,8 @@ ErrCode AnsSubscriberStub::HandleOnDisconnected(MessageParcel &data, MessageParc ErrCode AnsSubscriberStub::HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply) { - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGW("[HandleOnConsumedMap] fail: notification ReadParcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -143,7 +144,7 @@ ErrCode AnsSubscriberStub::HandleOnConsumedListMap(MessageParcel &data, MessageP ANS_LOGD("Start handle notifications in consumed list."); std::vector> notifications; - if (!ReadParcelableVector(notifications, data)) { + if (!ReadLargeInfoFromParcelable(data, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("read notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -169,8 +170,8 @@ ErrCode AnsSubscriberStub::HandleOnConsumedListMap(MessageParcel &data, MessageP ErrCode AnsSubscriberStub::HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply) { - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGW("[HandleOnCanceledMap] fail: notification ReadParcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -204,7 +205,7 @@ ErrCode AnsSubscriberStub::HandleOnCanceledMap(MessageParcel &data, MessageParce ErrCode AnsSubscriberStub::HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply) { std::vector> notifications; - if (!ReadParcelableVector(notifications, data)) { + if (!ReadLargeInfoFromParcelable(data, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("read notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -234,30 +235,6 @@ ErrCode AnsSubscriberStub::HandleOnCanceledListMap(MessageParcel &data, MessageP return ERR_OK; } - -template -bool AnsSubscriberStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) -{ - int32_t infoSize = 0; - if (!data.ReadInt32(infoSize)) { - ANS_LOGE("read Parcelable size failed."); - return false; - } - - parcelableInfos.clear(); - infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; - for (int32_t index = 0; index < infoSize; index++) { - sptr info = data.ReadStrongParcelable(); - if (info == nullptr) { - ANS_LOGE("read Parcelable infos failed."); - return false; - } - parcelableInfos.emplace_back(info); - } - - return true; -} - ErrCode AnsSubscriberStub::HandleOnUpdated(MessageParcel &data, MessageParcel &reply) { sptr notificationMap = data.ReadParcelable(); diff --git a/frameworks/core/src/manager/ans_manager_proxy.cpp b/frameworks/core/src/manager/ans_manager_proxy.cpp index 07aad5681..d47f37468 100644 --- a/frameworks/core/src/manager/ans_manager_proxy.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy.cpp @@ -17,6 +17,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" +#include "ans_ipc_common_utils.h" #include "ans_log_wrapper.h" #include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" @@ -42,11 +43,6 @@ ErrCode AnsManagerProxy::Publish(const std::string &label, const sptrGetAppInstanceKey().c_str()); MessageParcel data; - if (notification->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - return ERR_ANS_PARCELABLE_FAILED; - } - } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[Publish] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; @@ -56,12 +52,11 @@ ErrCode AnsManagerProxy::Publish(const std::string &label, const sptr(data, notification, + NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[Publish] fail: write notification parcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } - MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_NOTIFICATION, option, data, reply); @@ -86,17 +81,12 @@ ErrCode AnsManagerProxy::PublishNotificationForIndirectProxy(const sptrGetAppInstanceKey().c_str()); MessageParcel data; - if (notification->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - return ERR_ANS_PARCELABLE_FAILED; - } - } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[PublishNotificationForIndirectProxy] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; } - if (!data.WriteParcelable(notification)) { + if (!WriteLargeInfoIntoParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[PublishNotificationForIndirectProxy] fail: write notification parcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -320,8 +310,11 @@ ErrCode AnsManagerProxy::GetActiveNotifications( ANS_LOGE("[GetActiveNotifications] fail: transact ErrCode=%{public}d", result); return ERR_ANS_TRANSACT_FAILED; } - - if (!ReadParcelableVector(notifications, reply, result)) { + if (!reply.ReadInt32(result)) { + ANS_LOGE("read result failed."); + return false; + } + if (!ReadLargeInfoFromParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[GetActiveNotifications] fail: read notifications failed."); return ERR_ANS_PARCELABLE_FAILED; } @@ -367,18 +360,18 @@ ErrCode AnsManagerProxy::GetAllActiveNotifications(std::vector(); - if (request == nullptr) { + if (!ReadLargeInfoFromParcelable(reply, request, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[GetActiveNotificationByFilter] fail: read request is nullptr."); } @@ -534,17 +526,12 @@ ErrCode AnsManagerProxy::PublishAsBundle( } MessageParcel data; - if (notification->IsCommonLiveView()) { - if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - return ERR_ANS_PARCELABLE_FAILED; - } - } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[PublishAsBundle] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; } - if (!data.WriteParcelable(notification)) { + if (!WriteLargeInfoIntoParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[PublishAsBundle] fail: write notification failed."); return ERR_ANS_PARCELABLE_FAILED; } diff --git a/frameworks/core/src/manager/ans_manager_stub.cpp b/frameworks/core/src/manager/ans_manager_stub.cpp index 19f1826a0..fc0ac05a2 100644 --- a/frameworks/core/src/manager/ans_manager_stub.cpp +++ b/frameworks/core/src/manager/ans_manager_stub.cpp @@ -16,6 +16,7 @@ #include "ans_manager_stub.h" #include "ans_const_define.h" #include "ans_inner_errors.h" +#include "ans_ipc_common_utils.h" #include "ans_log_wrapper.h" #include "ans_subscriber_local_live_view_interface.h" #include "message_option.h" @@ -482,8 +483,8 @@ ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply) return ERR_ANS_PARCELABLE_FAILED; } - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandlePublish] fail: notification ReadParcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -498,8 +499,8 @@ ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply) ErrCode AnsManagerStub::HandlePublishNotificationForIndirectProxy(MessageParcel &data, MessageParcel &reply) { - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandlePublishNotificationForIndirectProxy] fail: notification ReadParcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -785,7 +786,11 @@ ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, Messag } std::vector> notifications; ErrCode result = GetActiveNotifications(notifications, appInstanceKey); - if (!WriteParcelableVector(notifications, reply, result)) { + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; + } + if (!WriteLargeInfoIntoParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[HandleGetActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -812,11 +817,11 @@ ErrCode AnsManagerStub::HandleGetAllActiveNotifications(MessageParcel &data, Mes { std::vector> notifications; ErrCode result = GetAllActiveNotifications(notifications); - - if (!reply.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - return ERR_ANS_PARCELABLE_FAILED; + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; } - if (!WriteParcelableVector(notifications, reply, result)) { + if (!WriteLargeInfoIntoParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[HandleGetAllActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -833,7 +838,11 @@ ErrCode AnsManagerStub::HandleGetSpecialActiveNotifications(MessageParcel &data, std::vector> notifications; ErrCode result = GetSpecialActiveNotifications(key, notifications); - if (!WriteParcelableVector(notifications, reply, result)) { + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; + } + if (!WriteLargeInfoIntoParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -873,7 +882,7 @@ ErrCode AnsManagerStub::HandleGetActiveNotificationByFilter(MessageParcel &data, return ERR_ANS_PARCELABLE_FAILED; } - if (!reply.WriteParcelable(request)) { + if (!WriteLargeInfoIntoParcelable(reply, request, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -905,8 +914,8 @@ ErrCode AnsManagerStub::HandleCanPublishAsBundle(MessageParcel &data, MessagePar ErrCode AnsManagerStub::HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply) { - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandlePublishAsBundle] fail: read notification failed"); return ERR_ANS_PARCELABLE_FAILED; } diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp index 831ecb7c3..83d91b8c1 100755 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/ans_subscriber_proxy_branch_test.cpp @@ -120,44 +120,4 @@ HWTEST_F(AnsSubscriberProxyBranchTest, OnCanceledList_0300, Function | MediumTes sptr notificationMap = new (std::nothrow) NotificationSortingMap(); int32_t deleteReason = 1; proxy->OnCanceledList(notifications, notificationMap, deleteReason); -} - -/* - * @tc.name: WriteParcelableVector_0100 - * @tc.desc: Test WriteParcelableVector function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, WriteParcelableVector_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, WriteParcelableVector_0100, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - std::vector> notifications; - MessageParcel data; - proxy->WriteParcelableVector(notifications, data); -} - -/* - * @tc.name: WriteParcelableVector_0200 - * @tc.desc: Test WriteParcelableVector function - * @tc.type: FUNC - * @tc.require: #I5SJ62 - */ -HWTEST_F(AnsSubscriberProxyBranchTest, WriteParcelableVector_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsSubscriberProxyBranchTest, WriteParcelableVector_0200, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); - std::vector> notifications; - notifications.emplace_back(notification); - MessageParcel data; - proxy->WriteParcelableVector(notifications, data); -} +} \ No newline at end of file diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp index 15493b1fb..708d80059 100644 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp @@ -255,8 +255,6 @@ HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap02, Function | SmallT ASSERT_NE(nullptr, remoteObject); std::shared_ptr proxy = std::make_shared(remoteObject); ASSERT_NE(nullptr, proxy); - bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); - EXPECT_EQ(isWriteNotificationsSucc, true); ErrCode res = stub_->HandleOnConsumedListMap(data, reply); EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); @@ -280,8 +278,6 @@ HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap03, Function | SmallT ASSERT_NE(nullptr, remoteObject); std::shared_ptr proxy = std::make_shared(remoteObject); ASSERT_NE(nullptr, proxy); - bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); - EXPECT_EQ(isWriteNotificationsSucc, true); bool existMap = true; data.WriteBool(existMap); @@ -308,8 +304,6 @@ HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap04, Function | SmallT ASSERT_NE(nullptr, remoteObject); std::shared_ptr proxy = std::make_shared(remoteObject); ASSERT_NE(nullptr, proxy); - bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); - EXPECT_EQ(isWriteNotificationsSucc, true); bool existMap = true; data.WriteBool(existMap); diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 8e6bfb2de..26fb80bbd 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -344,8 +344,12 @@ public: static constexpr uint64_t INVALID_TIMER_ID = 0ULL; - // live view max size is 512KB(extra size) + 8KB(base size) = 520KB - static constexpr uint64_t NOTIFICATION_MAX_LIVE_VIEW_SIZE = 520ULL * 1024ULL; + // live view max size is 1MB + static constexpr uint64_t NOTIFICATION_MAX_LIVE_VIEW_SIZE = 1ULL * 1024ULL * 1024ULL; + // ans message parcel max data size is 100MB + static constexpr uint64_t NOTIFICATION_MAX_DATA_SIZE = 100ULL * 1024ULL * 1024ULL; + // IPC raw data max size is 120MB + static constexpr uint64_t NOTIFICATION_MAX_RAW_DATA_SIZE = 120ULL * 1024ULL * 1014ULL; // rdb constexpr static const char* NOTIFICATION_RDB_NAME = "/notificationdb.db"; diff --git a/services/ans/src/ans_manager_stub.cpp b/services/ans/src/ans_manager_stub.cpp index 6efd6ad7e..a21f867e2 100644 --- a/services/ans/src/ans_manager_stub.cpp +++ b/services/ans/src/ans_manager_stub.cpp @@ -16,6 +16,7 @@ #include "ans_manager_stub.h" #include "ans_const_define.h" #include "ans_inner_errors.h" +#include "ans_ipc_common_utils.h" #include "ans_log_wrapper.h" #include "ans_subscriber_local_live_view_interface.h" #include "disturb_manager.h" @@ -474,8 +475,9 @@ ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply) return ERR_ANS_PARCELABLE_FAILED; } - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + data.PrintBuffer(__FUNCTION__, __LINE__); + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandlePublish] fail: notification ReadParcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -490,8 +492,8 @@ ErrCode AnsManagerStub::HandlePublish(MessageParcel &data, MessageParcel &reply) ErrCode AnsManagerStub::HandlePublishNotificationForIndirectProxy(MessageParcel &data, MessageParcel &reply) { - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandlePublishNotificationForIndirectProxy] fail: notification ReadParcelable failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -777,7 +779,11 @@ ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, Messag } std::vector> notifications; ErrCode result = GetActiveNotifications(notifications, appInstanceKey); - if (!WriteParcelableVector(notifications, reply, result)) { + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; + } + if (!WriteLargeInfoIntoParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[HandleGetActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -804,11 +810,11 @@ ErrCode AnsManagerStub::HandleGetAllActiveNotifications(MessageParcel &data, Mes { std::vector> notifications; ErrCode result = GetAllActiveNotifications(notifications); - - if (!reply.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { - return ERR_ANS_PARCELABLE_FAILED; + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; } - if (!WriteParcelableVector(notifications, reply, result)) { + if (!WriteLargeInfoIntoParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[HandleGetAllActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -825,7 +831,11 @@ ErrCode AnsManagerStub::HandleGetSpecialActiveNotifications(MessageParcel &data, std::vector> notifications; ErrCode result = GetSpecialActiveNotifications(key, notifications); - if (!WriteParcelableVector(notifications, reply, result)) { + if (!reply.WriteInt32(result)) { + ANS_LOGE("write result failed, ErrCode=%{public}d", result); + return false; + } + if (!WriteLargeInfoIntoParcelable(reply, notifications, NotificationConstant::NOTIFICATION_MAX_DATA_SIZE)) { ANS_LOGE("[HandleGetSpecialActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -865,7 +875,7 @@ ErrCode AnsManagerStub::HandleGetActiveNotificationByFilter(MessageParcel &data, return ERR_ANS_PARCELABLE_FAILED; } - if (!reply.WriteParcelable(request)) { + if (!WriteLargeInfoIntoParcelable(reply, request, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -897,8 +907,8 @@ ErrCode AnsManagerStub::HandleCanPublishAsBundle(MessageParcel &data, MessagePar ErrCode AnsManagerStub::HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply) { - sptr notification = data.ReadParcelable(); - if (!notification) { + sptr notification = nullptr; + if (!ReadLargeInfoFromParcelable(data, notification, NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { ANS_LOGE("[HandlePublishAsBundle] fail: read notification failed"); return ERR_ANS_PARCELABLE_FAILED; } -- Gitee