From 49d73ebbbf4aeeaf1bd005139bb4e861767f3e1c Mon Sep 17 00:00:00 2001 From: lvyuanmin Date: Thu, 4 Aug 2022 00:25:28 +0800 Subject: [PATCH] add dfx code Signed-off-by: lvyuanmin --- bundle.json | 4 ++ frameworks/inc/standard/ipc_dev_auth_stub.h | 1 + frameworks/src/standard/ipc_dev_auth_stub.cpp | 8 +++ hisysevent.yaml | 23 +++++++ services/BUILD.gn | 17 +++++ services/data_manager/src/data_manager.c | 49 +++++++++++++++ services/deviceauth.gni | 10 +++ .../inc/hiview_adapter/dev_auth_hievent.h | 32 ++++++++++ .../inc/hiview_adapter/hidump_adapter.h | 35 +++++++++++ .../inc/hiview_adapter/hisysevent_adapter.h | 54 ++++++++++++++++ .../inc/hiview_adapter/hitrace_adapter.h | 35 +++++++++++ .../src/hiview_adapter/dev_auth_hievent.c | 56 +++++++++++++++++ .../src/hiview_adapter/hidump_adapter.c | 31 +++++++++ .../src/hiview_adapter/hisysevent_adapter.cpp | 48 ++++++++++++++ .../src/hiview_adapter/hitrace_adapter.cpp | 40 ++++++++++++ .../src/hiview_adapter/hiview_mock.c | 63 +++++++++++++++++++ .../src/module/dev_auth_module_manager.c | 3 + .../src/group_operation/group_operation.c | 18 +++++- test/unittest/deviceauth/BUILD.gn | 2 + 19 files changed, 528 insertions(+), 1 deletion(-) create mode 100644 hisysevent.yaml create mode 100644 services/frameworks/inc/hiview_adapter/dev_auth_hievent.h create mode 100644 services/frameworks/inc/hiview_adapter/hidump_adapter.h create mode 100644 services/frameworks/inc/hiview_adapter/hisysevent_adapter.h create mode 100644 services/frameworks/inc/hiview_adapter/hitrace_adapter.h create mode 100644 services/frameworks/src/hiview_adapter/dev_auth_hievent.c create mode 100644 services/frameworks/src/hiview_adapter/hidump_adapter.c create mode 100644 services/frameworks/src/hiview_adapter/hisysevent_adapter.cpp create mode 100644 services/frameworks/src/hiview_adapter/hitrace_adapter.cpp create mode 100644 services/frameworks/src/hiview_adapter/hiview_mock.c diff --git a/bundle.json b/bundle.json index 0330dada..2f990bcb 100644 --- a/bundle.json +++ b/bundle.json @@ -16,6 +16,9 @@ "subsystem": "security", "syscap": [ "SystemCapability.Security.DeviceAuth" ], "features": [], + "hisysevent_config": [ + "//base/security/device_auth/hisysevent.yaml" + ], "adapted_system_type": [ "standard", "small", @@ -33,6 +36,7 @@ "common", "utils_base", "hiviewdfx_hilog_native", + "hisysevent_native", "samgr_standard", "ipc" ], diff --git a/frameworks/inc/standard/ipc_dev_auth_stub.h b/frameworks/inc/standard/ipc_dev_auth_stub.h index 6e96a19e..aba6b8c2 100755 --- a/frameworks/inc/standard/ipc_dev_auth_stub.h +++ b/frameworks/inc/standard/ipc_dev_auth_stub.h @@ -32,6 +32,7 @@ class ServiceDevAuth : public IRemoteStub { public: ServiceDevAuth(); ~ServiceDevAuth(); + int32_t Dump(int32_t fd, const std::vector& args) override; virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; void ResetCallMap(void); diff --git a/frameworks/src/standard/ipc_dev_auth_stub.cpp b/frameworks/src/standard/ipc_dev_auth_stub.cpp index 339320f0..fe0163d5 100644 --- a/frameworks/src/standard/ipc_dev_auth_stub.cpp +++ b/frameworks/src/standard/ipc_dev_auth_stub.cpp @@ -23,6 +23,7 @@ #include "permission_adapter.h" #include "securec.h" #include "system_ability_definition.h" +#include "hidump_adapter.h" using namespace std; namespace OHOS { @@ -48,6 +49,13 @@ ServiceDevAuth::~ServiceDevAuth() callMapElemNum = 0; } +int32_t ServiceDevAuth::Dump(int32_t fd, const std::vector& args) +{ + DevAuthDump(fd); + (void)args; + return 0; +} + IpcServiceCall ServiceDevAuth::GetCallMethodByMethodId(int32_t methodId) { int32_t i; diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 00000000..f4adc6d2 --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,23 @@ +# 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_AUTH + +CORE_FUNCTION: + __BASE: {type: STATISTIC, level: MINOR, desc: the frequency of function calling} + EVENT: {type: INT32, desc: event id} + APP_ID: {type: STRING, desc: app id} + TYPE: {type: INT32, desc: the type of group or auth} + BATCH_NUMBER: {type: INT32, desc: the number of batch operation} + RESULT: {type: INT32, desc: ret of call} + OS_ACCOUNT_ID: {type: INT32, desc: os account id} \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 5e3999ad..7c0ea1ab 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -29,8 +29,10 @@ if (os_level == "mini" || os_level == "small") { "//foundation/communication/dsoftbus/interfaces/kits/common", "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_files + sources += hiview_adapter_mock_files deps = [ "${deps_adapter_path}:${hal_module_name}", "//build/lite/config/component/cJSON:cjson_shared", @@ -40,6 +42,7 @@ if (os_level == "mini" || os_level == "small") { defines = [ "HILOG_ENABLE" ] defines += deviceauth_defines + defines += [ "DISABLE_HIVIEW" ] if (board_toolchain_type == "iccarm") { cflags = [ "--diag_suppress", @@ -81,9 +84,11 @@ if (os_level == "mini" || os_level == "small") { "//third_party/bounds_checking_function/include", "${frameworks_path}/inc/lite", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files + sources += hiview_adapter_mock_files sources += [ "${frameworks_path}/src/ipc_service.c", "${frameworks_path}/src/lite/ipc_service_init.c", @@ -117,6 +122,7 @@ if (os_level == "mini" || os_level == "small") { "${frameworks_path}/inc/lite", "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files @@ -146,9 +152,11 @@ if (os_level == "mini" || os_level == "small") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_files + sources += hiview_adapter_files cflags = [ "-DHILOG_ENABLE" ] defines = deviceauth_defines cflags += build_flags @@ -167,6 +175,8 @@ if (os_level == "mini" || os_level == "small") { external_deps = [ "c_utils:utils", "dsoftbus:softbus_client", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", ] if (support_jsapi) { @@ -194,6 +204,7 @@ if (os_level == "mini" || os_level == "small") { "//third_party/cJSON", "${frameworks_path}/inc/standard", "${dev_frameworks_path}/inc/permission_adapter", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files @@ -215,6 +226,8 @@ if (os_level == "mini" || os_level == "small") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", @@ -231,10 +244,12 @@ if (os_level == "mini" || os_level == "small") { "//third_party/cJSON", "${frameworks_path}/inc/standard", "${dev_frameworks_path}/inc/permission_adapter", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files sources += permission_adapter_files + sources += hiview_adapter_files sources += [ "${frameworks_path}/src/ipc_sdk.c" ] defines = [ @@ -255,6 +270,8 @@ if (os_level == "mini" || os_level == "small") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/services/data_manager/src/data_manager.c b/services/data_manager/src/data_manager.c index d12890e3..e6fc9f85 100644 --- a/services/data_manager/src/data_manager.c +++ b/services/data_manager/src/data_manager.c @@ -26,6 +26,7 @@ #include "hc_string_vector.h" #include "hc_types.h" #include "securec.h" +#include "hidump_adapter.h" typedef struct { DECLARE_TLV_STRUCT(9) @@ -1146,6 +1147,51 @@ int32_t SaveOsAccountDb(int32_t osAccountId) return HC_SUCCESS; } +#ifndef DISABLE_HIVIEW +static void DumpGroups(int fd, GroupEntryVec *vec) +{ + dprintf(fd, "---- GROUP INFO ----\n"); + uint32_t index; + TrustedGroupEntry **entry; + FOR_EACH_HC_VECTOR(*vec, index, entry) { + dprintf(fd, "GROUP NAME: %s", (*entry)->name); + dprintf(fd, "GROUP ID: %s", (*entry)->id); + dprintf(fd, "GROUP TYPE: %s", (*entry)->type); + dprintf(fd, "GROUP VISIBILITY: %s", (*entry)->visibility); + dprintf(fd, "GROUP OWNER: %s", (*entry)->managers); + } +} + +static void DumpDevices(int fd, DeviceEntryVec *vec) +{ + dprintf(fd, "---- DEVICE INFO ----\n"); + uint32_t index; + TrustedDeviceEntry **entry; + FOR_EACH_HC_VECTOR(*vec, index, entry) { + dprintf(fd, "DEVICES ID: %s", (*entry)->udid); + dprintf(fd, "GROUP ID: %s", (*entry)->groupId); + } +} + +static void DevAuthDataBaseDump(int fd) +{ + if (g_databaseMutex == NULL) { + LOGE("[DB]: Init mutex failed"); + return; + } + g_databaseMutex->lock(g_databaseMutex); + + uint32_t index; + OsAccountTrustedInfo *info; + FOR_EACH_HC_VECTOR(g_deviceauthDb, index, info) { + dprintf(fd, "OS ACCOUNT ID: %s\n;", info->osAccountId); + DumpGroups(fd, &info->groups); + DumpDevices(fd, &info->devices); + } + + g_databaseMutex->unlock(g_databaseMutex); +} +#endif int32_t InitDatabase(void) { if (g_databaseMutex == NULL) { @@ -1163,6 +1209,9 @@ int32_t InitDatabase(void) } g_deviceauthDb = CREATE_HC_VECTOR(DeviceAuthDb); LoadDeviceAuthDb(); +#ifndef DISABLE_HIVIEW + RegisterDumpFunc(DevAuthDataBaseDump); +#endif return HC_SUCCESS; } diff --git a/services/deviceauth.gni b/services/deviceauth.gni index 009f78eb..13ddd8f9 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -100,6 +100,16 @@ os_account_adapter_lite_files = [ "${dev_frameworks_path}/src/os_account_adapter permission_adapter_files = [ "${dev_frameworks_path}/src/permission_adapter/permission_adapter.cpp" ] +hiview_adapter_files = [ + "${dev_frameworks_path}/src/hiview_adapter/hidump_adapter.c", + "${dev_frameworks_path}/src/hiview_adapter/hisysevent_adapter.cpp", + "${dev_frameworks_path}/src/hiview_adapter/dev_auth_hievent.c", + "${dev_frameworks_path}/src/hiview_adapter/hitrace_adapter.cpp", +] + +hiview_adapter_mock_files = + [ "${dev_frameworks_path}/src/hiview_adapter/hiview_mock.c" ] + group_auth_files = [ "${group_auth_path}/src/group_auth_manager/group_auth_data_operation.c", "${group_auth_path}/src/group_auth_manager/group_auth_manager.c", diff --git a/services/frameworks/inc/hiview_adapter/dev_auth_hievent.h b/services/frameworks/inc/hiview_adapter/dev_auth_hievent.h new file mode 100644 index 00000000..f1c1a7ad --- /dev/null +++ b/services/frameworks/inc/hiview_adapter/dev_auth_hievent.h @@ -0,0 +1,32 @@ +/* + * 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 DEV_AUTH_BIGDATA_EVENT_H +#define DEV_AUTH_BIGDATA_EVENT_H + +#include "stdint.h" +#include "json_utils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ReportHiEventCoreFuncInvoke(int32_t eventId, int32_t osAccountId, CJson *params, int32_t result); + +#ifdef __cplusplus +} +#endif + +#endif // DEV_AUTH_BIGDATA_EVENT_H diff --git a/services/frameworks/inc/hiview_adapter/hidump_adapter.h b/services/frameworks/inc/hiview_adapter/hidump_adapter.h new file mode 100644 index 00000000..226b397c --- /dev/null +++ b/services/frameworks/inc/hiview_adapter/hidump_adapter.h @@ -0,0 +1,35 @@ +/* + * 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 HIDUMP_ADAPTER_H +#define HIDUMP_ADAPTER_H + +#include + +typedef void (*DumpCallBack)(int); + +#ifdef __cplusplus +extern "C" { +#endif + +void DevAuthDump(int fd); + +void RegisterDumpFunc(DumpCallBack func); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/services/frameworks/inc/hiview_adapter/hisysevent_adapter.h b/services/frameworks/inc/hiview_adapter/hisysevent_adapter.h new file mode 100644 index 00000000..f6aed45b --- /dev/null +++ b/services/frameworks/inc/hiview_adapter/hisysevent_adapter.h @@ -0,0 +1,54 @@ +/* + * 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 HISYSEVENT_ADAPTER_H +#define HISYSEVENT_ADAPTER_H + +#include + +#define EVENT_APPID_LEN 128 + + +enum InvokeEventId { + EVENT_ID_CREATE_GROUP = 0, + EVENT_ID_DELETE_GROUP = 1, + EVENT_ID_ADD_MEMBER = 2, + EVENT_ID_DELETE_MEMBER = 3, + EVENT_ID_GET_REGISTER_INFO = 4, + EVENT_ID_ADD_MULTI_MEMBERS = 5, + EVENT_ID_DELETE_MULTI_MEMBERS = 6, + EVENT_ID_AUTH_DEVICE = 7, +}; + +typedef struct InvokeEvent { + int32_t eventId; + char appId[EVENT_APPID_LEN]; + int32_t type; + int32_t batchNumber; + int32_t result; + int32_t osAccountId; +} InvokeEvent; + +#ifdef __cplusplus +extern "C" { +#endif + +void ReportCoreFuncInvokeEvent(const InvokeEvent *event); + +#ifdef __cplusplus +} +#endif + +#endif // SERVICE_DSLM_BIGDATA_H diff --git a/services/frameworks/inc/hiview_adapter/hitrace_adapter.h b/services/frameworks/inc/hiview_adapter/hitrace_adapter.h new file mode 100644 index 00000000..a637c1b6 --- /dev/null +++ b/services/frameworks/inc/hiview_adapter/hitrace_adapter.h @@ -0,0 +1,35 @@ +/* + * 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 HITRACE_ADAPTER_H +#define HITRACE_ADAPTER_H + +#include + +#define TRACE_TAG_AUTH_PROCESS "auth_process" + +#ifdef __cplusplus +extern "C" { +#endif + +void DevAuthStartTrace(const char *value); + +void DevAuthFinishTrace(void); + +#ifdef __cplusplus +} +#endif + +#endif // HITRACE_ADAPTER_H \ No newline at end of file diff --git a/services/frameworks/src/hiview_adapter/dev_auth_hievent.c b/services/frameworks/src/hiview_adapter/dev_auth_hievent.c new file mode 100644 index 00000000..f7b3dd3d --- /dev/null +++ b/services/frameworks/src/hiview_adapter/dev_auth_hievent.c @@ -0,0 +1,56 @@ +/* + * 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 "dev_auth_hievent.h" + +#include +#include +#include "securec.h" +#include "hc_types.h" + +#include "hisysevent_adapter.h" +#include "device_auth_defines.h" +#include "device_auth.h" + +void ReportHiEventCoreFuncInvoke(int32_t eventId, int32_t osAccountId, CJson *params, int32_t result) +{ + if (params == NULL) { + return; + } + + InvokeEvent event; + (void)memset_s(&event, sizeof(InvokeEvent), 0, sizeof(InvokeEvent)); + + int32_t groupType = PEER_TO_PEER_GROUP; + if (GetIntFromJson(params, FIELD_GROUP_TYPE, &groupType) != HC_SUCCESS) { + return; + } + + event.eventId = eventId; + event.type = groupType; + event.batchNumber = 0; + event.result = result; + event.osAccountId = osAccountId; + + const char *appId = GetStringFromJson(params, FIELD_APP_ID); + if (appId == NULL) { + return; + } + if (memcpy_s(event.appId, EVENT_APPID_LEN, appId, HcStrlen(appId)) != EOK) { + (void)memset_s(event.appId, EVENT_APPID_LEN, 0, EVENT_APPID_LEN); + } + + ReportCoreFuncInvokeEvent(&event); +} \ No newline at end of file diff --git a/services/frameworks/src/hiview_adapter/hidump_adapter.c b/services/frameworks/src/hiview_adapter/hidump_adapter.c new file mode 100644 index 00000000..cd2beb4b --- /dev/null +++ b/services/frameworks/src/hiview_adapter/hidump_adapter.c @@ -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 "hidump_adapter.h" + +static DumpCallBack g_dumpCallBack = NULL; + +void DevAuthDump(int fd) +{ + if (g_dumpCallBack != NULL) { + g_dumpCallBack(fd); + } +} + +void RegisterDumpFunc(DumpCallBack func) +{ + g_dumpCallBack = func; +} \ No newline at end of file diff --git a/services/frameworks/src/hiview_adapter/hisysevent_adapter.cpp b/services/frameworks/src/hiview_adapter/hisysevent_adapter.cpp new file mode 100644 index 00000000..3954919a --- /dev/null +++ b/services/frameworks/src/hiview_adapter/hisysevent_adapter.cpp @@ -0,0 +1,48 @@ +/* + * 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 "hisysevent_adapter.h" +#include "hisysevent.h" + +#ifdef __cplusplus +extern "C" { +#endif + +constexpr char STR_EVENT_CORE_FUNCTION[] = "CORE_FUNCTION"; +constexpr char STR_EVENT[] = "EVENT"; +constexpr char STR_APP_ID[] = "APP_ID"; +constexpr char STR_BATCH_NUMBER[] = "BATCH_NUMBER"; +constexpr char STR_RESULT[] = "RESULT"; +constexpr char STR_OS_ACCOUNT_ID[] = "OS_ACCOUNT_ID"; + +void ReportCoreFuncInvokeEvent(const InvokeEvent *event) +{ + if (event == nullptr) { + return; + } + OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_AUTH, + STR_EVENT_CORE_FUNCTION, + OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, + STR_EVENT, event->eventId, + STR_APP_ID, event->appId, + STR_BATCH_NUMBER, event->batchNumber, + STR_RESULT, event->result, + STR_OS_ACCOUNT_ID, event->osAccountId); +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/services/frameworks/src/hiview_adapter/hitrace_adapter.cpp b/services/frameworks/src/hiview_adapter/hitrace_adapter.cpp new file mode 100644 index 00000000..57eca825 --- /dev/null +++ b/services/frameworks/src/hiview_adapter/hitrace_adapter.cpp @@ -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. + */ + +#include "hitrace_adapter.h" + +#include "hitrace_meter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void DevAuthStartTrace(const char *value) +{ + if (value == nullptr) { + return; + } + + StartTrace(HITRACE_TAG_APP, value); +} + +void DevAuthFinishTrace(void) +{ + FinishTrace(HITRACE_TAG_APP); +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/services/frameworks/src/hiview_adapter/hiview_mock.c b/services/frameworks/src/hiview_adapter/hiview_mock.c new file mode 100644 index 00000000..eff361b3 --- /dev/null +++ b/services/frameworks/src/hiview_adapter/hiview_mock.c @@ -0,0 +1,63 @@ +/* + * 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 "dev_auth_hievent.h" +#include "hidump_adapter.h" +#include "hisysevent_adapter.h" +#include "hitrace_adapter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// dev_auth_hievent +void ReportHiEventCoreFuncInvoke(int32_t eventId, int32_t osAccountId, CJson *params, int32_t result) +{ + (void)eventId; + (void)osAccountId; + (void)params; + (void)result; +} + +// hidump_adapter +void DevAuthDump(int fd) +{ + (void)fd; +} + +void RegisterDumpFunc(DumpCallBack func) +{ + (void)func; +} + +// hisysevent_adapter +void ReportCoreFuncInvokeEvent(const InvokeEvent *event) +{ + (void)event; +} + +// hitrace_adapter +void DevAuthStartTrace(const char *value) +{ + (void)value; +} + +void DevAuthFinishTrace(void) +{ +} + +#ifdef __cplusplus +} +#endif diff --git a/services/frameworks/src/module/dev_auth_module_manager.c b/services/frameworks/src/module/dev_auth_module_manager.c index e1ca5e5e..ab7b629a 100644 --- a/services/frameworks/src/module/dev_auth_module_manager.c +++ b/services/frameworks/src/module/dev_auth_module_manager.c @@ -21,6 +21,7 @@ #include "hc_vector.h" #include "account_module.h" #include "version_util.h" +#include "hitrace_adapter.h" DECLARE_HC_VECTOR(AuthModuleVec, void *); IMPLEMENT_HC_VECTOR(AuthModuleVec, void *, 1) @@ -185,7 +186,9 @@ int32_t ProcessTask(int taskId, const CJson *in, CJson *out, int32_t *status, in LOGE("Unsupported method in the module, moduleType: %d.", moduleType); return HC_ERR_UNSUPPORTED_METHOD; } + DevAuthStartTrace(TRACE_TAG_AUTH_PROCESS); int32_t res = module->processTask(taskId, in, out, status); + DevAuthFinishTrace(); if (res != HC_SUCCESS) { LOGE("Process task failed, taskId: %d, moduleType: %d, res: %d.", taskId, moduleType, res); return res; diff --git a/services/group_manager/src/group_operation/group_operation.c b/services/group_manager/src/group_operation/group_operation.c index a665c065..37eaf474 100644 --- a/services/group_manager/src/group_operation/group_operation.c +++ b/services/group_manager/src/group_operation/group_operation.c @@ -33,7 +33,8 @@ #include "across_account_group.h" #include "identical_account_group.h" #include "peer_to_peer_group.h" - +#include "dev_auth_hievent.h" +#include "hisysevent_adapter.h" static bool IsGroupTypeSupported(int groupType) { @@ -559,6 +560,9 @@ static void DoCreateGroup(HcTaskBase *baseTask) LOGI("[Start]: DoCreateGroup! [ReqId]: %" PRId64, task->reqId); char *returnJsonStr = NULL; int32_t result = CreateGroup(task->osAccountId, task->params, &returnJsonStr); + + ReportHiEventCoreFuncInvoke(EVENT_ID_CREATE_GROUP, task->osAccountId, task->params, result); + if (result != HC_SUCCESS) { ProcessErrorCallback(task->reqId, GROUP_CREATE, result, NULL, task->cb); } else { @@ -577,6 +581,9 @@ static void DoDeleteGroup(HcTaskBase *baseTask) LOGI("[Start]: DoDeleteGroup! [ReqId]: %" PRId64, task->reqId); char *returnJsonStr = NULL; int32_t result = DeleteGroup(task->osAccountId, task->params, &returnJsonStr); + + ReportHiEventCoreFuncInvoke(EVENT_ID_DELETE_GROUP, task->osAccountId, task->params, result); + if (result != HC_SUCCESS) { ProcessErrorCallback(task->reqId, GROUP_DISBAND, result, NULL, task->cb); } else { @@ -594,6 +601,9 @@ static void DoAddMember(HcTaskBase *baseTask) GroupManagerTask *task = (GroupManagerTask *)baseTask; LOGI("[Start]: DoAddMember! [ReqId]: %" PRId64, task->reqId); (void)AddMemberToPeerToPeerGroup(task->osAccountId, task->reqId, task->params, task->cb); + + // 0 means success + ReportHiEventCoreFuncInvoke(EVENT_ID_ADD_MEMBER, task->osAccountId, task->params, 0); } static void DoDeleteMember(HcTaskBase *baseTask) @@ -605,6 +615,9 @@ static void DoDeleteMember(HcTaskBase *baseTask) GroupManagerTask *task = (GroupManagerTask *)baseTask; LOGI("[Start]: DoDeleteMember! [ReqId]: %" PRId64, task->reqId); (void)DeleteMemberFromPeerToPeerGroup(task->osAccountId, task->reqId, task->params, task->cb); + + // 0 means success + ReportHiEventCoreFuncInvoke(EVENT_ID_DELETE_MEMBER, task->osAccountId, task->params, 0); } static void DoProcessBindData(HcTaskBase *baseTask) @@ -781,6 +794,8 @@ static int32_t RequestAddMultiMembersToGroup(int32_t osAccountId, const char *ap res = HC_ERR_INVALID_PARAMS; } FreeJson(params); + + ReportHiEventCoreFuncInvoke(EVENT_ID_ADD_MULTI_MEMBERS, osAccountId, params, res); LOGI("[End]: RequestAddMultiMembersToGroup!"); return res; } @@ -820,6 +835,7 @@ static int32_t RequestDelMultiMembersFromGroup(int32_t osAccountId, const char * res = HC_ERR_INVALID_PARAMS; } FreeJson(params); + ReportHiEventCoreFuncInvoke(EVENT_ID_DELETE_MULTI_MEMBERS, osAccountId, params, res); LOGI("[End]: RequestDelMultiMembersFromGroup!"); return res; } diff --git a/test/unittest/deviceauth/BUILD.gn b/test/unittest/deviceauth/BUILD.gn index 76487844..7c55cea7 100644 --- a/test/unittest/deviceauth/BUILD.gn +++ b/test/unittest/deviceauth/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("deviceauth_llt") { "//foundation/communication/dsoftbus/interfaces/kits/common", "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ @@ -58,6 +59,7 @@ ohos_unittest("deviceauth_llt") { "${os_adapter_path}/impl/src/linux/hc_types.c", ] sources += deviceauth_files + sources += hiview_adapter_mock_files sources += [ "source/deviceauth_standard_test.cpp" ] deps = [