From fd939eacca466d2b641e5ae65a9ef77d8bf5e1a5 Mon Sep 17 00:00:00 2001 From: illybyy Date: Tue, 15 Feb 2022 14:22:29 +0800 Subject: [PATCH 1/3] fix empty device id at startup Signed-off-by: illybyy --- .../app_distributeddata/include/visibility.h | 18 ++++----- .../adapter/security/BUILD.gn | 4 +- .../adapter/security/src/security.cpp | 7 +++- .../app/src/kvstore_data_service.cpp | 18 +++++++-- .../distributeddataservice/framework/BUILD.gn | 2 +- .../framework/checker/checker_manager.cpp | 2 - .../include/checker/checker_manager.h | 1 + .../include/utils}/block_integer.h | 39 ++++++++----------- .../src => framework/utils}/block_integer.cpp | 5 ++- 9 files changed, 53 insertions(+), 43 deletions(-) rename services/distributeddataservice/{adapter/security/src => framework/include/utils}/block_integer.h (44%) mode change 100755 => 100644 rename services/distributeddataservice/{adapter/security/src => framework/utils}/block_integer.cpp (90%) mode change 100755 => 100644 diff --git a/interfaces/innerkits/app_distributeddata/include/visibility.h b/interfaces/innerkits/app_distributeddata/include/visibility.h index 2ffb65244..6a751a3d7 100644 --- a/interfaces/innerkits/app_distributeddata/include/visibility.h +++ b/interfaces/innerkits/app_distributeddata/include/visibility.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,16 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef OHOS_DISTRIBUTED_DATA_INTERFACE_APP_DISTRIBUTEDDATA_INCLUDE_COMMON_VISIBILITY_H +#define OHOS_DISTRIBUTED_DATA_INTERFACE_APP_DISTRIBUTEDDATA_INCLUDE_COMMON_VISIBILITY_H -#ifndef KVSTORE_API -#ifdef _WIN32 - #ifdef DB_DLL_EXPORT - #define KVSTORE_API __declspec(dllexport) - #else - #define KVSTORE_API - #endif -#else - #define KVSTORE_API __attribute__ ((visibility ("default"))) +#ifndef API_EXPORT +#define API_EXPORT __attribute__((visibility("default"))) #endif +#ifndef KVSTORE_API +#define KVSTORE_API API_EXPORT #endif +#endif// OHOS_DISTRIBUTED_DATA_INTERFACE_APP_DISTRIBUTEDDATA_INCLUDE_COMMON_VISIBILITY_H diff --git a/services/distributeddataservice/adapter/security/BUILD.gn b/services/distributeddataservice/adapter/security/BUILD.gn index 4ca34ef5c..9ff3ec648 100755 --- a/services/distributeddataservice/adapter/security/BUILD.gn +++ b/services/distributeddataservice/adapter/security/BUILD.gn @@ -15,7 +15,6 @@ import("//build/ohos.gni") ohos_static_library("distributeddata_security_static") { sources = [ - "src/block_integer.cpp", "src/security.cpp", "src/security_adapter.cpp", "src/sensitive.cpp", @@ -28,11 +27,14 @@ ohos_static_library("distributeddata_security_static") { "../include/log", "../include/security", "../include/communicator", + "//foundation/distributeddatamgr/distributeddatamgr/frameworks/common", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/app_distributeddata/include", + "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/framework/include", ] deps = [ "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/libs/distributeddb:distributeddb", + "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/framework:distributeddatasvcfwk", "//utils/native/base:utils", ] diff --git a/services/distributeddataservice/adapter/security/src/security.cpp b/services/distributeddataservice/adapter/security/src/security.cpp index 05f95e918..7ab087ff8 100755 --- a/services/distributeddataservice/adapter/security/src/security.cpp +++ b/services/distributeddataservice/adapter/security/src/security.cpp @@ -14,19 +14,22 @@ */ #include "security.h" + #include #include + #include "communication_provider.h" #include "constant.h" -#include "sensitive.h" #include "log_print.h" -#include "block_integer.h" #include "ohos_account_kits.h" +#include "sensitive.h" +#include "utils/block_integer.h" #undef LOG_TAG #define LOG_TAG "SecurityAdapter" namespace OHOS::DistributedKv { using namespace DistributedDB; +using BlockInteger = OHOS::DistributedData::BlockInteger; std::atomic_bool Security::isInitialized_ = true; const char * const Security::LABEL_VALUES[S4 + 1] = {}; const char * const Security::DATA_DE[] = { nullptr }; diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index b59f3ea40..98135ed8e 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -16,12 +16,14 @@ #define LOG_TAG "KvStoreDataService" #include "kvstore_data_service.h" -#include + #include #include #include -#include #include +#include +#include + #include "auto_launch_export.h" #include "bootstrap.h" #include "checker/checker_manager.h" @@ -41,10 +43,11 @@ #include "permission/permission_kit.h" #include "permission_validator.h" #include "process_communicator_impl.h" -#include "reporter.h" #include "rdb_service_impl.h" +#include "reporter.h" #include "system_ability_definition.h" #include "uninstaller/uninstaller.h" +#include "utils/block_integer.h" #include "utils/crypto.h" namespace OHOS::DistributedKv { @@ -812,6 +815,15 @@ void KvStoreDataService::OnStart() void KvStoreDataService::StartService() { + static constexpr int32_t RETRY_TIMES = 10; + static constexpr int32_t RETRY_INTERVAL = 500; // unit is ms + for (BlockInteger retry(RETRY_INTERVAL); retry < RETRY_TIMES; ++retry) { + if (!DeviceKvStoreImpl::GetLocalDeviceId().empty()) { + break; + } + ZLOGE("GetLocalDeviceId failed, reties: %{public}d", static_cast(retry)); + } + // register this to ServiceManager. bool ret = SystemAbility::Publish(this); if (!ret) { diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 92907a777..8a7722a00 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -40,6 +40,7 @@ ohos_shared_library("distributeddatasvcfwk") { "serializable/serializable.cpp", "utils/constant.cpp", "utils/crypto.cpp", + "utils/block_integer.cpp", ] cflags = [ "-Wno-multichar" ] @@ -49,7 +50,6 @@ ohos_shared_library("distributeddatasvcfwk") { ldflags = [ "-Wl,--exclude-libs,libcrypto_static.a" ] deps = [ - "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/openssl:libcrypto_static", "//utils/native/base:utils", ] diff --git a/services/distributeddataservice/framework/checker/checker_manager.cpp b/services/distributeddataservice/framework/checker/checker_manager.cpp index 1b62d6510..f0a7c316a 100644 --- a/services/distributeddataservice/framework/checker/checker_manager.cpp +++ b/services/distributeddataservice/framework/checker/checker_manager.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ #include "checker/checker_manager.h" -#include "account/account_delegate.h" -using namespace OHOS::DistributedKv; namespace OHOS { namespace DistributedData { CheckerManager &CheckerManager::GetInstance() diff --git a/services/distributeddataservice/framework/include/checker/checker_manager.h b/services/distributeddataservice/framework/include/checker/checker_manager.h index e703a46ed..938730a9d 100644 --- a/services/distributeddataservice/framework/include/checker/checker_manager.h +++ b/services/distributeddataservice/framework/include/checker/checker_manager.h @@ -15,6 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H +#include #include "visibility.h" #include "concurrent_map.h" namespace OHOS { diff --git a/services/distributeddataservice/adapter/security/src/block_integer.h b/services/distributeddataservice/framework/include/utils/block_integer.h old mode 100755 new mode 100644 similarity index 44% rename from services/distributeddataservice/adapter/security/src/block_integer.h rename to services/distributeddataservice/framework/include/utils/block_integer.h index 62ed8b4db..4c4549ce1 --- a/services/distributeddataservice/adapter/security/src/block_integer.h +++ b/services/distributeddataservice/framework/include/utils/block_integer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,41 +13,36 @@ * limitations under the License. */ -#ifndef OHOS_BLOCK_INTEGER_H -#define OHOS_BLOCK_INTEGER_H - +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_UTILS_BLOCK_INTEGER_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_UTILS_BLOCK_INTEGER_H +#include "visibility.h" +namespace OHOS::DistributedData { class BlockInteger { public: - explicit BlockInteger(int interval) - : interval_(interval) - { - }; - BlockInteger(const BlockInteger &integer) - : interval_(integer.interval_), value_(integer.value_) - { - }; - BlockInteger &operator=(const BlockInteger &integer) = default; + API_EXPORT explicit BlockInteger(int interval) : interval_(interval){}; + API_EXPORT BlockInteger(const BlockInteger &integer) : interval_(integer.interval_), value_(integer.value_){}; + API_EXPORT BlockInteger &operator=(const BlockInteger &integer) = default; - ~BlockInteger() = default; + API_EXPORT ~BlockInteger() = default; - operator int () const + API_EXPORT operator int() const { return value_; } - bool operator < (int other) const + API_EXPORT bool operator<(int other) const { return value_ < other; } - BlockInteger &operator=(int value); + API_EXPORT BlockInteger &operator=(int value); - BlockInteger &operator++(); + API_EXPORT BlockInteger &operator++(); + + API_EXPORT BlockInteger operator++(int); - BlockInteger operator++(int); private: int interval_ = 0; int value_ = 0; }; - - -#endif // OHOS_BLOCK_INTEGER_H +} +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_UTILS_BLOCK_INTEGER_H diff --git a/services/distributeddataservice/adapter/security/src/block_integer.cpp b/services/distributeddataservice/framework/utils/block_integer.cpp old mode 100755 new mode 100644 similarity index 90% rename from services/distributeddataservice/adapter/security/src/block_integer.cpp rename to services/distributeddataservice/framework/utils/block_integer.cpp index 8c800cca8..536e525ff --- a/services/distributeddataservice/adapter/security/src/block_integer.cpp +++ b/services/distributeddataservice/framework/utils/block_integer.cpp @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "block_integer.h" +#include "utils/block_integer.h" #include +namespace OHOS::DistributedData { BlockInteger &BlockInteger::operator++() { value_++; @@ -37,3 +37,4 @@ BlockInteger &BlockInteger::operator=(int value) value_ = value; return *this; } +} \ No newline at end of file -- Gitee From 78a8d3fc441335c8474b7e702eec856cb3daa5c0 Mon Sep 17 00:00:00 2001 From: illybyy Date: Tue, 15 Feb 2022 15:51:12 +0800 Subject: [PATCH 2/3] format gn Signed-off-by: illybyy --- services/distributeddataservice/adapter/security/BUILD.gn | 2 +- services/distributeddataservice/framework/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/security/BUILD.gn b/services/distributeddataservice/adapter/security/BUILD.gn index 9ff3ec648..5b0f6a3a2 100755 --- a/services/distributeddataservice/adapter/security/BUILD.gn +++ b/services/distributeddataservice/adapter/security/BUILD.gn @@ -33,8 +33,8 @@ ohos_static_library("distributeddata_security_static") { ] deps = [ - "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/libs/distributeddb:distributeddb", "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/framework:distributeddatasvcfwk", + "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/libs/distributeddb:distributeddb", "//utils/native/base:utils", ] diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 8a7722a00..60f591ddf 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -38,9 +38,9 @@ ohos_shared_library("distributeddatasvcfwk") { "metadata/secret_key_meta_data.cpp", "metadata/store_meta_data.cpp", "serializable/serializable.cpp", + "utils/block_integer.cpp", "utils/constant.cpp", "utils/crypto.cpp", - "utils/block_integer.cpp", ] cflags = [ "-Wno-multichar" ] -- Gitee From bc75177cb659e3537184e3c7de29b78797006d29 Mon Sep 17 00:00:00 2001 From: illybyy Date: Tue, 15 Feb 2022 17:56:36 +0800 Subject: [PATCH 3/3] fix code check Signed-off-by: illybyy --- interfaces/innerkits/app_distributeddata/include/visibility.h | 2 +- .../framework/include/utils/block_integer.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/app_distributeddata/include/visibility.h b/interfaces/innerkits/app_distributeddata/include/visibility.h index 6a751a3d7..a5c2669c8 100644 --- a/interfaces/innerkits/app_distributeddata/include/visibility.h +++ b/interfaces/innerkits/app_distributeddata/include/visibility.h @@ -22,4 +22,4 @@ #define KVSTORE_API API_EXPORT #endif -#endif// OHOS_DISTRIBUTED_DATA_INTERFACE_APP_DISTRIBUTEDDATA_INCLUDE_COMMON_VISIBILITY_H +#endif // OHOS_DISTRIBUTED_DATA_INTERFACE_APP_DISTRIBUTEDDATA_INCLUDE_COMMON_VISIBILITY_H diff --git a/services/distributeddataservice/framework/include/utils/block_integer.h b/services/distributeddataservice/framework/include/utils/block_integer.h index 4c4549ce1..ca8733cc3 100644 --- a/services/distributeddataservice/framework/include/utils/block_integer.h +++ b/services/distributeddataservice/framework/include/utils/block_integer.h @@ -19,8 +19,8 @@ namespace OHOS::DistributedData { class BlockInteger { public: - API_EXPORT explicit BlockInteger(int interval) : interval_(interval){}; - API_EXPORT BlockInteger(const BlockInteger &integer) : interval_(integer.interval_), value_(integer.value_){}; + API_EXPORT explicit BlockInteger(int interval) : interval_(interval) {}; + API_EXPORT BlockInteger(const BlockInteger &integer) : interval_(integer.interval_), value_(integer.value_) {}; API_EXPORT BlockInteger &operator=(const BlockInteger &integer) = default; API_EXPORT ~BlockInteger() = default; -- Gitee