From f345eebe51d4cb4e81de6a6482cb37f3265156d3 Mon Sep 17 00:00:00 2001 From: srr101 Date: Tue, 19 Mar 2024 00:53:14 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E5=B8=A6value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- ability_runtime.gni | 1 + interfaces/inner_api/dataobs_manager/BUILD.gn | 1 + .../include/dataobs_mgr_changeinfo.h | 10 +++++-- .../dataobsmgr/src/dataobs_mgr_changeinfo.cpp | 29 +++++++++++++++---- .../dataobsmgr/src/dataobs_mgr_inner_ext.cpp | 3 +- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/ability_runtime.gni b/ability_runtime.gni index 6d0eae9be2..edef7d6d67 100644 --- a/ability_runtime.gni +++ b/ability_runtime.gni @@ -71,6 +71,7 @@ srms_inner_api_path = "${ability_runtime_path}/service_router_framework/interfaces/inner_api" fuzz_test_output_path = "ability_runtime/ability_runtime" accessibility_path = "//foundation/barrierfree/accessibility" +kv_store_path = "//foundation/distributeddatamgr/kv_store" declare_args() { background_task_mgr_continuous_task_enable = true diff --git a/interfaces/inner_api/dataobs_manager/BUILD.gn b/interfaces/inner_api/dataobs_manager/BUILD.gn index 3527f7d787..df0761027e 100644 --- a/interfaces/inner_api/dataobs_manager/BUILD.gn +++ b/interfaces/inner_api/dataobs_manager/BUILD.gn @@ -22,6 +22,7 @@ config("dataobs_manager_public_config") { "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_services_path}/dataobsmgr/include", "${ability_base_kits_path}/uri/include", + "${kv_store_path}/frameworks/common", ] cflags = [] if (target_cpu == "arm") { diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h index 5175464ef3..c9e80bb8a9 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h @@ -16,6 +16,7 @@ #define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_CHANGENOTIFICATION_H #include +#include #include "uri.h" #include "message_parcel.h" @@ -29,14 +30,19 @@ struct ChangeInfo { OTHER, INVAILD, }; + using Value = std::variant>; + using Values = std::vector; + using VBucket = std::map; + using VBuckets = std::vector; - static bool Marshalling(const ChangeInfo &input, MessageParcel &data); - static bool Unmarshalling(ChangeInfo &output, MessageParcel &data); + static bool Marshalling(const ChangeInfo &input, MessageParcel &parcel); + static bool Unmarshalling(ChangeInfo &output, MessageParcel &parcel); ChangeType changeType_ = INVAILD; mutable std::list uris_ = {}; void *data_ = nullptr; uint32_t size_ = 0; + VBuckets valuesBucket_ = {}; static constexpr int LIST_MAX_COUNT = 3000; }; } // namespace AAFwk diff --git a/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp b/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp index 1d5f969029..41af0c0c14 100644 --- a/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp @@ -14,32 +14,44 @@ */ #include #include "dataobs_mgr_changeinfo.h" +#include "itypes_util.h" #include "securec.h" namespace OHOS { namespace AAFwk { -bool ChangeInfo::Marshalling(const ChangeInfo &input, MessageParcel &data) +using Value = std::variant>; +using Values = std::vector; +using VBucket = std::map; +using VBuckets = std::vector; +bool ChangeInfo::Marshalling(const ChangeInfo &input, MessageParcel &parcel) { - if (!data.WriteUint32(static_cast(input.changeType_))) { + if (!parcel.WriteUint32(static_cast(input.changeType_))) { return false; } if (input.uris_.size() > std::numeric_limits::max() || - !data.WriteUint32(static_cast(input.uris_.size()))) { + !parcel.WriteUint32(static_cast(input.uris_.size()))) { return false; } for (auto const &uri : input.uris_) { - if (!data.WriteString(uri.ToString())) { + if (!parcel.WriteString(uri.ToString())) { return false; } } - if (!data.WriteUint32(input.size_)) { + if (!parcel.WriteUint32(input.size_)) { return false; } - return input.size_ == 0 || data.WriteBuffer(input.data_, input.size_); + if (!(input.size_ == 0 || parcel.WriteBuffer(input.data_, input.size_))) { + return false; + } + + if (!ITypesUtil::Marshal(parcel, input.valuesBucket_)) { + return false; + } + return true; } bool ChangeInfo::Unmarshalling(ChangeInfo &output, MessageParcel &parcel) @@ -75,10 +87,15 @@ bool ChangeInfo::Unmarshalling(ChangeInfo &output, MessageParcel &parcel) if (size > 0 && data == nullptr) { return false; } + VBuckets bucket; + if (!(ITypesUtil::Unmarshal(parcel, bucket))) { + return false; + } output.changeType_ = static_cast(changeType); std::swap(output.uris_, uris); output.data_ = const_cast(data); output.size_ = size; + output.valuesBucket_ = std::move(bucket); return true; } } // namespace AAFwk diff --git a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp index b115bbe5a6..9117207bcb 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp @@ -101,7 +101,8 @@ Status DataObsMgrInnerExt::HandleNotifyChange(const ChangeInfo &changeInfo) } for (const auto &[obs, value] : changeRes) { if (obs != nullptr && !value.empty()) { - obs->OnChangeExt({ changeInfo.changeType_, move(value), changeInfo.data_, changeInfo.size_ }); + obs->OnChangeExt( + { changeInfo.changeType_, move(value), changeInfo.data_, changeInfo.size_, changeInfo.valuesBucket_ }); } } From 8e2ca909fb2a305211b3650cc4fcd68cdd32d0ec Mon Sep 17 00:00:00 2001 From: srr101 Date: Tue, 19 Mar 2024 11:43:09 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- interfaces/inner_api/dataobs_manager/BUILD.gn | 1 - .../dataobs_manager/include/dataobs_utils.h | 589 ++++++++++++++++++ .../dataobsmgr/src/dataobs_mgr_changeinfo.cpp | 6 +- 3 files changed, 592 insertions(+), 4 deletions(-) create mode 100644 interfaces/inner_api/dataobs_manager/include/dataobs_utils.h diff --git a/interfaces/inner_api/dataobs_manager/BUILD.gn b/interfaces/inner_api/dataobs_manager/BUILD.gn index df0761027e..3527f7d787 100644 --- a/interfaces/inner_api/dataobs_manager/BUILD.gn +++ b/interfaces/inner_api/dataobs_manager/BUILD.gn @@ -22,7 +22,6 @@ config("dataobs_manager_public_config") { "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_services_path}/dataobsmgr/include", "${ability_base_kits_path}/uri/include", - "${kv_store_path}/frameworks/common", ] cflags = [] if (target_cpu == "arm") { diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h b/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h new file mode 100644 index 0000000000..ee7aa2a42f --- /dev/null +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h @@ -0,0 +1,589 @@ +/* + * Copyright (c) 2024 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 OHOS_ABILITY_RUNTIME_DATAOBS_UTILS_H +#define OHOS_ABILITY_RUNTIME_DATAOBS_UTILS_H +#include +#include +#include +#include +#include +#include +#include + +#include "iremote_object.h" +#include "message_parcel.h" +namespace OHOS { +template +struct is_container : std::false_type { +}; +template +struct is_container> : std::true_type { +}; +template +struct is_container> : std::true_type { +}; +namespace DataObsUtils { +inline constexpr size_t MAX_COUNT = 100000; +inline constexpr size_t MAX_SIZE = 1 * 1024 * 1024 * 1024; //1G +static inline bool Marshal(MessageParcel &data) +{ + return true; +} + +static inline bool Unmarshal(MessageParcel &data) +{ + return true; +} + +static inline bool Marshalling(int16_t input, MessageParcel &data) +{ + return data.WriteInt16(input); +} + +static inline bool Unmarshalling(int16_t &output, MessageParcel &data) +{ + return data.ReadInt16(output); +} + +static inline bool Marshalling(uint32_t input, MessageParcel &data) +{ + return data.WriteUint32(input); +} + +static inline bool Unmarshalling(uint32_t &output, MessageParcel &data) +{ + return data.ReadUint32(output); +} + +static inline bool Marshalling(int32_t input, MessageParcel &data) +{ + return data.WriteInt32(input); +} + +static inline bool Unmarshalling(int32_t &output, MessageParcel &data) +{ + return data.ReadInt32(output); +} + +static inline bool Marshalling(uint64_t input, MessageParcel &data) +{ + return data.WriteUint64(input); +} + +static inline bool Unmarshalling(uint64_t &output, MessageParcel &data) +{ + return data.ReadUint64(output); +} + +static inline bool Marshalling(int64_t input, MessageParcel &data) +{ + return data.WriteInt64(input); +} + +static inline bool Unmarshalling(int64_t &output, MessageParcel &data) +{ + return data.ReadInt64(output); +} + +static inline bool Marshalling(double input, MessageParcel &data) +{ + return data.WriteDouble(input); +} + +static inline bool Unmarshalling(double &output, MessageParcel &data) +{ + return data.ReadDouble(output); +} + +static inline bool Marshalling(bool input, MessageParcel &data) +{ + return data.WriteBool(input); +} + +static inline bool Unmarshalling(bool &output, MessageParcel &data) +{ + return data.ReadBool(output); +} + +static inline bool Marshalling(const std::monostate &input, MessageParcel &data) +{ + return true; +} + +static inline bool Unmarshalling(std::monostate &output, MessageParcel &data) +{ + return true; +} + +static inline bool Marshalling(const std::string &input, MessageParcel &data) +{ + return data.WriteString(input); +} + +static inline bool Unmarshalling(std::string &output, MessageParcel &data) +{ + return data.ReadString(output); +} + +static inline bool Marshalling(const std::u16string &input, MessageParcel &data) +{ + return data.WriteString16(input); +} + +static inline bool Unmarshalling(std::u16string &output, MessageParcel &data) +{ + return data.ReadString16(output); +} + +static inline bool Marshalling(const std::vector &input, MessageParcel &data) +{ + return data.WriteUInt8Vector(input); +} + +static inline bool Unmarshalling(std::vector &output, MessageParcel &data) +{ + return data.ReadUInt8Vector(&output); +} + +static inline bool Marshalling(const sptr &input, MessageParcel &data) +{ + return data.WriteRemoteObject(input); +} + +static inline bool Unmarshalling(sptr &output, MessageParcel &data) +{ + output = data.ReadRemoteObject(); + return true; +} + +static inline bool Marshalling(IRemoteObject *input, MessageParcel &data) +{ + return data.WriteRemoteObject(input); +} + +template +bool ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data); +template +bool ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data); + +template +bool WriteVariant(uint32_t step, const _InTp &input, MessageParcel &data); +template +bool WriteVariant(uint32_t step, const _InTp &input, MessageParcel &data); + +template +bool Marshalling(const std::variant<_Types...> &input, MessageParcel &data); +template +bool Unmarshalling(std::variant<_Types...> &output, MessageParcel &data); + +template +bool Marshalling(const std::map &result, MessageParcel &parcel); +template +bool Unmarshalling(std::map &val, MessageParcel &parcel); + +template +bool Marshalling(const std::tuple &result, MessageParcel &parcel); +template +bool Unmarshalling(std::tuple &val, MessageParcel &parcel); + +template +bool Marshalling(const std::pair &result, MessageParcel &parcel); +template +bool Unmarshalling(std::pair &val, MessageParcel &parcel); + +template +bool Marshalling(const std::vector &val, MessageParcel &parcel); +template +bool Unmarshalling(std::vector &val, MessageParcel &parcel); + +template +bool Marshalling(const std::list &val, MessageParcel &parcel); +template +bool Unmarshalling(std::list &val, MessageParcel &parcel); + +template{}, int>::type = 0> +bool Marshalling(const T &input, MessageParcel &data) = delete; +template{}, int>::type = 0> +bool Unmarshalling(T &output, MessageParcel &data) = delete; + +template +bool Marshalling(const T &input, MessageParcel &data); +template +bool Unmarshalling(T &output, MessageParcel &data); + +template{}, int>::type = 0> +bool MarshalToContainer(const T &val, MessageParcel &parcel); +template{}, int>::type = 0> +bool UnmarshalFromContainer(T &val, MessageParcel &parcel); + +template +bool MarshalToBuffer(const T &input, int size, MessageParcel &data); +template +bool MarshalToBuffer(const std::vector &input, int size, MessageParcel &data); + +template +bool UnmarshalFromBuffer(MessageParcel &data, T &output); +template +bool UnmarshalFromBuffer(MessageParcel &data, std::vector &output); + +template +bool Marshal(MessageParcel &parcel, const T &first, const Types &...others); + +template +bool Unmarshal(MessageParcel &parcel, T &first, Types &...others); +} // namespace ITypesUtil + +template +bool DataObsUtils::ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data) +{ + return false; +} + +template +bool DataObsUtils::ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data) +{ + if (step == index) { + _First value{}; + auto success = DataObsUtils::Unmarshalling(value, data); + output = value; + return success; + } + return DataObsUtils::ReadVariant<_OutTp, _Rest...>(step + 1, index, output, data); +} + +template +bool DataObsUtils::WriteVariant(uint32_t step, const _InTp &input, MessageParcel &data) +{ + return false; +} + +template +bool DataObsUtils::WriteVariant(uint32_t step, const _InTp &input, MessageParcel &data) +{ + if (step == input.index()) { + return DataObsUtils::Marshalling(std::get<_First>(input), data); + } + return DataObsUtils::WriteVariant<_InTp, _Rest...>(step + 1, input, data); +} + +template +bool DataObsUtils::Marshalling(const std::variant<_Types...> &input, MessageParcel &data) +{ + uint32_t index = static_cast(input.index()); + if (!data.WriteUint32(index)) { + return false; + } + + return DataObsUtils::WriteVariant(0, input, data); +} + +template +bool DataObsUtils::Unmarshalling(std::variant<_Types...> &output, MessageParcel &data) +{ + uint32_t index = data.ReadUint32(); + if (index >= sizeof...(_Types)) { + return false; + } + + return DataObsUtils::ReadVariant(0, index, output, data); +} + +template +bool DataObsUtils::Marshalling(const std::map &result, MessageParcel &parcel) +{ + if (!parcel.WriteInt32(static_cast(result.size()))) { + return false; + } + for (const auto &entry : result) { + if (!DataObsUtils::Marshalling(entry.first, parcel)) { + return false; + } + if (!DataObsUtils::Marshalling(entry.second, parcel)) { + return false; + } + } + return true; +} + +template +bool DataObsUtils::Unmarshalling(std::map &val, MessageParcel &parcel) +{ + int32_t size = 0; + if (!parcel.ReadInt32(size)) { + return false; + } + if (size < 0) { + return false; + } + + size_t readAbleSize = parcel.GetReadableBytes(); + if ((static_cast(size) > readAbleSize) || static_cast(size) > val.max_size()) { + return false; + } + + for (int32_t i = 0; i < size; i++) { + K key; + if (!DataObsUtils::Unmarshalling(key, parcel)) { + return false; + } + if (!DataObsUtils::Unmarshalling(val[key], parcel)) { + return false; + } + } + return true; +} + +template +bool DataObsUtils::Marshalling(const std::tuple &result, MessageParcel &parcel) +{ + if (!DataObsUtils::Marshalling(std::get<0>(result), parcel)) { + return false; + } + if (!DataObsUtils::Marshalling(std::get<1>(result), parcel)) { + return false; + } + if (!DataObsUtils::Marshalling(std::get<2>(result), parcel)) { // 2 is the last element in tuple + return false; + } + return true; +} + +template +bool DataObsUtils::Unmarshalling(std::tuple &val, MessageParcel &parcel) +{ + F first; + if (!DataObsUtils::Unmarshalling(first, parcel)) { + return false; + } + S second; + if (!DataObsUtils::Unmarshalling(second, parcel)) { + return false; + } + T third; + if (!DataObsUtils::Unmarshalling(third, parcel)) { + return false; + } + val = { first, second, third }; + return true; +} + +template +bool DataObsUtils::Marshalling(const std::pair &result, MessageParcel &parcel) +{ + if (!DataObsUtils::Marshalling(result.first, parcel)) { + return false; + } + if (!DataObsUtils::Marshalling(result.second, parcel)) { + return false; + } + return true; +} + +template +bool DataObsUtils::Unmarshalling(std::pair &val, MessageParcel &parcel) +{ + F first; + if (!DataObsUtils::Unmarshalling(first, parcel)) { + return false; + } + S second; + if (!DataObsUtils::Unmarshalling(second, parcel)) { + return false; + } + val = { first, second }; + return true; +} + +template +bool DataObsUtils::Marshalling(const std::vector &val, MessageParcel &parcel) +{ + return DataObsUtils::MarshalToContainer(val, parcel); +} + +template +bool DataObsUtils::Unmarshalling(std::vector &val, MessageParcel &parcel) +{ + return DataObsUtils::UnmarshalFromContainer(val, parcel); +} + +template +bool DataObsUtils::Marshalling(const std::list &val, MessageParcel &parcel) +{ + return DataObsUtils::MarshalToContainer(val, parcel); +} + +template +bool DataObsUtils::Unmarshalling(std::list &val, MessageParcel &parcel) +{ + return DataObsUtils::UnmarshalFromContainer(val, parcel); +} + +template{}, int>::type> +bool DataObsUtils::MarshalToContainer(const T &val, MessageParcel &parcel) +{ + if (val.size() > INT_MAX) { + return false; + } + + if (!parcel.WriteInt32(static_cast(val.size()))) { + return false; + } + + for (auto &v : val) { + if (!DataObsUtils::Marshalling(v, parcel)) { + return false; + } + } + return true; +} + +template{}, int>::type> +bool DataObsUtils::UnmarshalFromContainer(T &val, MessageParcel &parcel) +{ + int32_t len = parcel.ReadInt32(); + if (len < 0) { + return false; + } + + size_t readAbleSize = parcel.GetReadableBytes(); + size_t size = static_cast(len); + if ((size > readAbleSize) || (size > val.max_size())) { + return false; + } + + val.clear(); + for (size_t i = 0; i < size; i++) { + typename T::value_type value; + if (!DataObsUtils::Unmarshalling(value, parcel)) { + return false; + } + val.emplace_back(std::move(value)); + } + return true; +} + +template +bool DataObsUtils::MarshalToBuffer(const T &input, int size, MessageParcel &data) +{ + if (size < 0 || static_cast(size) > MAX_SIZE || !data.WriteInt32(size)) { + return false; + } + if (size == 0) { + return true; + } + std::unique_ptr buffer = std::make_unique(size); + if (buffer == nullptr) { + return false; + } + + int leftSize = size; + uint8_t *cursor = buffer.get(); + if (!input.WriteToBuffer(cursor, leftSize)) { + return false; + } + return data.WriteRawData(buffer.get(), size); +} + +template +bool DataObsUtils::MarshalToBuffer(const std::vector &input, int size, MessageParcel &data) +{ + if (size < 0 || static_cast(size) > MAX_SIZE || input.size() > MAX_COUNT || !data.WriteInt32(size)) { + return false; + } + if (size == 0) { + return true; + } + if (!data.WriteInt32(input.size())) { + return false; + } + + std::unique_ptr buffer = std::make_unique(size); + if (buffer == nullptr) { + return false; + } + + uint8_t *cursor = buffer.get(); + int32_t left = size; + for (const auto &entry : input) { + if (!entry.WriteToBuffer(cursor, left)) { + return false; + } + } + return data.WriteRawData(buffer.get(), size); +} + +template +bool DataObsUtils::UnmarshalFromBuffer(MessageParcel &data, T &output) +{ + int32_t size = data.ReadInt32(); + if (size == 0) { + return true; + } + if (size < 0 || static_cast(size) > MAX_SIZE) { + return false; + } + const uint8_t *buffer = reinterpret_cast(data.ReadRawData(size)); + if (buffer == nullptr) { + return false; + } + return output.ReadFromBuffer(buffer, size); +} + +template +bool DataObsUtils::UnmarshalFromBuffer(MessageParcel &data, std::vector &output) +{ + int size = data.ReadInt32(); + if (size == 0) { + return true; + } + if (size < 0 || static_cast(size) > MAX_SIZE) { + return false; + } + int count = data.ReadInt32(); + const uint8_t *buffer = reinterpret_cast(data.ReadRawData(size)); + if (count < 0 || static_cast(count) > MAX_COUNT || buffer == nullptr) { + return false; + } + + output.resize(count); + for (auto &entry : output) { + if (!entry.ReadFromBuffer(buffer, size)) { + output.clear(); + return false; + } + } + return true; +} + +template +bool DataObsUtils::Marshal(MessageParcel &parcel, const T &first, const Types &...others) +{ + if (!DataObsUtils::Marshalling(first, parcel)) { + return false; + } + return DataObsUtils::Marshal(parcel, others...); +} + +template +bool DataObsUtils::Unmarshal(MessageParcel &parcel, T &first, Types &...others) +{ + if (!DataObsUtils::Unmarshalling(first, parcel)) { + return false; + } + return DataObsUtils::Unmarshal(parcel, others...); +} +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DATAOBS_UTILS_H \ No newline at end of file diff --git a/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp b/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp index 41af0c0c14..0f2e897b66 100644 --- a/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp @@ -14,7 +14,7 @@ */ #include #include "dataobs_mgr_changeinfo.h" -#include "itypes_util.h" +#include "dataobs_utils.h" #include "securec.h" namespace OHOS { @@ -48,7 +48,7 @@ bool ChangeInfo::Marshalling(const ChangeInfo &input, MessageParcel &parcel) return false; } - if (!ITypesUtil::Marshal(parcel, input.valuesBucket_)) { + if (!DataObsUtils::Marshal(parcel, input.valuesBucket_)) { return false; } return true; @@ -88,7 +88,7 @@ bool ChangeInfo::Unmarshalling(ChangeInfo &output, MessageParcel &parcel) return false; } VBuckets bucket; - if (!(ITypesUtil::Unmarshal(parcel, bucket))) { + if (!(DataObsUtils::Unmarshal(parcel, bucket))) { return false; } output.changeType_ = static_cast(changeType); From 942c122ec0bd90802e4c1c34e4d8ed37ea9feebf Mon Sep 17 00:00:00 2001 From: srr101 Date: Tue, 19 Mar 2024 11:45:16 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- ability_runtime.gni | 1 - 1 file changed, 1 deletion(-) diff --git a/ability_runtime.gni b/ability_runtime.gni index edef7d6d67..6d0eae9be2 100644 --- a/ability_runtime.gni +++ b/ability_runtime.gni @@ -71,7 +71,6 @@ srms_inner_api_path = "${ability_runtime_path}/service_router_framework/interfaces/inner_api" fuzz_test_output_path = "ability_runtime/ability_runtime" accessibility_path = "//foundation/barrierfree/accessibility" -kv_store_path = "//foundation/distributeddatamgr/kv_store" declare_args() { background_task_mgr_continuous_task_enable = true From 3582680370cecbc4d4f9deb5e13fd1f895a0ac1d Mon Sep 17 00:00:00 2001 From: srr101 Date: Fri, 22 Mar 2024 14:41:48 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- .../dataobs_manager/include/dataobs_mgr_changeinfo.h | 3 +-- services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp | 9 ++++----- services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h index c9e80bb8a9..70404e5a31 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_changeinfo.h @@ -31,7 +31,6 @@ struct ChangeInfo { INVAILD, }; using Value = std::variant>; - using Values = std::vector; using VBucket = std::map; using VBuckets = std::vector; @@ -42,7 +41,7 @@ struct ChangeInfo { mutable std::list uris_ = {}; void *data_ = nullptr; uint32_t size_ = 0; - VBuckets valuesBucket_ = {}; + VBuckets valueBuckets_ = {}; static constexpr int LIST_MAX_COUNT = 3000; }; } // namespace AAFwk diff --git a/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp b/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp index 0f2e897b66..d2aaf6c094 100644 --- a/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_changeinfo.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace AAFwk { using Value = std::variant>; -using Values = std::vector; using VBucket = std::map; using VBuckets = std::vector; bool ChangeInfo::Marshalling(const ChangeInfo &input, MessageParcel &parcel) @@ -48,7 +47,7 @@ bool ChangeInfo::Marshalling(const ChangeInfo &input, MessageParcel &parcel) return false; } - if (!DataObsUtils::Marshal(parcel, input.valuesBucket_)) { + if (!DataObsUtils::Marshal(parcel, input.valueBuckets_)) { return false; } return true; @@ -87,15 +86,15 @@ bool ChangeInfo::Unmarshalling(ChangeInfo &output, MessageParcel &parcel) if (size > 0 && data == nullptr) { return false; } - VBuckets bucket; - if (!(DataObsUtils::Unmarshal(parcel, bucket))) { + VBuckets buckets; + if (!(DataObsUtils::Unmarshal(parcel, buckets))) { return false; } output.changeType_ = static_cast(changeType); std::swap(output.uris_, uris); output.data_ = const_cast(data); output.size_ = size; - output.valuesBucket_ = std::move(bucket); + output.valueBuckets_ = std::move(buckets); return true; } } // namespace AAFwk diff --git a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp index 9117207bcb..9910c5789a 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp @@ -102,7 +102,7 @@ Status DataObsMgrInnerExt::HandleNotifyChange(const ChangeInfo &changeInfo) for (const auto &[obs, value] : changeRes) { if (obs != nullptr && !value.empty()) { obs->OnChangeExt( - { changeInfo.changeType_, move(value), changeInfo.data_, changeInfo.size_, changeInfo.valuesBucket_ }); + { changeInfo.changeType_, move(value), changeInfo.data_, changeInfo.size_, changeInfo.valueBuckets_ }); } } From 63f5ca3bada79cced38f4b377c59f611ea4b63ce Mon Sep 17 00:00:00 2001 From: srr101 Date: Wed, 27 Mar 2024 19:38:18 +0800 Subject: [PATCH 5/6] delete unuse function Signed-off-by: srr101 --- .../dataobs_manager/include/dataobs_utils.h | 266 +----------------- 1 file changed, 1 insertion(+), 265 deletions(-) diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h b/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h index ee7aa2a42f..3fb22d9757 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h @@ -36,8 +36,6 @@ template struct is_container> : std::true_type { }; namespace DataObsUtils { -inline constexpr size_t MAX_COUNT = 100000; -inline constexpr size_t MAX_SIZE = 1 * 1024 * 1024 * 1024; //1G static inline bool Marshal(MessageParcel &data) { return true; @@ -48,46 +46,6 @@ static inline bool Unmarshal(MessageParcel &data) return true; } -static inline bool Marshalling(int16_t input, MessageParcel &data) -{ - return data.WriteInt16(input); -} - -static inline bool Unmarshalling(int16_t &output, MessageParcel &data) -{ - return data.ReadInt16(output); -} - -static inline bool Marshalling(uint32_t input, MessageParcel &data) -{ - return data.WriteUint32(input); -} - -static inline bool Unmarshalling(uint32_t &output, MessageParcel &data) -{ - return data.ReadUint32(output); -} - -static inline bool Marshalling(int32_t input, MessageParcel &data) -{ - return data.WriteInt32(input); -} - -static inline bool Unmarshalling(int32_t &output, MessageParcel &data) -{ - return data.ReadInt32(output); -} - -static inline bool Marshalling(uint64_t input, MessageParcel &data) -{ - return data.WriteUint64(input); -} - -static inline bool Unmarshalling(uint64_t &output, MessageParcel &data) -{ - return data.ReadUint64(output); -} - static inline bool Marshalling(int64_t input, MessageParcel &data) { return data.WriteInt64(input); @@ -138,16 +96,6 @@ static inline bool Unmarshalling(std::string &output, MessageParcel &data) return data.ReadString(output); } -static inline bool Marshalling(const std::u16string &input, MessageParcel &data) -{ - return data.WriteString16(input); -} - -static inline bool Unmarshalling(std::u16string &output, MessageParcel &data) -{ - return data.ReadString16(output); -} - static inline bool Marshalling(const std::vector &input, MessageParcel &data) { return data.WriteUInt8Vector(input); @@ -158,22 +106,6 @@ static inline bool Unmarshalling(std::vector &output, MessageParcel &da return data.ReadUInt8Vector(&output); } -static inline bool Marshalling(const sptr &input, MessageParcel &data) -{ - return data.WriteRemoteObject(input); -} - -static inline bool Unmarshalling(sptr &output, MessageParcel &data) -{ - output = data.ReadRemoteObject(); - return true; -} - -static inline bool Marshalling(IRemoteObject *input, MessageParcel &data) -{ - return data.WriteRemoteObject(input); -} - template bool ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data); template @@ -194,31 +126,11 @@ bool Marshalling(const std::map &result, MessageParcel &parcel); template bool Unmarshalling(std::map &val, MessageParcel &parcel); -template -bool Marshalling(const std::tuple &result, MessageParcel &parcel); -template -bool Unmarshalling(std::tuple &val, MessageParcel &parcel); - -template -bool Marshalling(const std::pair &result, MessageParcel &parcel); -template -bool Unmarshalling(std::pair &val, MessageParcel &parcel); - template bool Marshalling(const std::vector &val, MessageParcel &parcel); template bool Unmarshalling(std::vector &val, MessageParcel &parcel); -template -bool Marshalling(const std::list &val, MessageParcel &parcel); -template -bool Unmarshalling(std::list &val, MessageParcel &parcel); - -template{}, int>::type = 0> -bool Marshalling(const T &input, MessageParcel &data) = delete; -template{}, int>::type = 0> -bool Unmarshalling(T &output, MessageParcel &data) = delete; - template bool Marshalling(const T &input, MessageParcel &data); template @@ -229,22 +141,12 @@ bool MarshalToContainer(const T &val, MessageParcel &parcel); template{}, int>::type = 0> bool UnmarshalFromContainer(T &val, MessageParcel &parcel); -template -bool MarshalToBuffer(const T &input, int size, MessageParcel &data); -template -bool MarshalToBuffer(const std::vector &input, int size, MessageParcel &data); - -template -bool UnmarshalFromBuffer(MessageParcel &data, T &output); -template -bool UnmarshalFromBuffer(MessageParcel &data, std::vector &output); - template bool Marshal(MessageParcel &parcel, const T &first, const Types &...others); template bool Unmarshal(MessageParcel &parcel, T &first, Types &...others); -} // namespace ITypesUtil +}// namespace DataObsUtils template bool DataObsUtils::ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data) @@ -346,67 +248,6 @@ bool DataObsUtils::Unmarshalling(std::map &val, MessageParcel &parcel) return true; } -template -bool DataObsUtils::Marshalling(const std::tuple &result, MessageParcel &parcel) -{ - if (!DataObsUtils::Marshalling(std::get<0>(result), parcel)) { - return false; - } - if (!DataObsUtils::Marshalling(std::get<1>(result), parcel)) { - return false; - } - if (!DataObsUtils::Marshalling(std::get<2>(result), parcel)) { // 2 is the last element in tuple - return false; - } - return true; -} - -template -bool DataObsUtils::Unmarshalling(std::tuple &val, MessageParcel &parcel) -{ - F first; - if (!DataObsUtils::Unmarshalling(first, parcel)) { - return false; - } - S second; - if (!DataObsUtils::Unmarshalling(second, parcel)) { - return false; - } - T third; - if (!DataObsUtils::Unmarshalling(third, parcel)) { - return false; - } - val = { first, second, third }; - return true; -} - -template -bool DataObsUtils::Marshalling(const std::pair &result, MessageParcel &parcel) -{ - if (!DataObsUtils::Marshalling(result.first, parcel)) { - return false; - } - if (!DataObsUtils::Marshalling(result.second, parcel)) { - return false; - } - return true; -} - -template -bool DataObsUtils::Unmarshalling(std::pair &val, MessageParcel &parcel) -{ - F first; - if (!DataObsUtils::Unmarshalling(first, parcel)) { - return false; - } - S second; - if (!DataObsUtils::Unmarshalling(second, parcel)) { - return false; - } - val = { first, second }; - return true; -} - template bool DataObsUtils::Marshalling(const std::vector &val, MessageParcel &parcel) { @@ -419,18 +260,6 @@ bool DataObsUtils::Unmarshalling(std::vector &val, MessageParcel &parcel) return DataObsUtils::UnmarshalFromContainer(val, parcel); } -template -bool DataObsUtils::Marshalling(const std::list &val, MessageParcel &parcel) -{ - return DataObsUtils::MarshalToContainer(val, parcel); -} - -template -bool DataObsUtils::Unmarshalling(std::list &val, MessageParcel &parcel) -{ - return DataObsUtils::UnmarshalFromContainer(val, parcel); -} - template{}, int>::type> bool DataObsUtils::MarshalToContainer(const T &val, MessageParcel &parcel) { @@ -475,99 +304,6 @@ bool DataObsUtils::UnmarshalFromContainer(T &val, MessageParcel &parcel) return true; } -template -bool DataObsUtils::MarshalToBuffer(const T &input, int size, MessageParcel &data) -{ - if (size < 0 || static_cast(size) > MAX_SIZE || !data.WriteInt32(size)) { - return false; - } - if (size == 0) { - return true; - } - std::unique_ptr buffer = std::make_unique(size); - if (buffer == nullptr) { - return false; - } - - int leftSize = size; - uint8_t *cursor = buffer.get(); - if (!input.WriteToBuffer(cursor, leftSize)) { - return false; - } - return data.WriteRawData(buffer.get(), size); -} - -template -bool DataObsUtils::MarshalToBuffer(const std::vector &input, int size, MessageParcel &data) -{ - if (size < 0 || static_cast(size) > MAX_SIZE || input.size() > MAX_COUNT || !data.WriteInt32(size)) { - return false; - } - if (size == 0) { - return true; - } - if (!data.WriteInt32(input.size())) { - return false; - } - - std::unique_ptr buffer = std::make_unique(size); - if (buffer == nullptr) { - return false; - } - - uint8_t *cursor = buffer.get(); - int32_t left = size; - for (const auto &entry : input) { - if (!entry.WriteToBuffer(cursor, left)) { - return false; - } - } - return data.WriteRawData(buffer.get(), size); -} - -template -bool DataObsUtils::UnmarshalFromBuffer(MessageParcel &data, T &output) -{ - int32_t size = data.ReadInt32(); - if (size == 0) { - return true; - } - if (size < 0 || static_cast(size) > MAX_SIZE) { - return false; - } - const uint8_t *buffer = reinterpret_cast(data.ReadRawData(size)); - if (buffer == nullptr) { - return false; - } - return output.ReadFromBuffer(buffer, size); -} - -template -bool DataObsUtils::UnmarshalFromBuffer(MessageParcel &data, std::vector &output) -{ - int size = data.ReadInt32(); - if (size == 0) { - return true; - } - if (size < 0 || static_cast(size) > MAX_SIZE) { - return false; - } - int count = data.ReadInt32(); - const uint8_t *buffer = reinterpret_cast(data.ReadRawData(size)); - if (count < 0 || static_cast(count) > MAX_COUNT || buffer == nullptr) { - return false; - } - - output.resize(count); - for (auto &entry : output) { - if (!entry.ReadFromBuffer(buffer, size)) { - output.clear(); - return false; - } - } - return true; -} - template bool DataObsUtils::Marshal(MessageParcel &parcel, const T &first, const Types &...others) { From 5a7a3af5b2f7a04679d235e5cf3234c6fb21403a Mon Sep 17 00:00:00 2001 From: srr101 Date: Wed, 27 Mar 2024 19:48:25 +0800 Subject: [PATCH 6/6] code check fix Signed-off-by: srr101 --- interfaces/inner_api/dataobs_manager/include/dataobs_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h b/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h index 3fb22d9757..103c1e221e 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_utils.h @@ -146,7 +146,7 @@ bool Marshal(MessageParcel &parcel, const T &first, const Types &...others); template bool Unmarshal(MessageParcel &parcel, T &first, Types &...others); -}// namespace DataObsUtils +} // namespace DataObsUtils template bool DataObsUtils::ReadVariant(uint32_t step, uint32_t index, const _OutTp &output, MessageParcel &data)