diff --git a/hisysevent.yaml b/hisysevent.yaml index 44a9a7852..daba8439e 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -100,6 +100,15 @@ DATABASE_BEHAVIOUR: STORE_ID: {type: STRING, desc: store id } BEHAVIOUR_INFO: {type: STRING, desc: behaviour type and behaviour resulte } +UDMF_DATA_BEHAVIOR: + __BASE: {type: BEHAVIOR, level: MINOR, desc: The event is behaviour record } + APP_ID: {type: STRING, desc: app id } + CHANNEL: {type: STRING, desc: channel name } + DATA_SIZE: {type: INT64, desc: data size } + DATA_TYPE: {type: STRING, desc: data type } + OPERATION: {type: STRING, desc: data operation } + RESULT: {type: STRING, desc: data operation result } + OPEN_DATABASE_FAILED: __BASE: {type: FAULT, level: CRITICAL, desc: The database open failed} APP_ID: {type: STRING, desc: app id } diff --git a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp index 9e3b46197..cee6b854e 100644 --- a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp +++ b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "behaviour_reporter_impl.h" namespace OHOS { @@ -22,6 +21,13 @@ ReportStatus BehaviourReporterImpl::Report(const BehaviourMsg &msg) HiViewAdapter::ReportBehaviour(DfxCodeConstant::DATABASE_BEHAVIOUR, msg, executors_); return ReportStatus::SUCCESS; } + +ReportStatus BehaviourReporterImpl::UDMFReport(const UDMFBehaviourMsg &msg) +{ + HiViewAdapter::ReportUDMFBehaviour(DfxCodeConstant::UDMF_DATA_BEHAVIOR, msg, executors_); + return ReportStatus::SUCCESS; +} + void BehaviourReporterImpl::SetThreadPool(std::shared_ptr executors) { executors_ = executors; diff --git a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h index 7ac010b19..72d9ef3c5 100644 --- a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h +++ b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h @@ -25,6 +25,7 @@ class BehaviourReporterImpl : public BehaviourReporter { public: virtual ~BehaviourReporterImpl() {} ReportStatus Report(const struct BehaviourMsg &msg) override; + ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) override; void SetThreadPool(std::shared_ptr executors); private: diff --git a/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h b/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h index a78caaaf7..cc2cba1d1 100644 --- a/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h +++ b/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h @@ -32,5 +32,6 @@ public: static inline const int DATABASE_CORRUPTED_FAILED = 950001113; static inline const int DATABASE_REKEY_FAILED = 950001114; static inline const int DATABASE_BEHAVIOUR = 950001115; + static inline const int UDMF_DATA_BEHAVIOR = 950001116; }; #endif // DISTRIBUTEDDATAMGR_DFX_CODE_CONSTANT_H diff --git a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp index 9ac6fef2f..c98b3b369 100644 --- a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp +++ b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp @@ -47,6 +47,11 @@ constexpr const char *TAG = "TAG"; constexpr const char *POWERSTATS = "PowerStats"; // behaviour key constexpr const char *BEHAVIOUR_INFO = "BEHAVIOUR_INFO"; +constexpr const char *CHANNEL = "CHANNEL"; +constexpr const char *DATA_SIZE = "DATA_SIZE"; +constexpr const char *DATA_TYPE = "DATA_TYPE"; +constexpr const char *OPERATION = "OPERATION"; +constexpr const char *RESULT = "RESULT"; const std::map EVENT_COVERT_TABLE = { { DfxCodeConstant::SERVICE_FAULT, "SERVICE_FAULT" }, @@ -63,6 +68,7 @@ const std::map EVENT_COVERT_TABLE = { { DfxCodeConstant::DATABASE_CORRUPTED_FAILED, "DATABASE_CORRUPTED_FAILED" }, { DfxCodeConstant::DATABASE_REKEY_FAILED, "DATABASE_REKEY_FAILED" }, { DfxCodeConstant::DATABASE_BEHAVIOUR, "DATABASE_BEHAVIOUR" }, + { DfxCodeConstant::UDMF_DATA_BEHAVIOR, "UDMF_DATA_BEHAVIOR" }, }; } using OHOS::HiviewDFX::HiSysEvent; @@ -298,6 +304,23 @@ void HiViewAdapter::ReportApiPerformanceStatistic(int dfxCode, const ApiPerforma StartTimerThread(executors); } +void HiViewAdapter::ReportUDMFBehaviour( + int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr executors) +{ + ExecutorPool::Task task([dfxCode, msg]() { + HiSysEventWrite(HiSysEvent::Domain::DISTRIBUTED_DATAMGR, + CoverEventID(dfxCode), + HiSysEvent::EventType::BEHAVIOR, + APP_ID, msg.appId, + CHANNEL, msg.channel, + DATA_SIZE, msg.dataSize, + DATA_TYPE, msg.dataType, + OPERATION, msg.operation, + RESULT, msg.result); + }); + executors->Execute(std::move(task)); +} + void HiViewAdapter::InvokeApiPerformance() { std::string message; diff --git a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h index 21de2703b..7bfbc6c0e 100644 --- a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h +++ b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h @@ -46,6 +46,7 @@ public: static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat, std::shared_ptr executors); static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr executors); + static void ReportUDMFBehaviour(int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr executors); static void StartTimerThread(std::shared_ptr executors); private: diff --git a/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h b/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h index 57b1f32c4..4a9c9062a 100644 --- a/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h +++ b/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h @@ -23,6 +23,7 @@ namespace DistributedDataDfx { class BehaviourReporter { public: KVSTORE_API virtual ReportStatus Report(const BehaviourMsg &msg) = 0; + KVSTORE_API virtual ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) = 0; KVSTORE_API virtual ~BehaviourReporter() {} }; } // namespace DistributedDataDfx diff --git a/services/distributeddataservice/adapter/include/dfx/dfx_types.h b/services/distributeddataservice/adapter/include/dfx/dfx_types.h index e8ab47b42..8068abbe4 100644 --- a/services/distributeddataservice/adapter/include/dfx/dfx_types.h +++ b/services/distributeddataservice/adapter/include/dfx/dfx_types.h @@ -131,6 +131,15 @@ struct BehaviourMsg { std::string extensionInfo; }; +struct UDMFBehaviourMsg { + std::string appId; + std::string channel; + int64_t dataSize; + std::string dataType; + std::string operation; + std::string result; +}; + struct VisitStat { std::string appId; std::string interfaceName; diff --git a/services/distributeddataservice/adapter/include/dfx/reporter.h b/services/distributeddataservice/adapter/include/dfx/reporter.h index c2537b573..de60c0e84 100644 --- a/services/distributeddataservice/adapter/include/dfx/reporter.h +++ b/services/distributeddataservice/adapter/include/dfx/reporter.h @@ -43,7 +43,7 @@ public: void SetThreadPool(std::shared_ptr executors) { executors_ = executors; - if (executors == nullptr) { + if (executors != nullptr) { ServiceFault(); RuntimeFault(); DatabaseFault(); diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index cc2093153..4e33af713 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -17,19 +17,21 @@ config("module_public_config") { visibility = [ ":*" ] include_dirs = [ - "${udmf_path}/framework/common", - "${udmf_path}/interfaces/innerkits/common", - "${udmf_path}/interfaces/innerkits/data", "${data_service_path}/framework/include", + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/adapter/include/dfx", "${data_service_path}/service/udmf/lifecycle", "${data_service_path}/service/udmf/permission", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", - "${kv_store_path}/frameworks/common", - "${file_service_path}/interfaces/innerkits/native/remote_file_share/include", "${device_manager_path}/interfaces/inner_kits/native_cpp/include", - "${data_service_path}/adapter/include/communicator", + "${file_service_path}/interfaces/innerkits/native/remote_file_share/include", + "${kv_store_path}/interfaces/innerkits/distributeddata/include", + "${kv_store_common_path}", + "${udmf_path}/framework/common", + "${udmf_path}/interfaces/innerkits/common", + "${udmf_path}/interfaces/innerkits/data", ] } diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index ec92b385d..8641ed43c 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -17,6 +17,7 @@ #include "data_manager.h" #include "checker_manager.h" +#include "dfx_types.h" #include "file.h" #include "lifecycle/lifecycle_manager.h" #include "log_print.h" @@ -151,6 +152,7 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str()); return E_DB_ERROR; } + PreProcessUtils::SetRemoteData(unifiedData); return E_OK; } std::string DataManager::ConvertUri(std::shared_ptr record, const std::string &localDevId, @@ -181,7 +183,8 @@ int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector -#include "error_code.h" + #include "accesstoken_kit.h" #include "bundlemgr/bundle_mgr_client_impl.h" -#include "ipc_skeleton.h" #include "device_manager_adapter.h" +#include "error_code.h" +#include "file.h" +#include "ipc_skeleton.h" #include "log_print.h" namespace OHOS { namespace UDMF { static constexpr int ID_LEN = 32; const char SPECIAL = '^'; +using namespace Security::AccessToken; int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &option) { auto it = UD_INTENTION_MAP.find(option.intention); @@ -52,12 +54,6 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption & return E_OK; } -std::string PreProcessUtils::GetLocalDeviceId() -{ - auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice(); - return DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); -} - std::string PreProcessUtils::IdGenerator() { std::random_device randomDevice; @@ -113,5 +109,37 @@ bool PreProcessUtils::GetNativeProcessNameByToken(int tokenId, std::string &proc processName = nativeInfo.processName; return true; } + +std::string PreProcessUtils::GetLocalDeviceId() +{ + auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice(); + std::string encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); + return encryptedUuid; +} + +void PreProcessUtils::SetRemoteData(UnifiedData &data) +{ + if (data.IsEmpty()) { + ZLOGD("invalid data."); + return; + } + std::shared_ptr runtime = data.GetRuntime(); + if (runtime->deviceId == PreProcessUtils::GetLocalDeviceId()) { + ZLOGD("not remote data."); + return; + } + ZLOGD("is remote data."); + auto records = data.GetRecords(); + for (auto record : records) { + auto type = record->GetType(); + if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO + || type == UDType::FOLDER) { + auto file = static_cast(record.get()); + UDDetails details = file->GetDetails(); + details.insert({"isRemote", "true"}); + file->SetDetails(details); + } + } +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 52759057b..76272973d 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -33,7 +33,8 @@ public: static int32_t GetHapUidByToken(uint32_t tokenId); static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName); static bool GetNativeProcessNameByToken(int tokenId, std::string &processName); - static std::string GetLocalDeviceId(); // uuid + static std::string GetLocalDeviceId(); + static void SetRemoteData(UnifiedData &data); }; } // namespace UDMF } // namespace OHOS diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index dcbf8b474..b1744347b 100755 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -22,10 +22,13 @@ #include "lifecycle/lifecycle_manager.h" #include "log_print.h" #include "preprocess_utils.h" +#include "reporter.h" namespace OHOS { namespace UDMF { using FeatureSystem = DistributedData::FeatureSystem; +using UDMFBehaviourMsg = OHOS::DistributedDataDfx::UDMFBehaviourMsg; +using Reporter = OHOS::DistributedDataDfx::Reporter; __attribute__((used)) UdmfServiceImpl::Factory UdmfServiceImpl::factory_; UdmfServiceImpl::Factory::Factory() { @@ -46,13 +49,49 @@ UdmfServiceImpl::Factory::~Factory() int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) { ZLOGD("start"); - return DataManager::GetInstance().SaveData(option, unifiedData, key); + int32_t res = E_OK; + UDMFBehaviourMsg msg; + auto find = UD_INTENTION_MAP.find(option.intention); + msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second; + msg.operation = "insert"; + std::string bundleName; + if (!PreProcessUtils::GetHapBundleNameByToken(option.tokenId, bundleName)) { + msg.appId = "unknown"; + res = E_ERROR; + } else { + msg.appId = bundleName; + res = DataManager::GetInstance().SaveData(option, unifiedData, key); + } + msg.result = ERROR_MAP.find(res)->second; + std::vector types = unifiedData.GetUDTypes(); + msg.dataType = unifiedData.GetTypes(); + msg.dataSize = unifiedData.GetSize(); + Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); + return res; } int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedData) { ZLOGD("start"); - return DataManager::GetInstance().RetrieveData(query, unifiedData); + int32_t res = E_OK; + UDMFBehaviourMsg msg; + auto find = UD_INTENTION_MAP.find(query.intention); + msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second; + msg.operation = "insert"; + std::string bundleName; + if (!PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName)) { + msg.appId = "unknown"; + res = E_ERROR; + } else { + msg.appId = bundleName; + res = DataManager::GetInstance().RetrieveData(query, unifiedData); + } + msg.result = ERROR_MAP.find(res)->second; + std::vector types = unifiedData.GetUDTypes(); + msg.dataType = unifiedData.GetTypes(); + msg.dataSize = unifiedData.GetSize(); + Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); + return res; } int32_t UdmfServiceImpl::GetBatchData(const QueryOption &query, std::vector &unifiedDataSet)