mirror of
https://github.com/openharmony/device_profile_core.git
synced 2026-06-30 22:17:58 -04:00
@@ -13,6 +13,9 @@
|
||||
"name": "device_profile_core",
|
||||
"subsystem": "deviceprofile",
|
||||
"adapted_system_type": [ "standard" ],
|
||||
"hisysevent_config":[
|
||||
"//foundation/deviceprofile/device_profile_core/hisysevent.yaml"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
|
||||
@@ -0,0 +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.
|
||||
|
||||
domain: DEVICE_PROFILE
|
||||
|
||||
DEVICE_PROFILE_SYNC_EVENT:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceProfileSyn, desc: device profile sync}
|
||||
|
||||
DEVICE_PROFILE_SYNC_FAILED:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: device profile sync failed}
|
||||
FAULT_CODE: {type: INT32, desc: fault code}
|
||||
@@ -16,6 +16,7 @@ import("//build/ohos_var.gni")
|
||||
|
||||
device_profile_path = "//foundation/deviceprofile/device_profile_core"
|
||||
device_profile_innerkits = "${device_profile_path}/interfaces/innerkits"
|
||||
services = "${device_profile_path}/services"
|
||||
device_profile_common_sources =
|
||||
[ "${device_profile_path}/common/src/device_profile_utils.cpp" ]
|
||||
|
||||
@@ -30,6 +31,7 @@ config("device_profile_core_config") {
|
||||
"include/subscribemanager",
|
||||
"${device_profile_path}/common/include",
|
||||
"${device_profile_innerkits}/core/include",
|
||||
"${services}/core/include",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
}
|
||||
@@ -51,6 +53,7 @@ ohos_shared_library("distributed_device_profile") {
|
||||
"src/dbstorage/sync_coordinator.cpp",
|
||||
"src/devicemanager/device_info.cpp",
|
||||
"src/devicemanager/device_manager.cpp",
|
||||
"src/dfx/hisysevent_report.cpp",
|
||||
"src/distributed_device_profile_service.cpp",
|
||||
"src/distributed_device_profile_stub.cpp",
|
||||
"src/profile_change_notification.cpp",
|
||||
@@ -76,6 +79,8 @@ ohos_shared_library("distributed_device_profile") {
|
||||
"distributeddatamgr:distributeddata_inner",
|
||||
"dsoftbus:softbus_client",
|
||||
"eventhandler:libeventhandler",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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_DEVICEPROFILE_HISTSEVENT_REPORT_H
|
||||
#define OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H
|
||||
|
||||
#include "hisysevent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace BehaviorEvent{
|
||||
const std::string DEVICE_PROFILE_SYNC_EVENT = "DEVICE_PROFILE_SYNC_EVENT";
|
||||
}
|
||||
|
||||
namespace FaultEvent{
|
||||
const std::string DEVICE_PROFILE_SYNC_FAILED = "DEVICE_PROFILE_SYNC_FAILED";
|
||||
}
|
||||
|
||||
namespace ErrorType{
|
||||
const std::string FAULT_CODE_KEY = "FAULT_CODE";
|
||||
}
|
||||
const std::string DOMAIN_NAME = std::string(OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE);
|
||||
|
||||
class DpHiSysEventReport {
|
||||
public:
|
||||
static int ReportSyncBehavior(const std::string& eventName);
|
||||
static int ReportSyncFault(const std::string& faultName, const int32_t code);
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
|
||||
#endif /* OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H */
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_DEVICEPROFILE_HITRACE_REPORT_H
|
||||
#define OHOS_DEVICEPROFILE_HITRACE_REPORT_H
|
||||
|
||||
#include "hisysevent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
const std::string DP_DEVICE_PUT_TRACE = "DP_DEVICE_PUT";
|
||||
const std::string DP_DEVICE_GET_TRACE = "DP_DEVICE_GET";
|
||||
const std::string DP_DEVICE_DELETE_TRACE = "DP_DEVICE_DELETE";
|
||||
const std::string DP_DEVICE_SYNC_TRACE = "DP_DEVICE_SYNC";
|
||||
const std::string DP_DEVICE_SUB_TRACE = "DP_DEVICE_SUB";
|
||||
const std::string DP_CONTENT_SENSOR_TRACE = "DP_CONTENT_SENSOR";
|
||||
}
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
|
||||
#endif /* OHOS_DEVICEPROFILE_HITRACE_REPORT_H */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-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
|
||||
@@ -17,9 +17,12 @@
|
||||
|
||||
#include "device_info_collector.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "dfx/dp_hitrace_report.h"
|
||||
#include "syscap_info_collector.h"
|
||||
#include "system_info_collector.h"
|
||||
|
||||
#include "hitrace_meter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
@@ -46,6 +49,7 @@ bool ContentSensorManager::Collect()
|
||||
taskList.push_back(std::make_shared<DeviceInfoCollector>());
|
||||
taskList.push_back(std::make_shared<SystemInfoCollector>());
|
||||
taskList.push_back(std::make_shared<SyscapInfoCollector>());
|
||||
HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_CONTENT_SENSOR_TRACE);
|
||||
for (auto& task : taskList) {
|
||||
ServiceCharacteristicProfile profileData;
|
||||
if (!task->ConvertToProfileData(profileData)) {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_storage_manager.h"
|
||||
#include "device_profile_utils.h"
|
||||
#include "dfx/dp_hisysevent_report.h"
|
||||
#include "dfx/dp_hitrace_report.h"
|
||||
#include "service_characteristic_profile.h"
|
||||
#include "trust_group_manager.h"
|
||||
|
||||
@@ -270,7 +272,6 @@ int32_t DeviceProfileStorage::SyncDeviceProfile(const std::vector<std::string>&
|
||||
int32_t DeviceProfileStorage::RemoveDeviceData(const std::string networkId)
|
||||
{
|
||||
HILOGI("called");
|
||||
|
||||
std::unique_lock<std::shared_mutex> writeLock(storageLock_);
|
||||
if (kvStorePtr_ == nullptr) {
|
||||
HILOGE("null kvstore");
|
||||
|
||||
@@ -18,12 +18,17 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "device_manager.h"
|
||||
#include "device_profile_errors.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_utils.h"
|
||||
#include "dfx/dp_hisysevent_report.h"
|
||||
#include "dfx/dp_hitrace_report.h"
|
||||
#include "sync_coordinator.h"
|
||||
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_object_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
@@ -127,6 +132,7 @@ std::string DeviceProfileStorageManager::GenerateKey(const std::string& udid,
|
||||
|
||||
int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristicProfile& profile)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_PUT_TRACE);
|
||||
if (kvDataServiceFailed_ || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) {
|
||||
HILOGE("kvstore init failed");
|
||||
return ERR_DP_INIT_DB_FAILED;
|
||||
@@ -165,6 +171,7 @@ int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristi
|
||||
int32_t DeviceProfileStorageManager::GetDeviceProfile(const std::string& udid,
|
||||
const std::string& serviceId, ServiceCharacteristicProfile& profile)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_GET_TRACE);
|
||||
if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) {
|
||||
HILOGE("kvstore init failed");
|
||||
return ERR_DP_INIT_DB_FAILED;
|
||||
@@ -231,6 +238,7 @@ void DeviceProfileStorageManager::SetServiceType(const std::string& udid,
|
||||
|
||||
int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serviceId)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_DELETE_TRACE);
|
||||
if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) {
|
||||
HILOGE("kvstore init failed");
|
||||
return ERR_DP_INIT_DB_FAILED;
|
||||
@@ -309,14 +317,24 @@ int32_t DeviceProfileStorageManager::SyncDeviceProfile(const SyncOptions& syncOp
|
||||
|
||||
auto syncTask = [syncOptions, this]() {
|
||||
HILOGI("start sync");
|
||||
int ret = DpHiSysEventReport::ReportSyncBehavior(BehaviorEvent::DEVICE_PROFILE_SYNC_EVENT);
|
||||
if (ret != 0) {
|
||||
HILOGE("hisysevent write failed! ret %{public}d.", ret);
|
||||
}
|
||||
|
||||
auto devicesList = syncOptions.GetDeviceList();
|
||||
if (devicesList.empty()) {
|
||||
DeviceManager::GetInstance().GetDeviceIdList(devicesList);
|
||||
}
|
||||
|
||||
SyncCoordinator::GetInstance().SetSyncTrigger(false);
|
||||
std::vector<std::string> devicesVector(std::vector<std::string> { devicesList.begin(), devicesList.end() });
|
||||
int32_t result = onlineSyncTbl_->SyncDeviceProfile(devicesVector, syncOptions.GetSyncMode());
|
||||
if (result != ERR_OK) {
|
||||
int ret = DpHiSysEventReport::ReportSyncFault(FaultEvent::DEVICE_PROFILE_SYNC_FAILED, result);
|
||||
if (ret != 0) {
|
||||
HILOGE("hisysevent write failed! ret %{public}d.", ret);
|
||||
}
|
||||
HILOGE("sync failed result : %{public}d", result);
|
||||
NotifySyncCompleted();
|
||||
return;
|
||||
@@ -337,6 +355,8 @@ int32_t DeviceProfileStorageManager::NotifySyncStart(const sptr<IRemoteObject>&
|
||||
return ERR_DP_DEVICE_SYNC_BUSY;
|
||||
}
|
||||
|
||||
StartAsyncTrace(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE, getpid());
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(profileSyncLock_);
|
||||
syncEventNotifier_ = profileEventNotifier;
|
||||
@@ -362,6 +382,7 @@ void DeviceProfileStorageManager::NotifySyncCompleted()
|
||||
{
|
||||
HILOGI("called");
|
||||
SyncCoordinator::GetInstance().ReleaseSync();
|
||||
FinishAsyncTrace(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE, getpid());
|
||||
std::lock_guard<std::mutex> autoLock(profileSyncLock_);
|
||||
std::list<ProfileEvent> profileEvents;
|
||||
profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 "dfx/dp_hisysevent_report.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace {
|
||||
const std::string TAG = "DpHiSysEventReport";
|
||||
}
|
||||
|
||||
int DpHiSysEventReport::ReportSyncBehavior(const std::string& eventName)
|
||||
{
|
||||
int ret = HiSysEvent::Write(DOMAIN_NAME, eventName, HiSysEvent::EventType::BEHAVIOR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DpHiSysEventReport::ReportSyncFault(const std::string& faultName, const int32_t code)
|
||||
{
|
||||
int ret = HiSysEvent::Write(DOMAIN_NAME, faultName, HiSysEvent::EventType::FAULT, FAULT_CODE_KEY, code);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,15 @@
|
||||
#include "device_profile_errors.h"
|
||||
#include "device_profile_log.h"
|
||||
#include "device_profile_storage_manager.h"
|
||||
#include "dfx/dp_hitrace_report.h"
|
||||
#include "service_characteristic_profile.h"
|
||||
#include "subscribe_manager.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "trust_group_manager.h"
|
||||
|
||||
#include "hitrace_meter.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace {
|
||||
@@ -95,6 +99,7 @@ int32_t DistributedDeviceProfileService::SubscribeProfileEvents(const std::list<
|
||||
const sptr<IRemoteObject>& profileEventNotifier,
|
||||
std::list<ProfileEvent>& failedEvents)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE);
|
||||
return SubscribeManager::GetInstance().SubscribeProfileEvents(subscribeInfos,
|
||||
profileEventNotifier, failedEvents);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ device_profile_deps = [
|
||||
device_profile_external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"eventhandler:libeventhandler",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"syscap_codec:syscap_interface_shared",
|
||||
@@ -41,7 +42,10 @@ device_profile_external_deps = [
|
||||
ohos_unittest("profile_crud_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [ "unittest/profile_crud_test.cpp" ]
|
||||
sources = [
|
||||
"unittest/dp_hisysevent_report.cpp",
|
||||
"unittest/profile_crud_test.cpp",
|
||||
]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 "dfx/dp_hisysevent_report.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace {
|
||||
const std::string TAG = "DpHiSysEventReport";
|
||||
}
|
||||
|
||||
int DpHiSysEventReport::ReportSyncFault(const std::string& faultName, const int32_t code)
|
||||
{
|
||||
int ret = HiSysEvent::Write(DOMAIN_NAME, faultName, HiSysEvent::EventType::FAULT, FAULT_CODE_KEY, code);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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_DEVICEPROFILE_HISTSEVENT_REPORT_H
|
||||
#define OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H
|
||||
|
||||
#include "hisysevent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DeviceProfile {
|
||||
namespace FaultEvent{
|
||||
const std::string DEVICE_PROFILE_SYNC_FAILED = "DEVICE_PROFILE_SYNC_FAILED";
|
||||
}
|
||||
|
||||
namespace ErrorType{
|
||||
const std::string FAULT_CODE_KEY = "FAULT_CODE";
|
||||
}
|
||||
const std::string DOMAIN_NAME = std::string(OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE);
|
||||
|
||||
class DpHiSysEventReport {
|
||||
public:
|
||||
static int ReportSyncBehavior(const std::string& eventName);
|
||||
static int ReportSyncFault(const std::string& faultName, const int32_t code);
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
|
||||
#endif /* OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H */
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "dp_hisysevent_report.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define private public
|
||||
@@ -228,5 +229,16 @@ HWTEST_F(ProfileCrudTest, GetDeviceProfile_001, TestSize.Level2)
|
||||
DTEST_LOG << "PrivateSyscap: " << *(priOutput + i) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DfxErrorPrint_001
|
||||
* @tc.desc: print hisysevent error event
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ProfileCrudTest, DfxErrorPrint_001, TestSize.Level0)
|
||||
{
|
||||
int ret = DpHiSysEventReport::ReportSyncFault(DEVICE_PROFILE_SYNC_FAILED, -1);
|
||||
EXPECT_TRUE(ret == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user