mirror of
https://gitee.com/openharmony/deviceprofile_device_info_manager
synced 2024-11-23 07:30:13 +00:00
refactor dir
Signed-off-by: tangfan <tangfan5@huawei.com>
This commit is contained in:
parent
8b5f8ccf30
commit
e538989b23
15
bundle.json
15
bundle.json
@ -46,19 +46,18 @@
|
||||
"group_type": {
|
||||
"base_group": [],
|
||||
"fwk_group": [
|
||||
"//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core:distributed_device_profile_client"
|
||||
],
|
||||
"//foundation/deviceprofile/device_info_manager/old/interfaces/innerkits/core:distributed_device_profile_client", ],
|
||||
"service_group": [
|
||||
"//foundation/deviceprofile/device_info_manager/etc/profile:deviceprofile_trust",
|
||||
"//foundation/deviceprofile/device_info_manager/etc/init:etc",
|
||||
"//foundation/deviceprofile/device_info_manager/permission:authority_json",
|
||||
"//foundation/deviceprofile/device_info_manager/old/permission:authority_json",
|
||||
"//foundation/deviceprofile/device_info_manager/sa_profile:dps_sa_profile",
|
||||
"//foundation/deviceprofile/device_info_manager/services/core:distributed_device_profile"
|
||||
"//foundation/deviceprofile/device_info_manager/old/services/core:distributed_device_profile",
|
||||
]
|
||||
},
|
||||
"inner_kits": [
|
||||
{
|
||||
"name": "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core:distributed_device_profile_client",
|
||||
"name": "//foundation/deviceprofile/device_info_manager/old/interfaces/innerkits/core:distributed_device_profile_client",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"distributed_device_profile_client.h",
|
||||
@ -70,13 +69,13 @@
|
||||
"service_characteristic_profile.h",
|
||||
"subscribe_info.h"
|
||||
],
|
||||
"header_base": "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core/include/"
|
||||
"header_base": "//foundation/deviceprofile/device_info_manager/old/interfaces/innerkits/core/include/"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//foundation/deviceprofile/device_info_manager/services/core:unittest",
|
||||
"//foundation/deviceprofile/device_info_manager/services/core/test/fuzztest:fuzztest"
|
||||
"//foundation/deviceprofile/device_info_manager/old/services/core:unittest",
|
||||
"//foundation/deviceprofile/device_info_manager/old/services/core/test/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,17 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
device_profile_path = "//foundation/deviceprofile/device_info_manager"
|
||||
old_device_profile_path = "//foundation/deviceprofile/device_info_manager/old"
|
||||
old_device_profile_service =
|
||||
"//foundation/deviceprofile/device_info_manager/old/services"
|
||||
old_device_profile_innerkits =
|
||||
"//foundation/deviceprofile/device_info_manager/old/interfaces/innerkits"
|
||||
old_device_profile_test = "//foundation/deviceprofile/device_info_manager/old/test"
|
||||
|
||||
old_fuzz_test_output_path = "device_info_manager/device_info_manager"
|
||||
|
||||
device_profile_path = "//foundation/deviceprofile/device_info_manager/"
|
||||
device_profile_common = "//foundation/deviceprofile/device_info_manager/common"
|
||||
device_profile_service =
|
||||
"//foundation/deviceprofile/device_info_manager/services"
|
||||
device_profile_innerkits =
|
||||
|
@ -19,7 +19,7 @@ config("distributed_device_profile_client_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${device_profile_path}/common/include",
|
||||
"${old_device_profile_path}/common/include",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
}
|
||||
@ -39,11 +39,11 @@ ohos_shared_library("distributed_device_profile_client") {
|
||||
install_enable = true
|
||||
|
||||
sources = [
|
||||
"${device_profile_path}/common/src/device_profile_utils.cpp",
|
||||
"${device_profile_service}/core/src/profile_change_notification.cpp",
|
||||
"${device_profile_service}/core/src/service_characteristic_profile.cpp",
|
||||
"${device_profile_service}/core/src/subscribemanager/subscribe_info.cpp",
|
||||
"${device_profile_service}/core/src/sync_options.cpp",
|
||||
"${old_device_profile_path}/common/src/device_profile_utils.cpp",
|
||||
"${old_device_profile_service}/core/src/profile_change_notification.cpp",
|
||||
"${old_device_profile_service}/core/src/service_characteristic_profile.cpp",
|
||||
"${old_device_profile_service}/core/src/subscribemanager/subscribe_info.cpp",
|
||||
"${old_device_profile_service}/core/src/sync_options.cpp",
|
||||
"src/callback/device_profile_load_callback.cpp",
|
||||
"src/distributed_device_profile_client.cpp",
|
||||
"src/distributed_device_profile_proxy.cpp",
|
||||
@ -52,7 +52,7 @@ ohos_shared_library("distributed_device_profile_client") {
|
||||
|
||||
public_configs = [
|
||||
":distributed_device_profile_client_config",
|
||||
"${device_profile_test}/resource:coverage_flags",
|
||||
"${old_device_profile_test}/resource:coverage_flags",
|
||||
]
|
||||
|
||||
external_deps = [
|
@ -16,7 +16,7 @@ import("//build/ohos_var.gni")
|
||||
import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni")
|
||||
|
||||
device_profile_common_sources =
|
||||
[ "${device_profile_path}/common/src/device_profile_utils.cpp" ]
|
||||
[ "${old_device_profile_path}/common/src/device_profile_utils.cpp" ]
|
||||
|
||||
config("device_info_manager_config") {
|
||||
visibility = [ ":*" ]
|
||||
@ -29,9 +29,9 @@ config("device_info_manager_config") {
|
||||
"include/dbstorage",
|
||||
"include/dfx",
|
||||
"include/subscribemanager",
|
||||
"${device_profile_path}/common/include",
|
||||
"${device_profile_innerkits}/core/include",
|
||||
"${device_profile_service}/core/include",
|
||||
"${old_device_profile_path}/common/include",
|
||||
"${old_device_profile_innerkits}/core/include",
|
||||
"${old_device_profile_service}/core/include",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
}
|
||||
@ -86,7 +86,7 @@ ohos_shared_library("distributed_device_profile") {
|
||||
|
||||
configs = [
|
||||
":device_info_manager_config",
|
||||
"${device_profile_test}/resource:coverage_flags",
|
||||
"${old_device_profile_test}/resource:coverage_flags",
|
||||
]
|
||||
|
||||
external_deps = [
|
@ -1,60 +1,60 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
|
||||
#define OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "device_auth.h"
|
||||
#include "device_auth_defines.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "event_handler.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
struct GroupInfo {
|
||||
std::string groupName;
|
||||
std::string groupId;
|
||||
std::string groupOwner;
|
||||
int32_t groupType;
|
||||
int32_t groupVisibility;
|
||||
|
||||
GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0) {}
|
||||
};
|
||||
|
||||
void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo);
|
||||
|
||||
class TrustGroupManager {
|
||||
DECLARE_SINGLE_INSTANCE(TrustGroupManager);
|
||||
|
||||
public:
|
||||
bool CheckTrustGroup(const std::string& deviceId);
|
||||
bool InitHichainService();
|
||||
private:
|
||||
static void OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo);
|
||||
static bool CheckDeviceId(const std::string udid);
|
||||
static std::string GetDeviceUdid();
|
||||
void InitDataChangeListener();
|
||||
bool CheckGroupsInfo(const char* returnGroups, uint32_t groupNum);
|
||||
|
||||
private:
|
||||
const DeviceGroupManager* hichainGmInstance_ = nullptr;
|
||||
DataChangeListener dataChangeListener_;
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
|
||||
#define OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "device_auth.h"
|
||||
#include "device_auth_defines.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "event_handler.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
struct GroupInfo {
|
||||
std::string groupName;
|
||||
std::string groupId;
|
||||
std::string groupOwner;
|
||||
int32_t groupType;
|
||||
int32_t groupVisibility;
|
||||
|
||||
GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0) {}
|
||||
};
|
||||
|
||||
void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo);
|
||||
|
||||
class TrustGroupManager {
|
||||
DECLARE_SINGLE_INSTANCE(TrustGroupManager);
|
||||
|
||||
public:
|
||||
bool CheckTrustGroup(const std::string& deviceId);
|
||||
bool InitHichainService();
|
||||
private:
|
||||
static void OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo);
|
||||
static bool CheckDeviceId(const std::string udid);
|
||||
static std::string GetDeviceUdid();
|
||||
void InitDataChangeListener();
|
||||
bool CheckGroupsInfo(const char* returnGroups, uint32_t groupNum);
|
||||
|
||||
private:
|
||||
const DeviceGroupManager* hichainGmInstance_ = nullptr;
|
||||
DataChangeListener dataChangeListener_;
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H
|
@ -1,33 +1,33 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H
|
||||
#define OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H
|
||||
|
||||
#include "content_collector.h"
|
||||
#include "service_characteristic_profile.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
class StorageInfoCollector : public ContentCollector {
|
||||
public:
|
||||
bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override;
|
||||
|
||||
private:
|
||||
int64_t GetTotalSize();
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H
|
||||
#define OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H
|
||||
|
||||
#include "content_collector.h"
|
||||
#include "service_characteristic_profile.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
class StorageInfoCollector : public ContentCollector {
|
||||
public:
|
||||
bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override;
|
||||
|
||||
private:
|
||||
int64_t GetTotalSize();
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H
|
@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H
|
||||
#define OHOS_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "content_collector.h"
|
||||
#include "service_characteristic_profile.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
class SyscapInfoCollector : public ContentCollector {
|
||||
public:
|
||||
bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override;
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
/*
|
||||
* Copyright (c) 2021 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_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H
|
||||
#define OHOS_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "content_collector.h"
|
||||
#include "service_characteristic_profile.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
class SyscapInfoCollector : public ContentCollector {
|
||||
public:
|
||||
bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override;
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H
|
@ -1,39 +1,39 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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_DEVICE_PROFILE_DUMPER_H
|
||||
#define OHOS_DEVICE_PROFILE_DUMPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
class DeviceProfileDumper {
|
||||
public:
|
||||
static bool Dump(const std::vector<std::string>& args, std::string& result);
|
||||
|
||||
private:
|
||||
DeviceProfileDumper() = default;
|
||||
~DeviceProfileDumper() = default;
|
||||
|
||||
static void ShowHelp(std::string& result);
|
||||
static void IllegalInput(std::string& result);
|
||||
static bool CanDump();
|
||||
static bool DumpDefault(std::string& result);
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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_DEVICE_PROFILE_DUMPER_H
|
||||
#define OHOS_DEVICE_PROFILE_DUMPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
class DeviceProfileDumper {
|
||||
public:
|
||||
static bool Dump(const std::vector<std::string>& args, std::string& result);
|
||||
|
||||
private:
|
||||
DeviceProfileDumper() = default;
|
||||
~DeviceProfileDumper() = default;
|
||||
|
||||
static void ShowHelp(std::string& result);
|
||||
static void IllegalInput(std::string& result);
|
||||
static bool CanDump();
|
||||
static bool DumpDefault(std::string& result);
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DEVICE_PROFILE_DUMPER_H
|
@ -1,180 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 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.
|
||||
*/
|
||||
|
||||
#include "trust_group_manager.h"
|
||||
|
||||
#include "device_profile_errors.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_storage_manager.h"
|
||||
#include "device_profile_utils.h"
|
||||
#include "dp_device_manager.h"
|
||||
#include "sync_coordinator.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "TrustGroupManager";
|
||||
|
||||
constexpr int32_t VISIBILITY_PUBLIC = -1;
|
||||
const std::string AUTH_APPID = "device_profile_auth";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(TrustGroupManager);
|
||||
|
||||
void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo)
|
||||
{
|
||||
if (jsonObject.find(FIELD_GROUP_NAME) != jsonObject.end() && jsonObject[FIELD_GROUP_NAME].is_string()) {
|
||||
jsonObject.at(FIELD_GROUP_NAME).get_to(groupInfo.groupName);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end() && jsonObject[FIELD_GROUP_ID].is_string()) {
|
||||
jsonObject.at(FIELD_GROUP_ID).get_to(groupInfo.groupId);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end() && jsonObject[FIELD_GROUP_OWNER].is_string()) {
|
||||
jsonObject.at(FIELD_GROUP_OWNER).get_to(groupInfo.groupOwner);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end() && jsonObject[FIELD_GROUP_TYPE].is_number_integer()) {
|
||||
jsonObject.at(FIELD_GROUP_TYPE).get_to(groupInfo.groupType);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end() &&
|
||||
jsonObject[FIELD_GROUP_VISIBILITY].is_number_integer()) {
|
||||
jsonObject.at(FIELD_GROUP_VISIBILITY).get_to(groupInfo.groupVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
bool TrustGroupManager::InitHichainService()
|
||||
{
|
||||
if (hichainGmInstance_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (InitDeviceAuthService() != ERR_OK) {
|
||||
HILOGE("auth InitDeviceAuthService failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
hichainGmInstance_ = GetGmInstance();
|
||||
if (hichainGmInstance_ == nullptr) {
|
||||
HILOGE("auth GetGmInstance failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
InitDataChangeListener();
|
||||
HILOGI("init succeeded");
|
||||
return true;
|
||||
}
|
||||
|
||||
void TrustGroupManager::InitDataChangeListener()
|
||||
{
|
||||
dataChangeListener_.onDeviceUnBound = OnDeviceUnBoundAdapter;
|
||||
if (hichainGmInstance_->regDataChangeListener(AUTH_APPID.c_str(), &dataChangeListener_) != 0) {
|
||||
HILOGE("auth RegDataChangeListener failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool TrustGroupManager::CheckTrustGroup(const std::string& deviceId)
|
||||
{
|
||||
if (!InitHichainService()) {
|
||||
HILOGE("auth GetGmInstance failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t groupNum = 0;
|
||||
char* returnGroups = nullptr;
|
||||
int32_t ret = hichainGmInstance_->getRelatedGroups(ANY_OS_ACCOUNT, AUTH_APPID.c_str(), deviceId.c_str(),
|
||||
&returnGroups, &groupNum);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("failed, ret:%{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return CheckGroupsInfo(returnGroups, groupNum);
|
||||
}
|
||||
|
||||
bool TrustGroupManager::CheckGroupsInfo(const char* returnGroups, uint32_t groupNum)
|
||||
{
|
||||
if (returnGroups == nullptr || groupNum == 0) {
|
||||
HILOGE("failed, returnGroups is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
nlohmann::json jsonObject = nlohmann::json::parse(returnGroups, nullptr, false);
|
||||
if (jsonObject.is_discarded()) {
|
||||
HILOGE("returnGroups parse error");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
|
||||
for (const auto& groupInfo : groupInfos) {
|
||||
// check group visibility is whether public or not
|
||||
if (groupInfo.groupVisibility != VISIBILITY_PUBLIC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check group type is whether (same count or point to point) or not
|
||||
if (groupInfo.groupType == GroupType::IDENTICAL_ACCOUNT_GROUP
|
||||
|| groupInfo.groupType == GroupType::PEER_TO_PEER_GROUP) {
|
||||
HILOGI("check success type = %{public}d", groupInfo.groupType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
HILOGE("check failed, not in trust group");
|
||||
return false;
|
||||
}
|
||||
|
||||
void TrustGroupManager::OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo)
|
||||
{
|
||||
const std::string udid = peerUdid;
|
||||
if (!CheckDeviceId(udid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto removeUnBoundDeviceTask = [udid = std::move(udid)]() {
|
||||
HILOGI("remove unbound deivce profile start, udid = %{public}s",
|
||||
DeviceProfileUtils::AnonymizeDeviceId(udid).c_str());
|
||||
if (GetInstance().CheckTrustGroup(udid)) {
|
||||
HILOGI("unbound device in trust group");
|
||||
return;
|
||||
}
|
||||
|
||||
if (DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(udid) != ERR_OK) {
|
||||
HILOGE("remove unbound device profile failed, udid = %{public}s",
|
||||
DeviceProfileUtils::AnonymizeDeviceId(udid).c_str());
|
||||
} else {
|
||||
HILOGI("remove unbound deivce profile success, udid = %{public}s",
|
||||
DeviceProfileUtils::AnonymizeDeviceId(udid).c_str());
|
||||
}
|
||||
DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid(udid);
|
||||
};
|
||||
if (!SyncCoordinator::GetInstance().DispatchSyncTask(removeUnBoundDeviceTask)) {
|
||||
HILOGE("post task failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool TrustGroupManager::CheckDeviceId(const std::string udid)
|
||||
{
|
||||
std::string localDeviceId;
|
||||
DpDeviceManager::GetInstance().GetLocalDeviceUdid(localDeviceId);
|
||||
if (udid.empty() || localDeviceId.empty()) {
|
||||
HILOGE("device id is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (udid == localDeviceId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
/*
|
||||
* Copyright (c) 2022-2023 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.
|
||||
*/
|
||||
|
||||
#include "trust_group_manager.h"
|
||||
|
||||
#include "device_profile_errors.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_storage_manager.h"
|
||||
#include "device_profile_utils.h"
|
||||
#include "dp_device_manager.h"
|
||||
#include "sync_coordinator.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "TrustGroupManager";
|
||||
|
||||
constexpr int32_t VISIBILITY_PUBLIC = -1;
|
||||
const std::string AUTH_APPID = "device_profile_auth";
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(TrustGroupManager);
|
||||
|
||||
void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo)
|
||||
{
|
||||
if (jsonObject.find(FIELD_GROUP_NAME) != jsonObject.end() && jsonObject[FIELD_GROUP_NAME].is_string()) {
|
||||
jsonObject.at(FIELD_GROUP_NAME).get_to(groupInfo.groupName);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end() && jsonObject[FIELD_GROUP_ID].is_string()) {
|
||||
jsonObject.at(FIELD_GROUP_ID).get_to(groupInfo.groupId);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end() && jsonObject[FIELD_GROUP_OWNER].is_string()) {
|
||||
jsonObject.at(FIELD_GROUP_OWNER).get_to(groupInfo.groupOwner);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end() && jsonObject[FIELD_GROUP_TYPE].is_number_integer()) {
|
||||
jsonObject.at(FIELD_GROUP_TYPE).get_to(groupInfo.groupType);
|
||||
}
|
||||
if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end() &&
|
||||
jsonObject[FIELD_GROUP_VISIBILITY].is_number_integer()) {
|
||||
jsonObject.at(FIELD_GROUP_VISIBILITY).get_to(groupInfo.groupVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
bool TrustGroupManager::InitHichainService()
|
||||
{
|
||||
if (hichainGmInstance_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (InitDeviceAuthService() != ERR_OK) {
|
||||
HILOGE("auth InitDeviceAuthService failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
hichainGmInstance_ = GetGmInstance();
|
||||
if (hichainGmInstance_ == nullptr) {
|
||||
HILOGE("auth GetGmInstance failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
InitDataChangeListener();
|
||||
HILOGI("init succeeded");
|
||||
return true;
|
||||
}
|
||||
|
||||
void TrustGroupManager::InitDataChangeListener()
|
||||
{
|
||||
dataChangeListener_.onDeviceUnBound = OnDeviceUnBoundAdapter;
|
||||
if (hichainGmInstance_->regDataChangeListener(AUTH_APPID.c_str(), &dataChangeListener_) != 0) {
|
||||
HILOGE("auth RegDataChangeListener failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool TrustGroupManager::CheckTrustGroup(const std::string& deviceId)
|
||||
{
|
||||
if (!InitHichainService()) {
|
||||
HILOGE("auth GetGmInstance failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t groupNum = 0;
|
||||
char* returnGroups = nullptr;
|
||||
int32_t ret = hichainGmInstance_->getRelatedGroups(ANY_OS_ACCOUNT, AUTH_APPID.c_str(), deviceId.c_str(),
|
||||
&returnGroups, &groupNum);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("failed, ret:%{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
return CheckGroupsInfo(returnGroups, groupNum);
|
||||
}
|
||||
|
||||
bool TrustGroupManager::CheckGroupsInfo(const char* returnGroups, uint32_t groupNum)
|
||||
{
|
||||
if (returnGroups == nullptr || groupNum == 0) {
|
||||
HILOGE("failed, returnGroups is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
nlohmann::json jsonObject = nlohmann::json::parse(returnGroups, nullptr, false);
|
||||
if (jsonObject.is_discarded()) {
|
||||
HILOGE("returnGroups parse error");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
|
||||
for (const auto& groupInfo : groupInfos) {
|
||||
// check group visibility is whether public or not
|
||||
if (groupInfo.groupVisibility != VISIBILITY_PUBLIC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check group type is whether (same count or point to point) or not
|
||||
if (groupInfo.groupType == GroupType::IDENTICAL_ACCOUNT_GROUP
|
||||
|| groupInfo.groupType == GroupType::PEER_TO_PEER_GROUP) {
|
||||
HILOGI("check success type = %{public}d", groupInfo.groupType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
HILOGE("check failed, not in trust group");
|
||||
return false;
|
||||
}
|
||||
|
||||
void TrustGroupManager::OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo)
|
||||
{
|
||||
const std::string udid = peerUdid;
|
||||
if (!CheckDeviceId(udid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto removeUnBoundDeviceTask = [udid = std::move(udid)]() {
|
||||
HILOGI("remove unbound deivce profile start, udid = %{public}s",
|
||||
DeviceProfileUtils::AnonymizeDeviceId(udid).c_str());
|
||||
if (GetInstance().CheckTrustGroup(udid)) {
|
||||
HILOGI("unbound device in trust group");
|
||||
return;
|
||||
}
|
||||
|
||||
if (DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(udid) != ERR_OK) {
|
||||
HILOGE("remove unbound device profile failed, udid = %{public}s",
|
||||
DeviceProfileUtils::AnonymizeDeviceId(udid).c_str());
|
||||
} else {
|
||||
HILOGI("remove unbound deivce profile success, udid = %{public}s",
|
||||
DeviceProfileUtils::AnonymizeDeviceId(udid).c_str());
|
||||
}
|
||||
DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid(udid);
|
||||
};
|
||||
if (!SyncCoordinator::GetInstance().DispatchSyncTask(removeUnBoundDeviceTask)) {
|
||||
HILOGE("post task failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool TrustGroupManager::CheckDeviceId(const std::string udid)
|
||||
{
|
||||
std::string localDeviceId;
|
||||
DpDeviceManager::GetInstance().GetLocalDeviceUdid(localDeviceId);
|
||||
if (udid.empty() || localDeviceId.empty()) {
|
||||
HILOGE("device id is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (udid == localDeviceId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
@ -1,62 +1,62 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "storage_info_collector.h"
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include "device_profile_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "StorageInfoCollector";
|
||||
|
||||
const char* PATH_DATA = "/data";
|
||||
const std::string SERVICE_ID = "storage";
|
||||
const std::string SERVICE_TYPE = "storage";
|
||||
const std::string CAPACITY = "capacity";
|
||||
constexpr int64_t KILOBYTE = 1024;
|
||||
}
|
||||
|
||||
bool StorageInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile)
|
||||
{
|
||||
profile.SetServiceId(SERVICE_ID);
|
||||
profile.SetServiceType(SERVICE_TYPE);
|
||||
nlohmann::json jsonData;
|
||||
int64_t totalSize = GetTotalSize();
|
||||
if (totalSize == 0) {
|
||||
return false;
|
||||
}
|
||||
jsonData[CAPACITY] = totalSize;
|
||||
profile.SetCharacteristicProfileJson(jsonData.dump());
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t StorageInfoCollector::GetTotalSize()
|
||||
{
|
||||
int64_t totalSize = 0;
|
||||
struct statvfs diskInfo;
|
||||
int ret = statvfs(PATH_DATA, &diskInfo);
|
||||
if (ret != 0) {
|
||||
HILOGE("GetTotalSize failed");
|
||||
return totalSize;
|
||||
}
|
||||
totalSize = (int64_t)diskInfo.f_bsize * (int64_t)diskInfo.f_blocks / KILOBYTE;
|
||||
return totalSize;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
} // OHOS
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "storage_info_collector.h"
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include "device_profile_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "StorageInfoCollector";
|
||||
|
||||
const char* PATH_DATA = "/data";
|
||||
const std::string SERVICE_ID = "storage";
|
||||
const std::string SERVICE_TYPE = "storage";
|
||||
const std::string CAPACITY = "capacity";
|
||||
constexpr int64_t KILOBYTE = 1024;
|
||||
}
|
||||
|
||||
bool StorageInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile)
|
||||
{
|
||||
profile.SetServiceId(SERVICE_ID);
|
||||
profile.SetServiceType(SERVICE_TYPE);
|
||||
nlohmann::json jsonData;
|
||||
int64_t totalSize = GetTotalSize();
|
||||
if (totalSize == 0) {
|
||||
return false;
|
||||
}
|
||||
jsonData[CAPACITY] = totalSize;
|
||||
profile.SetCharacteristicProfileJson(jsonData.dump());
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t StorageInfoCollector::GetTotalSize()
|
||||
{
|
||||
int64_t totalSize = 0;
|
||||
struct statvfs diskInfo;
|
||||
int ret = statvfs(PATH_DATA, &diskInfo);
|
||||
if (ret != 0) {
|
||||
HILOGE("GetTotalSize failed");
|
||||
return totalSize;
|
||||
}
|
||||
totalSize = (int64_t)diskInfo.f_bsize * (int64_t)diskInfo.f_blocks / KILOBYTE;
|
||||
return totalSize;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
} // OHOS
|
@ -1,75 +1,75 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "syscap_info_collector.h"
|
||||
|
||||
#include "device_profile_errors.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "parameters.h"
|
||||
#include "syscap_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "SyscapInfoCollector";
|
||||
|
||||
const std::string SERVICE_ID = "syscap";
|
||||
const std::string SERVICE_TYPE = "syscap";
|
||||
const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap";
|
||||
const std::string CHARACTER_OS_SYSCAP = "ossyscap";
|
||||
constexpr int32_t MAX_DATALEN = 1128;
|
||||
constexpr int32_t INT_BYTES_LEN = 4;
|
||||
}
|
||||
|
||||
bool SyscapInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile)
|
||||
{
|
||||
profile.SetServiceId(SERVICE_ID);
|
||||
profile.SetServiceType(SERVICE_TYPE);
|
||||
|
||||
char osBuffer[PCID_MAIN_BYTES];
|
||||
if (!EncodeOsSyscap(osBuffer, PCID_MAIN_BYTES)) {
|
||||
HILOGE("EncodeOsSyscap failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<int32_t> osSyscapData;
|
||||
for (int i = 0; i < PCID_MAIN_BYTES/INT_BYTES_LEN; i++) {
|
||||
int32_t value = *((int32_t *)osBuffer + i);
|
||||
osSyscapData.push_back(value);
|
||||
}
|
||||
|
||||
nlohmann::json jsonData;
|
||||
nlohmann::json osSyscapJsonData(osSyscapData);
|
||||
jsonData[CHARACTER_OS_SYSCAP] = osSyscapJsonData;
|
||||
|
||||
char* privateBuffer = nullptr;
|
||||
int32_t privateBufferLen;
|
||||
if (!EncodePrivateSyscap(&privateBuffer, &privateBufferLen)) {
|
||||
HILOGE("EncodePrivateSyscap failed");
|
||||
return false;
|
||||
}
|
||||
if (privateBufferLen + PCID_MAIN_BYTES > MAX_DATALEN) {
|
||||
free(privateBuffer);
|
||||
HILOGI("syscap data length too long");
|
||||
return false;
|
||||
}
|
||||
jsonData[CHARACTER_PRIVATE_SYSCAP] = privateBuffer;
|
||||
free(privateBuffer);
|
||||
profile.SetCharacteristicProfileJson(jsonData.dump());
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "syscap_info_collector.h"
|
||||
|
||||
#include "device_profile_errors.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "parameters.h"
|
||||
#include "syscap_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "SyscapInfoCollector";
|
||||
|
||||
const std::string SERVICE_ID = "syscap";
|
||||
const std::string SERVICE_TYPE = "syscap";
|
||||
const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap";
|
||||
const std::string CHARACTER_OS_SYSCAP = "ossyscap";
|
||||
constexpr int32_t MAX_DATALEN = 1128;
|
||||
constexpr int32_t INT_BYTES_LEN = 4;
|
||||
}
|
||||
|
||||
bool SyscapInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile)
|
||||
{
|
||||
profile.SetServiceId(SERVICE_ID);
|
||||
profile.SetServiceType(SERVICE_TYPE);
|
||||
|
||||
char osBuffer[PCID_MAIN_BYTES];
|
||||
if (!EncodeOsSyscap(osBuffer, PCID_MAIN_BYTES)) {
|
||||
HILOGE("EncodeOsSyscap failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<int32_t> osSyscapData;
|
||||
for (int i = 0; i < PCID_MAIN_BYTES/INT_BYTES_LEN; i++) {
|
||||
int32_t value = *((int32_t *)osBuffer + i);
|
||||
osSyscapData.push_back(value);
|
||||
}
|
||||
|
||||
nlohmann::json jsonData;
|
||||
nlohmann::json osSyscapJsonData(osSyscapData);
|
||||
jsonData[CHARACTER_OS_SYSCAP] = osSyscapJsonData;
|
||||
|
||||
char* privateBuffer = nullptr;
|
||||
int32_t privateBufferLen;
|
||||
if (!EncodePrivateSyscap(&privateBuffer, &privateBufferLen)) {
|
||||
HILOGE("EncodePrivateSyscap failed");
|
||||
return false;
|
||||
}
|
||||
if (privateBufferLen + PCID_MAIN_BYTES > MAX_DATALEN) {
|
||||
free(privateBuffer);
|
||||
HILOGI("syscap data length too long");
|
||||
return false;
|
||||
}
|
||||
jsonData[CHARACTER_PRIVATE_SYSCAP] = privateBuffer;
|
||||
free(privateBuffer);
|
||||
profile.SetCharacteristicProfileJson(jsonData.dump());
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
@ -1,82 +1,82 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "device_profile_dumper.h"
|
||||
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_storage_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
constexpr size_t MIN_ARGS_SIZE = 1;
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string TAG = "DeviceProfileDumper";
|
||||
constexpr int32_t UID_HIDUMPER = 1212;
|
||||
}
|
||||
|
||||
bool DeviceProfileDumper::DumpDefault(std::string& result)
|
||||
{
|
||||
result.append("DeviceProfile Dump:\n");
|
||||
DeviceProfileStorageManager::GetInstance().DumpLocalProfile(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceProfileDumper::Dump(const std::vector<std::string>& args, std::string& result)
|
||||
{
|
||||
result.clear();
|
||||
if (!CanDump()) {
|
||||
result.append("Dump failed, not allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() < MIN_ARGS_SIZE) {
|
||||
return DumpDefault(result);
|
||||
}
|
||||
|
||||
if (args.size() == MIN_ARGS_SIZE) {
|
||||
// -h
|
||||
if (args[0] == ARGS_HELP) {
|
||||
ShowHelp(result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
IllegalInput(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeviceProfileDumper::ShowHelp(std::string& result)
|
||||
{
|
||||
result.append("DeviceProfile Dump options:\n")
|
||||
.append(" [-h] [cmd]...\n");
|
||||
}
|
||||
|
||||
void DeviceProfileDumper::IllegalInput(std::string& result)
|
||||
{
|
||||
result.append("The arguments are illegal and you can enter '-h' for help.\n");
|
||||
}
|
||||
|
||||
bool DeviceProfileDumper::CanDump()
|
||||
{
|
||||
auto callingUid = IPCSkeleton::GetCallingUid();
|
||||
HILOGI("calling uid = %u", callingUid);
|
||||
if (callingUid != UID_HIDUMPER) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "device_profile_dumper.h"
|
||||
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_storage_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
constexpr size_t MIN_ARGS_SIZE = 1;
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string TAG = "DeviceProfileDumper";
|
||||
constexpr int32_t UID_HIDUMPER = 1212;
|
||||
}
|
||||
|
||||
bool DeviceProfileDumper::DumpDefault(std::string& result)
|
||||
{
|
||||
result.append("DeviceProfile Dump:\n");
|
||||
DeviceProfileStorageManager::GetInstance().DumpLocalProfile(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceProfileDumper::Dump(const std::vector<std::string>& args, std::string& result)
|
||||
{
|
||||
result.clear();
|
||||
if (!CanDump()) {
|
||||
result.append("Dump failed, not allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() < MIN_ARGS_SIZE) {
|
||||
return DumpDefault(result);
|
||||
}
|
||||
|
||||
if (args.size() == MIN_ARGS_SIZE) {
|
||||
// -h
|
||||
if (args[0] == ARGS_HELP) {
|
||||
ShowHelp(result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
IllegalInput(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeviceProfileDumper::ShowHelp(std::string& result)
|
||||
{
|
||||
result.append("DeviceProfile Dump options:\n")
|
||||
.append(" [-h] [cmd]...\n");
|
||||
}
|
||||
|
||||
void DeviceProfileDumper::IllegalInput(std::string& result)
|
||||
{
|
||||
result.append("The arguments are illegal and you can enter '-h' for help.\n");
|
||||
}
|
||||
|
||||
bool DeviceProfileDumper::CanDump()
|
||||
{
|
||||
auto callingUid = IPCSkeleton::GetCallingUid();
|
||||
HILOGI("calling uid = %u", callingUid);
|
||||
if (callingUid != UID_HIDUMPER) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
@ -19,13 +19,13 @@ import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni")
|
||||
module_output_path = "device_info_manager/deviceprofiletest"
|
||||
|
||||
device_profile_configs = [
|
||||
"${device_profile_service}/core:device_info_manager_config",
|
||||
"${device_profile_test}/resource:coverage_flags",
|
||||
"${old_device_profile_service}/core:device_info_manager_config",
|
||||
"${old_device_profile_test}/resource:coverage_flags",
|
||||
]
|
||||
|
||||
device_profile_deps = [
|
||||
"${device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${device_profile_service}/core:distributed_device_profile",
|
||||
"${old_device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${old_device_profile_service}/core:distributed_device_profile",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
@ -16,16 +16,16 @@ import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni")
|
||||
module_output_path = fuzz_test_output_path
|
||||
module_output_path = old_fuzz_test_output_path
|
||||
|
||||
device_profile_configs = [
|
||||
"${device_profile_service}/core:device_info_manager_config",
|
||||
"${device_profile_test}/resource:coverage_flags",
|
||||
"${old_device_profile_service}/core:device_info_manager_config",
|
||||
"${old_device_profile_test}/resource:coverage_flags",
|
||||
]
|
||||
|
||||
device_profile_deps = [
|
||||
"${device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${device_profile_service}/core:distributed_device_profile",
|
||||
"${old_device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${old_device_profile_service}/core:distributed_device_profile",
|
||||
]
|
||||
|
||||
##############################fuzztest##########################################
|
||||
@ -33,7 +33,7 @@ ohos_fuzztest("DeviceProfileFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${device_profile_service}/core/test/fuzztest/deviceprofile_fuzzer"
|
||||
"${old_device_profile_service}/core/test/fuzztest/deviceprofile_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
@ -1,16 +1,16 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
FUZZ
|
@ -1,114 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 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.
|
||||
*/
|
||||
|
||||
#include "device_profile_fuzzer.h"
|
||||
|
||||
#include "iremote_stub.h"
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "distributed_device_profile_service.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include "sys/stat.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
constexpr size_t THRESHOLD = 10;
|
||||
constexpr uint8_t MAX_CALL_TRANSACTION = 7;
|
||||
constexpr int32_t OFFSET = 4;
|
||||
int32_t ZERO_BIT = 0;
|
||||
int32_t FIRST_BIT = 1;
|
||||
int32_t SECOND_BIT = 2;
|
||||
int32_t THIRD_BIT = 3;
|
||||
int32_t ZERO_MOVE_LEN = 24;
|
||||
int32_t FIRST_MOVE_LEN = 16;
|
||||
int32_t SECOND_MOVE_LEN = 8;
|
||||
bool flag_ = false;
|
||||
const std::u16string DP_INTERFACE_TOKEN = u"OHOS.DeviceProfile.IDistributedDeviceProfile";
|
||||
}
|
||||
|
||||
uint32_t Convert2Uint32(const uint8_t* ptr)
|
||||
{
|
||||
if (ptr == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return (ptr[ZERO_BIT] << ZERO_MOVE_LEN) | (ptr[FIRST_BIT] << FIRST_MOVE_LEN) |
|
||||
(ptr[SECOND_BIT] << SECOND_MOVE_LEN) | (ptr[THIRD_BIT]);
|
||||
}
|
||||
|
||||
void MockPermission(const char* processName)
|
||||
{
|
||||
static const char *perms[] = {
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
};
|
||||
|
||||
uint64_t tokenId;
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = 1,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = processName,
|
||||
.aplStr = "system_core",
|
||||
};
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
|
||||
void FuzzDeviceProfile(const uint8_t* rawData, size_t size)
|
||||
{
|
||||
MockPermission("distributedsched");
|
||||
uint32_t code = Convert2Uint32(rawData);
|
||||
rawData = rawData + OFFSET;
|
||||
size = size - OFFSET;
|
||||
MessageParcel data;
|
||||
data.WriteInterfaceToken(DP_INTERFACE_TOKEN);
|
||||
data.WriteBuffer(rawData, size);
|
||||
data.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string baseDir = "/data/service/el1/public/database/distributed_device_profile_service";
|
||||
mkdir(baseDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
if (!flag_) {
|
||||
DistributedDeviceProfileService::GetInstance().Init();
|
||||
flag_ = true;
|
||||
}
|
||||
DistributedDeviceProfileService::GetInstance().OnRemoteRequest(code % MAX_CALL_TRANSACTION, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (size < OHOS::DeviceProfile::THRESHOLD) {
|
||||
return 0;
|
||||
}
|
||||
OHOS::DeviceProfile::FuzzDeviceProfile(data, size);
|
||||
return 0;
|
||||
/*
|
||||
* Copyright (c) 2022-2023 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.
|
||||
*/
|
||||
|
||||
#include "device_profile_fuzzer.h"
|
||||
|
||||
#include "iremote_stub.h"
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "distributed_device_profile_service.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include "sys/stat.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
constexpr size_t THRESHOLD = 10;
|
||||
constexpr uint8_t MAX_CALL_TRANSACTION = 7;
|
||||
constexpr int32_t OFFSET = 4;
|
||||
int32_t ZERO_BIT = 0;
|
||||
int32_t FIRST_BIT = 1;
|
||||
int32_t SECOND_BIT = 2;
|
||||
int32_t THIRD_BIT = 3;
|
||||
int32_t ZERO_MOVE_LEN = 24;
|
||||
int32_t FIRST_MOVE_LEN = 16;
|
||||
int32_t SECOND_MOVE_LEN = 8;
|
||||
bool flag_ = false;
|
||||
const std::u16string DP_INTERFACE_TOKEN = u"OHOS.DeviceProfile.IDistributedDeviceProfile";
|
||||
}
|
||||
|
||||
uint32_t Convert2Uint32(const uint8_t* ptr)
|
||||
{
|
||||
if (ptr == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return (ptr[ZERO_BIT] << ZERO_MOVE_LEN) | (ptr[FIRST_BIT] << FIRST_MOVE_LEN) |
|
||||
(ptr[SECOND_BIT] << SECOND_MOVE_LEN) | (ptr[THIRD_BIT]);
|
||||
}
|
||||
|
||||
void MockPermission(const char* processName)
|
||||
{
|
||||
static const char *perms[] = {
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
};
|
||||
|
||||
uint64_t tokenId;
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = 1,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = processName,
|
||||
.aplStr = "system_core",
|
||||
};
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
|
||||
void FuzzDeviceProfile(const uint8_t* rawData, size_t size)
|
||||
{
|
||||
MockPermission("distributedsched");
|
||||
uint32_t code = Convert2Uint32(rawData);
|
||||
rawData = rawData + OFFSET;
|
||||
size = size - OFFSET;
|
||||
MessageParcel data;
|
||||
data.WriteInterfaceToken(DP_INTERFACE_TOKEN);
|
||||
data.WriteBuffer(rawData, size);
|
||||
data.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
std::string baseDir = "/data/service/el1/public/database/distributed_device_profile_service";
|
||||
mkdir(baseDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
if (!flag_) {
|
||||
DistributedDeviceProfileService::GetInstance().Init();
|
||||
flag_ = true;
|
||||
}
|
||||
DistributedDeviceProfileService::GetInstance().OnRemoteRequest(code % MAX_CALL_TRANSACTION, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (size < OHOS::DeviceProfile::THRESHOLD) {
|
||||
return 0;
|
||||
}
|
||||
OHOS::DeviceProfile::FuzzDeviceProfile(data, size);
|
||||
return 0;
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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 DEVICE_PROFILE_FUZZER_H
|
||||
#define DEVICE_PROFILE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "device_profile_fuzzer"
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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 DEVICE_PROFILE_FUZZER_H
|
||||
#define DEVICE_PROFILE_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "device_profile_fuzzer"
|
||||
|
||||
#endif
|
@ -1,25 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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
|
||||
|
||||
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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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
|
||||
|
||||
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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -16,11 +16,11 @@ import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni")
|
||||
module_output_path = fuzz_test_output_path
|
||||
module_output_path = old_fuzz_test_output_path
|
||||
|
||||
device_profile_configs = [
|
||||
"${device_profile_service}/core:device_info_manager_config",
|
||||
"${device_profile_test}/resource:coverage_flags",
|
||||
"${old_device_profile_service}/core:device_info_manager_config",
|
||||
"${old_device_profile_test}/resource:coverage_flags",
|
||||
]
|
||||
|
||||
device_profile_external_deps = [
|
||||
@ -38,8 +38,8 @@ device_profile_external_deps = [
|
||||
]
|
||||
|
||||
device_profile_deps = [
|
||||
"${device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${device_profile_service}/core:distributed_device_profile",
|
||||
"${old_device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${old_device_profile_service}/core:distributed_device_profile",
|
||||
]
|
||||
|
||||
##############################fuzztest##########################################
|
||||
@ -47,7 +47,7 @@ ohos_fuzztest("DumpLocalProfileFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${device_profile_service}/core/test/fuzztest/dumplocalprofile_fuzzer"
|
||||
"${old_device_profile_service}/core/test/fuzztest/dumplocalprofile_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
@ -16,11 +16,11 @@ import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni")
|
||||
module_output_path = fuzz_test_output_path
|
||||
module_output_path = old_fuzz_test_output_path
|
||||
|
||||
device_profile_configs = [
|
||||
"${device_profile_service}/core:device_info_manager_config",
|
||||
"${device_profile_test}/resource:coverage_flags",
|
||||
"${old_device_profile_service}/core:device_info_manager_config",
|
||||
"${old_device_profile_test}/resource:coverage_flags",
|
||||
]
|
||||
|
||||
device_profile_external_deps = [
|
||||
@ -38,8 +38,8 @@ device_profile_external_deps = [
|
||||
]
|
||||
|
||||
device_profile_deps = [
|
||||
"${device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${device_profile_service}/core:distributed_device_profile",
|
||||
"${old_device_profile_innerkits}/core:distributed_device_profile_client",
|
||||
"${old_device_profile_service}/core:distributed_device_profile",
|
||||
]
|
||||
|
||||
##############################fuzztest##########################################
|
||||
@ -47,7 +47,7 @@ ohos_fuzztest("GetDeviceProfileFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
fuzz_config_file =
|
||||
"${device_profile_service}/core/test/fuzztest/getdeviceprofile_fuzzer"
|
||||
"${old_device_profile_service}/core/test/fuzztest/getdeviceprofile_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user