From 31f1a71fee10a1248de00ea1f36eeaf80e683673 Mon Sep 17 00:00:00 2001 From: "beiling.xie" Date: Fri, 16 Sep 2022 01:11:40 +0800 Subject: [PATCH] adapter deviceauth ipc service Signed-off-by: beiling.xie --- frameworks/inc/ipc_service.h | 2 ++ frameworks/src/ipc_service.c | 16 +----------- frameworks/src/standard/ipc_adapt.cpp | 18 +++++++------ .../src/standard/ipc_dev_auth_proxy.cpp | 25 ++++--------------- frameworks/src/standard/ipc_dev_auth_stub.cpp | 7 +----- services/BUILD.gn | 15 ++++++++++- services/device_auth.c | 6 +++++ 7 files changed, 39 insertions(+), 50 deletions(-) diff --git a/frameworks/inc/ipc_service.h b/frameworks/inc/ipc_service.h index e3eb11b..ed73555 100755 --- a/frameworks/inc/ipc_service.h +++ b/frameworks/inc/ipc_service.h @@ -20,6 +20,8 @@ extern "C" { #endif +int DeviceAuthIpcInit(); + #ifdef __cplusplus } #endif diff --git a/frameworks/src/ipc_service.c b/frameworks/src/ipc_service.c index afc21fc..3db6bb5 100644 --- a/frameworks/src/ipc_service.c +++ b/frameworks/src/ipc_service.c @@ -1038,20 +1038,10 @@ int32_t MainRescInit(void) return HC_SUCCESS; } -int32_t main(int32_t argc, char const *argv[]) +int DeviceAuthIpcInit() { uintptr_t serviceCtx = 0x0; int32_t ret; - HcCondition cond; - - (void)argc; - (void)argv; - LOGI("device authentication service starting ..."); - ret = InitDeviceAuthService(); - if (ret != HC_SUCCESS) { - LOGE("device auth service main, InitDeviceAuthService failed, ret %d", ret); - return 1; - } ret = MainRescInit(); if (ret != HC_SUCCESS) { @@ -1070,10 +1060,6 @@ int32_t main(int32_t argc, char const *argv[]) } (void)AddMethodMap(serviceCtx); LOGI("device authentication service register to IPC manager done, service running..."); - (void)memset_s(&cond, sizeof(cond), 0, sizeof(cond)); - InitHcCond(&cond, NULL); - cond.wait(&cond); - DestroyHcCond(&cond); return 0; } diff --git a/frameworks/src/standard/ipc_adapt.cpp b/frameworks/src/standard/ipc_adapt.cpp index 3dd4ec8..3910726 100644 --- a/frameworks/src/standard/ipc_adapt.cpp +++ b/frameworks/src/standard/ipc_adapt.cpp @@ -23,12 +23,14 @@ #include "ipc_dev_auth_stub.h" #include "ipc_sdk.h" #include "ipc_service.h" -#include "iservice_registry.h" #include "securec.h" #include "system_ability_definition.h" +#include "ipc_center.h" + using namespace std; using namespace OHOS; +static IpcCenter *g_deviceIpc = nullptr; namespace { static const int32_t BUFF_MAX_SZ = 128; static const int32_t IPC_CALL_BACK_MAX_NODES = 64; @@ -1335,19 +1337,19 @@ void DestroyServiceInstance(uintptr_t *ipcInstance) int32_t AddDevAuthServiceToManager(uintptr_t *serviceCtx) { - int32_t ret = ERR_OK; + int32_t ret = HC_SUCCESS; ServiceDevAuth *sPtr = nullptr; - sptr sysMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (sysMgr == nullptr) { - return HC_ERR_IPC_GET_SERVICE; - } sPtr = new(std::nothrow) ServiceDevAuth(); if (sPtr == nullptr) { return HC_ERR_ALLOC_MEMORY; } - ret = sysMgr->AddSystemAbility(DEVICE_AUTH_SERVICE_ID, sPtr); - if (ret != ERR_OK) { + sPtr->isDSoftBusObj = false; + if (!g_deviceIpc->Init(true, static_cast(sPtr))) { + LOGE("deviceIpc init failed"); + } + ret = IPCSkeleton::SetDeviceAuthObj(sPtr); + if (ret != true) { LOGE("add service failed"); delete sPtr; return HC_ERROR; diff --git a/frameworks/src/standard/ipc_dev_auth_proxy.cpp b/frameworks/src/standard/ipc_dev_auth_proxy.cpp index bc3abeb..c493f7a 100644 --- a/frameworks/src/standard/ipc_dev_auth_proxy.cpp +++ b/frameworks/src/standard/ipc_dev_auth_proxy.cpp @@ -19,9 +19,9 @@ #include "hc_log.h" #include "ipc_adapt.h" #include "ipc_sdk.h" -#include "iservice_registry.h" #include "system_ability_definition.h" + namespace OHOS { ProxyDevAuth::ProxyDevAuth(const sptr &impl) : IRemoteProxy(impl) {} @@ -33,7 +33,7 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re { int32_t ret; sptr remote = nullptr; - MessageOption option = { MessageOption::TF_SYNC }; + MessageOption option; LOGI("ProxyDevAuth, SendRequest..."); remote = Remote(); @@ -42,9 +42,6 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re return HC_ERR_IPC_INTERNAL_FAILED; } - if (withSync == false) { - option = { MessageOption::TF_ASYNC }; - } ret = remote->SendRequest(DEV_AUTH_CALL_REQUEST, dataParcel, replyParcel, option); LOGI("SendRequest done, ret %d", ret); (ret == ERR_NONE) ? replyParcel.ReadInt32(ret) : (ret = HC_ERR_IPC_INTERNAL_FAILED); @@ -53,15 +50,8 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re bool ProxyDevAuth::ServiceRunning(void) { - auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (saMgr == nullptr) { - return false; - } - auto daSa = saMgr->GetSystemAbility(DEVICE_AUTH_SERVICE_ID); - if (daSa == nullptr) { - return false; - } - return true; + auto daSa = IPCSkeleton::GetDeviceAuthObj(); + return daSa != nullptr; } int32_t ProxyDevAuthData::EncodeCallRequest(int32_t type, const uint8_t *param, int32_t paramSz) @@ -117,12 +107,7 @@ int32_t ProxyDevAuthData::FinalCallRequest(int32_t methodId) sptr ProxyDevAuthData::GetProxy() const { - auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (saMgr == nullptr) { - LOGE("GetSystemAbilityManager failed"); - return nullptr; - } - auto daSa = saMgr->GetSystemAbility(DEVICE_AUTH_SERVICE_ID); + auto daSa = IPCSkeleton::GetDeviceAuthObj(); if (daSa == nullptr) { LOGE("GetSystemAbility failed"); return nullptr; diff --git a/frameworks/src/standard/ipc_dev_auth_stub.cpp b/frameworks/src/standard/ipc_dev_auth_stub.cpp index e33b770..648bc3b 100644 --- a/frameworks/src/standard/ipc_dev_auth_stub.cpp +++ b/frameworks/src/standard/ipc_dev_auth_stub.cpp @@ -286,12 +286,7 @@ void ServiceDevAuth::ActCallback(int32_t objIdx, int32_t callbackId, bool sync, LOGW("nothing to do, callback id %d, remote object id %d", callbackId, objIdx); return; } - MessageOption option(MessageOption::TF_SYNC); - option.SetWaitTime(DEV_AUTH_CALL_WAIT_TIME); - if (!sync) { - option.SetFlags(MessageOption::TF_ASYNC); - option.SetWaitTime(0); - } + MessageOption option; std::lock_guard autoLock(g_cBMutex); sptr proxy = iface_cast(g_cbStub[objIdx].cbStub); proxy->DoCallBack(callbackId, cbHook, dataParcel, reply, option); diff --git a/services/BUILD.gn b/services/BUILD.gn index b2cdb17..ce6e24b 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -142,9 +142,14 @@ if (defined(ohos_lite)) { "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//third_party/json/include", + "${frameworks_path}/inc", + "${dev_frameworks_path}/inc/permission_adapter", ] sources = deviceauth_files + sources += deviceauth_ipc_files + sources += permission_adapter_files + sources += [ "${frameworks_path}/src/ipc_service.c" ] cflags = [ "-DHILOG_ENABLE" ] defines = deviceauth_defines cflags += build_flags @@ -164,6 +169,7 @@ if (defined(ohos_lite)) { external_deps = [ "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", ] if (support_jsapi) { external_deps += [ "os_account_standard:os_account_innerkits" ] @@ -238,6 +244,12 @@ if (defined(ohos_lite)) { sources = deviceauth_ipc_files sources += permission_adapter_files sources += [ "${frameworks_path}/src/ipc_sdk.c" ] + sources += [ "${os_adapter_path}/impl/src/hc_log.c" ] + sources += [ "${os_adapter_path}/impl/src/linux/hc_types.c" ] + sources += [ "${os_adapter_path}/impl/src/hc_mutex.c" ] + sources += [ "${common_lib_path}/impl/src/json_utils.c" ] + sources += [ "${common_lib_path}/impl/src/string_util.c" ] + sources += [ "${common_lib_path}/impl/src/clib_types.c" ] defines = [ "__LINUX__", @@ -250,9 +262,10 @@ if (defined(ohos_lite)) { } deps = [ - "${deps_adapter_path}:${hal_module_name}", "//third_party/cJSON:cjson_static", "//utils/native/base:utils", + "//third_party/bounds_checking_function:libsec_shared", + "//third_party/cJSON:cjson_static", ] external_deps = [ diff --git a/services/device_auth.c b/services/device_auth.c index e09dce4..16f6200 100644 --- a/services/device_auth.c +++ b/services/device_auth.c @@ -14,6 +14,7 @@ */ #include "device_auth.h" +#include "ipc_service.h" #include "alg_loader.h" #include "callback_manager.h" @@ -241,6 +242,11 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) DestroyGmAndGa(); return res; } + res = DeviceAuthIpcInit(); + if (res != HC_SUCCESS) { + DestroyGmAndGa(); + return res; + } SetInitStatus(); LOGI("[End]: [Service]: Init device auth service successfully!"); return HC_SUCCESS; -- 2.25.1