diff --git a/old/services/core/src/authority/authority_manager.cpp b/old/services/core/src/authority/authority_manager.cpp index a698d0dcfa2ba3a894f6ed6eb3e63703a1b9e1a1..d50cb0ca80c2080e27044a4798e52250b10b2fef 100644 --- a/old/services/core/src/authority/authority_manager.cpp +++ b/old/services/core/src/authority/authority_manager.cpp @@ -178,7 +178,7 @@ bool AuthorityManager::ValidateService(const nlohmann::json& authValJson, bool r bool AuthorityManager::CheckInterfaceAuthority(const std::string& ifaceName) { std::string procName = GetCallingProcName(); - if (!authJson_.contains(procName)) { + if (!authJson_.contains(procName) && !authJson_[procName].contains(INTERFACES)) { HILOGE("can't find entry for proc:%{public}s", procName.c_str()); return false; } @@ -214,7 +214,7 @@ bool AuthorityManager::CheckServicesAuthority(AuthValue authVal, } std::string procName = GetCallingProcName(); - if (!authJson_.contains(procName)) { + if (!authJson_.contains(procName) && !authJson_[procName].contains(SERVICES)) { HILOGE("can't find entry for proc:%{public}s", procName.c_str()); return false; } diff --git a/old/services/core/src/authority/trust_group_manager.cpp b/old/services/core/src/authority/trust_group_manager.cpp index 47f07599e83ab9dc75bf628626b29b2677c4047e..f341c1dee48bb390aab357d69924b40c19f5c5cf 100644 --- a/old/services/core/src/authority/trust_group_manager.cpp +++ b/old/services/core/src/authority/trust_group_manager.cpp @@ -114,6 +114,10 @@ bool TrustGroupManager::CheckGroupsInfo(const char* returnGroups, uint32_t group return false; } + if (!jsonObject.is_array()) { + HILOGE("jsonObject is not array!"); + return false; + } std::vector groupInfos = jsonObject.get>(); for (const auto& groupInfo : groupInfos) { // check group visibility is whether public or not diff --git a/old/services/core/src/dbstorage/device_profile_storage.cpp b/old/services/core/src/dbstorage/device_profile_storage.cpp index d4fb6bc6c9cbb6382e9ee8ead50641cfbc058df6..4a3f93b37f7a9f81dc685c7e8af66bbcc7ee0d46 100644 --- a/old/services/core/src/dbstorage/device_profile_storage.cpp +++ b/old/services/core/src/dbstorage/device_profile_storage.cpp @@ -36,7 +36,7 @@ using namespace std::chrono_literals; namespace { const std::string TAG = "DeviceProfileStorage"; -constexpr int32_t RETRY_TIMES_GET_KVSTORE = 500; +constexpr int32_t RETRY_TIMES_GET_KVSTORE = 30; } DeviceProfileStorage::DeviceProfileStorage(const std::string& appId, const std::string& storeId) @@ -133,7 +133,7 @@ bool DeviceProfileStorage::TryGetKvStore() return true; } HILOGD("retry get kvstore..."); - std::this_thread::sleep_for(10ms); + std::this_thread::sleep_for(500ms); retryTimes++; } if (kvStorePtr_ == nullptr) { diff --git a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp index 1789a8fdc6c40e06a62286c834af88087e63ed69..1f75eb216ed49bde1d9af299266e960a1d2f7078 100644 --- a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp +++ b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp @@ -151,7 +151,7 @@ int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristi keys.emplace_back(GenerateKey(localUdid_, serviceId, KeyType::SERVICE)); values.emplace_back(profile.GetCharacteristicProfileJson()); std::unique_lock autoLock(serviceLock_); - if (servicesJson_[serviceId] == nullptr) { + if (servicesJson_.contains(serviceId) && servicesJson_[serviceId] == nullptr) { nlohmann::json j; j[SERVICE_TYPE] = profile.GetServiceType(); servicesJson_[serviceId] = j; @@ -243,8 +243,12 @@ void DeviceProfileStorageManager::SetServiceType(const std::string& udid, { std::unique_lock autoLock(serviceLock_); if (udid.empty()) { + if (!servicesJson_.contains(serviceId)) { + HILOGE("ServicesJson not contains serviceId!"); + return; + } auto jsonData = servicesJson_[serviceId]; - if (jsonData != nullptr) { + if (jsonData != nullptr && jsonData.contains(SERVICE_TYPE)) { profile.SetServiceType(jsonData[SERVICE_TYPE]); } return; @@ -262,8 +266,12 @@ void DeviceProfileStorageManager::SetServiceType(const std::string& udid, HILOGE("parse error"); return; } + if (!jsonData.contains(serviceId)) { + HILOGE("jsonData don't has serviceId attribute!"); + return; + } auto typeData = jsonData[serviceId]; - if (typeData != nullptr && typeData[SERVICE_TYPE] != nullptr) { + if (typeData != nullptr && typeData.contains(SERVICE_TYPE) && typeData[SERVICE_TYPE] != nullptr) { profile.SetServiceType(typeData[SERVICE_TYPE]); } } @@ -277,7 +285,7 @@ int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serv } std::unique_lock autoLock(serviceLock_); - if (servicesJson_[serviceId] == nullptr) { + if (servicesJson_.contains(serviceId) && servicesJson_[serviceId] == nullptr) { HILOGW("can't find service %{public}s", serviceId.c_str()); return ERR_DP_INVALID_PARAMS; } diff --git a/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp b/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp index ca0652c8d70d643050cbde07d108a095a379eb01..48919ad47d036fc2dd68e11274a1d271e0683f58 100644 --- a/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp +++ b/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp @@ -29,7 +29,7 @@ namespace DistributedDeviceProfile { using namespace OHOS::DistributedKv; namespace { constexpr int32_t MAX_INIT_RETRY_TIMES = 30; - constexpr int32_t INIT_RETRY_SLEEP_INTERVAL = 50 * 1000; // 50ms + constexpr int32_t INIT_RETRY_SLEEP_INTERVAL = 500 * 1000; // 50ms const std::string DATABASE_DIR = "/data/service/el1/public/database/distributed_device_profile_service"; const std::string TAG = "KVAdapter"; } @@ -241,7 +241,7 @@ DistributedKv::Status KVAdapter::GetKvStorePtr() .createIfMissing = true, .encrypt = false, .autoSync = true, - .securityLevel = DistributedKv::SecurityLevel::S0, + .securityLevel = DistributedKv::SecurityLevel::S1, .area = 1, .kvStoreType = KvStoreType::SINGLE_VERSION, .baseDir = DATABASE_DIR