From d387ebf235e22977ac234f9bf5d0db6ba0ac19cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=96=E5=89=91=E6=A1=A5?= Date: Sat, 26 Oct 2024 11:50:49 +0800 Subject: [PATCH] deviceauth SA standardization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 赖剑桥 --- BUILD.gn | 5 +- bundle.json | 1 + frameworks/inc/deviceauth_sa.h | 59 + frameworks/inc/standard/ipc_dev_auth_stub.h | 18 +- frameworks/src/deviceauth_sa.cpp | 1507 +++++++++++++++++ .../lite/{ => client}/ipc_callback_proxy.c | 180 +- .../lite/{ => client}/ipc_dev_auth_proxy.c | 0 .../src/lite/{ => server}/ipc_callback_stub.c | 166 +- .../src/lite/{ => server}/ipc_dev_auth_stub.c | 0 .../{ => client}/ipc_callback_proxy.cpp | 0 .../{ => client}/ipc_dev_auth_proxy.cpp | 2 +- frameworks/src/standard/ipc_adapt.cpp | 1 - .../{ => server}/ipc_callback_stub.cpp | 0 .../{ => server}/ipc_dev_auth_stub.cpp | 43 +- services/BUILD.gn | 116 +- services/deviceauth.gni | 8 +- services/deviceauth_service.cfg | 28 + services/sa/sa_profile/4701.json | 12 + services/sa/sa_profile/BUILD.gn | 19 + 19 files changed, 1901 insertions(+), 264 deletions(-) create mode 100644 frameworks/inc/deviceauth_sa.h create mode 100644 frameworks/src/deviceauth_sa.cpp rename frameworks/src/lite/{ => client}/ipc_callback_proxy.c (96%) rename frameworks/src/lite/{ => client}/ipc_dev_auth_proxy.c (100%) rename frameworks/src/lite/{ => server}/ipc_callback_stub.c (96%) rename frameworks/src/lite/{ => server}/ipc_dev_auth_stub.c (100%) rename frameworks/src/standard/{ => client}/ipc_callback_proxy.cpp (100%) rename frameworks/src/standard/{ => client}/ipc_dev_auth_proxy.cpp (98%) rename frameworks/src/standard/{ => server}/ipc_callback_stub.cpp (100%) rename frameworks/src/standard/{ => server}/ipc_dev_auth_stub.cpp (89%) create mode 100644 services/deviceauth_service.cfg create mode 100644 services/sa/sa_profile/4701.json create mode 100644 services/sa/sa_profile/BUILD.gn diff --git a/BUILD.gn b/BUILD.gn index dcd18c66..615646b8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -21,7 +21,10 @@ group("deviceauth_sdk_build") { group("deviceauth_service_build") { if (os_level == "standard" || os_level == "small") { - deps = [ "services:deviceauth_service" ] + deps = [ + "services:deviceauth_service", + "services/sa/sa_profile:deviceauth_sa_profile", + ] } } diff --git a/bundle.json b/bundle.json index f6e2a9a1..4077b255 100644 --- a/bundle.json +++ b/bundle.json @@ -61,6 +61,7 @@ "openssl", "os_account", "samgr", + "safwk", "ipc" ] }, diff --git a/frameworks/inc/deviceauth_sa.h b/frameworks/inc/deviceauth_sa.h new file mode 100644 index 00000000..2890f069 --- /dev/null +++ b/frameworks/inc/deviceauth_sa.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024-2024 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_AUTH_SA_H +#define DEVICE_AUTH_SA_H + +#include +#include "system_ability.h" +#include "iremote_broker.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +#include "ipc_dev_auth_stub.h" + +namespace OHOS { + +constexpr int SA_ID_DEVAUTH_SERVICE = 4701; + +class DeviceAuthAbility : public SystemAbility, public ServiceDevAuth { + DECLARE_SYSTEM_ABILITY(DeviceAuthAbility); + +public: + DISALLOW_COPY_AND_MOVE(DeviceAuthAbility); + DeviceAuthAbility(int saId, bool runOnCreate); + virtual ~DeviceAuthAbility(); + + int32_t Dump(int32_t fd, const std::vector &args) override; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; + + static sptr GetInstance(); + static void DestroyInstance(); + +protected: + void OnStart() override; + void OnStop() override; + +private: + static std::mutex g_instanceLock; + static sptr g_instance; + + DeviceAuthAbility(); +}; + +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/frameworks/inc/standard/ipc_dev_auth_stub.h b/frameworks/inc/standard/ipc_dev_auth_stub.h index 8ffbb381..eb8f53af 100755 --- a/frameworks/inc/standard/ipc_dev_auth_stub.h +++ b/frameworks/inc/standard/ipc_dev_auth_stub.h @@ -16,9 +16,10 @@ #ifndef IPC_DEV_AUTH_STUB_H #define IPC_DEV_AUTH_STUB_H +#include "iremote_stub.h" + #include "ipc_iface.h" #include "ipc_adapt.h" -#include "iremote_stub.h" namespace OHOS { typedef struct { @@ -32,7 +33,7 @@ class ServiceDevAuth : public IRemoteStub { public: ServiceDevAuth(bool serialInvokeFlag = true); ~ServiceDevAuth() override; - int32_t Dump(int32_t fd, const std::vector& args) override; + int32_t Dump(int32_t fd, const std::vector &args) override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; void ResetCallMap(void); @@ -43,13 +44,16 @@ public: static void ActCallback(int32_t objIdx, int32_t callbackId, bool sync, uintptr_t cbHook, MessageParcel &dataParcel, MessageParcel &reply); -private: - int32_t maxCallMapSz = MAX_CALLMAP_SIZE; - IpcServiceCallMap *callMapTable = nullptr; - int32_t callMapElemNum = 0; - IpcServiceCall GetCallMethodByMethodId(int32_t methodId); +protected: + int32_t HandleRestoreCall(MessageParcel &data, MessageParcel &reply); int32_t HandleDeviceAuthCall(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + +private: + int32_t maxCallMapSz = MAX_CALLMAP_SIZE; + IpcServiceCallMap *standardCallMapTable = nullptr; + int32_t callMapElemNum = 0; + IpcServiceCall GetCallMethodByMethodId(int32_t methodId); }; class DevAuthDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/frameworks/src/deviceauth_sa.cpp b/frameworks/src/deviceauth_sa.cpp new file mode 100644 index 00000000..fca0fbda --- /dev/null +++ b/frameworks/src/deviceauth_sa.cpp @@ -0,0 +1,1507 @@ +/* + * Copyright (C) 2024-2024 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 +#include + +#include "hc_log.h" +#include "device_auth.h" +#include "device_auth_defines.h" +#include "ipc_adapt.h" +#include "hc_condition.h" +#include "ipc_dev_auth_stub.h" +#include "ipc_sdk.h" +#include "common_defs.h" +#include "hc_thread.h" +#include "securec.h" +#include "hc_string_vector.h" +#include "hidump_adapter.h" +#include "string_ex.h" + +#include "deviceauth_sa.h" + +namespace OHOS { + +static const int32_t IPC_RESULT_NUM_1 = 1; +static const int32_t IPC_RESULT_NUM_2 = 2; +static const char *SERVICE_APP_ID = "deviceauth_service"; +static DeviceGroupManager g_devGroupMgrMethod = {nullptr}; +static GroupAuthManager g_groupAuthMgrMethod = {nullptr}; +static DeviceAuthCallback g_bindCbAdt = {nullptr}; +static DeviceAuthCallback g_authCbAdt = {nullptr}; +static DataChangeListener g_listenCbAdt = {nullptr}; +static const uint32_t RESTORE_CODE = 14701; + +REGISTER_SYSTEM_ABILITY_BY_ID(DeviceAuthAbility, SA_ID_DEVAUTH_SERVICE, true); + +std::mutex DeviceAuthAbility::g_instanceLock; +sptr DeviceAuthAbility::g_instance; + +DeviceAuthAbility::DeviceAuthAbility(int saId, bool runOnCreate = true) : SystemAbility(saId, runOnCreate) +{ + LOGI("DeviceAuthAbility"); +} + +DeviceAuthAbility::~DeviceAuthAbility() +{ + LOGI("~DeviceAuthAbility"); +} + +static inline int32_t GetAndValSize32Param(const IpcDataInfo *ipcParams, + int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize) +{ + int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, paramSize); + if ((*paramSize) != sizeof(int32_t) || ret != HC_SUCCESS) { + LOGE("get param error, type %d", paramType); + return HC_ERR_IPC_BAD_PARAM; + } + return HC_SUCCESS; +} + +static inline int32_t GetAndValSize64Param(const IpcDataInfo *ipcParams, + int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize) +{ + int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, paramSize); + if ((*paramSize) != sizeof(int64_t) || ret != HC_SUCCESS) { + LOGE("get param error, type %d", paramType); + return HC_ERR_IPC_BAD_PARAM; + } + return HC_SUCCESS; +} + +static inline int32_t GetAndValSizeCbParam(const IpcDataInfo *ipcParams, + int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize) +{ + int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, paramSize); + if ((*paramSize) != sizeof(DeviceAuthCallback) || ret != HC_SUCCESS) { + LOGE("get param error, type %d", paramType); + return HC_ERR_IPC_BAD_PARAM; + } + return HC_SUCCESS; +} + +static inline int32_t GetAndValNullParam(const IpcDataInfo *ipcParams, + int32_t paramNum, int32_t paramType, uint8_t *param, int32_t *paramSize) +{ + int32_t ret = GetIpcRequestParamByType(ipcParams, paramNum, paramType, param, nullptr); + if (param == nullptr || ret != HC_SUCCESS) { + LOGE("get param error, type %d", paramType); + return HC_ERR_IPC_BAD_PARAM; + } + return HC_SUCCESS; +} + +static int32_t BindRequestIdWithAppId(const char *data) +{ + const char *appId = nullptr; + int32_t ret; + int64_t requestId = -1; + CJson *dataJson = CreateJsonFromString(data); + if (dataJson == nullptr) { + LOGE("failed to create json from string!"); + return HC_ERR_JSON_CREATE; + } + + appId = GetStringFromJson(dataJson, FIELD_APP_ID); + if (appId == nullptr) { + LOGE("failed to get appId from json object!"); + FreeJson(dataJson); + return HC_ERROR; + } + (void)GetInt64FromJson(dataJson, FIELD_REQUEST_ID, &requestId); + ret = AddReqIdByAppId(appId, requestId); + FreeJson(dataJson); + return ret; +} + +static int32_t IpcServiceGmRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + const char *appId = nullptr; + const DeviceAuthCallback *callback = nullptr; + int32_t cbObjIdx = -1; + int32_t inOutLen; + + LOGI("starting ..."); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + + inOutLen = sizeof(DeviceAuthCallback); + ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_DEV_AUTH); + if (ret != HC_SUCCESS) { + LOGE("add ipc callback failed"); + return HC_ERROR; + } + + inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT); + DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH); + return HC_ERR_IPC_BAD_PARAM; + } + AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_DEV_AUTH); + InitDeviceAuthCbCtx(&g_bindCbAdt, CB_TYPE_DEV_AUTH); + callRet = g_devGroupMgrMethod.regCallback(appId, &g_bindCbAdt); + if (callRet != HC_SUCCESS) { + DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH); + } + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmUnRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet = HC_SUCCESS; + int32_t ret; + const char *appId = nullptr; + + LOGI("starting ..."); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + + DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + const char *appId = nullptr; + const DataChangeListener *callback = nullptr; + static int32_t registered = 0; + int32_t cbObjIdx = -1; + int32_t inOutLen; + + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + + inOutLen = sizeof(DataChangeListener); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_LISTERNER, (uint8_t *)&callback, &inOutLen); + if ((ret != HC_SUCCESS) || (inOutLen != sizeof(DataChangeListener))) { + LOGE("get param error, type %d", PARAM_TYPE_LISTERNER); + return HC_ERR_IPC_BAD_PARAM; + } + + ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DataChangeListener), CB_TYPE_LISTENER); + if (ret != HC_SUCCESS) { + LOGE("add ipc callback failed"); + return HC_ERROR; + } + + inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT); + DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH); + return HC_ERR_IPC_BAD_PARAM; + } + AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_LISTENER); + + callRet = HC_SUCCESS; + if (registered == 0) { + InitDevAuthListenerCbCtx(&g_listenCbAdt); + callRet = g_devGroupMgrMethod.regDataChangeListener(SERVICE_APP_ID, &g_listenCbAdt); + if (callRet == HC_SUCCESS) { + registered = 1; + } else { + DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER); + } + } + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmUnRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet = HC_SUCCESS; + int32_t ret; + const char *appId = nullptr; + + LOGI("starting ..."); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t osAccountId; + int64_t requestId = 0; + int32_t inOutLen; + const char *createParams = nullptr; + const char *appId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CREATE_PARAMS, (uint8_t *)&createParams, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CREATE_PARAMS); + return HC_ERR_IPC_BAD_PARAM; + } + ret = AddReqIdByAppId(appId, requestId); + if (ret != 0) { + LOGE("bind request id by app id failed"); + return ret; + } + callRet = g_devGroupMgrMethod.createGroup(osAccountId, requestId, appId, createParams); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t osAccountId; + int64_t requestId = 0; + int32_t inOutLen; + const char *appId = nullptr; + const char *delParams = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS); + return HC_ERR_IPC_BAD_PARAM; + } + ret = AddReqIdByAppId(appId, requestId); + if (ret != 0) { + LOGE("bind request id by app id failed"); + return ret; + } + callRet = g_devGroupMgrMethod.deleteGroup(osAccountId, requestId, appId, delParams); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + int64_t requestId = 0; + const char *addParams = nullptr; + const char *appId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = AddReqIdByAppId(appId, requestId); + if (ret != HC_SUCCESS) { + return ret; + } + callRet = g_devGroupMgrMethod.addMemberToGroup(osAccountId, requestId, appId, addParams); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + int64_t requestId = 0; + const char *delParams = nullptr; + const char *appId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS); + return HC_ERR_IPC_BAD_PARAM; + } + ret = AddReqIdByAppId(appId, requestId); + if (ret != 0) { + LOGE("bind request id by app id failed"); + return ret; + } + callRet = g_devGroupMgrMethod.deleteMemberFromGroup(osAccountId, requestId, appId, delParams); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *addParams = nullptr; + const char *appId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return HC_ERR_IPC_BAD_PARAM; + } + callRet = g_devGroupMgrMethod.addMultiMembersToGroup(osAccountId, appId, addParams); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *delParams = nullptr; + const char *appId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_APPID); + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, nullptr); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS); + return HC_ERR_IPC_BAD_PARAM; + } + callRet = g_devGroupMgrMethod.delMultiMembersFromGroup(osAccountId, appId, delParams); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t dataLen; + int32_t inOutLen; + int64_t requestId = 0; + const uint8_t *data = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + + dataLen = 0; + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, &dataLen); + if ((dataLen <= 0) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d, data length %d", PARAM_TYPE_COMM_DATA, dataLen); + return HC_ERR_IPC_BAD_PARAM; + } + ret = BindRequestIdWithAppId(reinterpret_cast(data)); + if (ret != HC_SUCCESS) { + return ret; + } + callRet = g_devGroupMgrMethod.processData(requestId, data, dataLen); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + const char *reqJsonStr = nullptr; + char *registerInfo = nullptr; + + LOGI("starting ..."); + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + callRet = g_devGroupMgrMethod.getRegisterInfo(reqJsonStr, ®isterInfo); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_1), sizeof(int32_t)); + if (registerInfo != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO, + (const uint8_t *)registerInfo, HcStrlen(registerInfo) + 1); + g_devGroupMgrMethod.destroyInfo(®isterInfo); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO, nullptr, 0); + } + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmCheckAccessToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *groupId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.checkAccessToGroup(osAccountId, appId, groupId); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *queryParams = nullptr; + char *returnInfoList = nullptr; + uint32_t returnInfoNum = 0; + + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.getPkInfoList(osAccountId, appId, queryParams, &returnInfoList, &returnInfoNum); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_2), sizeof(int32_t)); + if (returnInfoList != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnInfoList, + HcStrlen(returnInfoList) + 1); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, nullptr, 0); + } + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&returnInfoNum, sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + g_devGroupMgrMethod.destroyInfo(&returnInfoList); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *groupId = nullptr; + char *groupInfo = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.getGroupInfoById(osAccountId, appId, groupId, &groupInfo); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_1), sizeof(int32_t)); + if (groupInfo != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)groupInfo, HcStrlen(groupInfo) + 1); + g_devGroupMgrMethod.destroyInfo(&groupInfo); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, nullptr, 0); + } + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *queryParams = nullptr; + char *outGroups = nullptr; + uint32_t groupNum = 0; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.getGroupInfo(osAccountId, appId, queryParams, &outGroups, &groupNum); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_2), sizeof(int32_t)); + if (outGroups != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, nullptr, 0); + } + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + g_devGroupMgrMethod.destroyInfo(&outGroups); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t groupType = 0; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + char *outGroups = nullptr; + uint32_t groupNum = 0; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(groupType); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUP_TYPE, (uint8_t *)&groupType, &inOutLen); + if ((inOutLen != sizeof(groupType)) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d", PARAM_TYPE_GROUP_TYPE); + return HC_ERR_IPC_BAD_PARAM; + } + + callRet = g_devGroupMgrMethod.getJoinedGroups(osAccountId, appId, groupType, &outGroups, &groupNum); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_2), sizeof(int32_t)); + if (outGroups != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1); + g_devGroupMgrMethod.destroyInfo(&outGroups); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, nullptr, 0); + } + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *peerUdid = nullptr; + char *outGroups = nullptr; + uint32_t groupNum = 0; + + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.getRelatedGroups(osAccountId, appId, peerUdid, &outGroups, &groupNum); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_2), sizeof(int32_t)); + if (outGroups != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, nullptr, 0); + } + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t)); + g_devGroupMgrMethod.destroyInfo(&outGroups); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *peerUdid = nullptr; + const char *groupId = nullptr; + char *outDevInfo = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.getDeviceInfoById(osAccountId, appId, peerUdid, groupId, &outDevInfo); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_1), sizeof(int32_t)); + if (outDevInfo != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, + (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1); + g_devGroupMgrMethod.destroyInfo(&outDevInfo); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, nullptr, 0); + } + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + const char *appId = nullptr; + const char *groupId = nullptr; + char *outDevInfo = nullptr; + uint32_t outDevNum = 0; + + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + callRet = g_devGroupMgrMethod.getTrustedDevices(osAccountId, appId, groupId, &outDevInfo, &outDevNum); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, + reinterpret_cast(&IPC_RESULT_NUM_2), sizeof(int32_t)); + if (outDevInfo != nullptr) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, + (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1); + } else { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, nullptr, 0); + } + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&outDevNum, sizeof(int32_t)); + g_devGroupMgrMethod.destroyInfo(&outDevInfo); + return (ret == HC_SUCCESS) ? ret : HC_ERROR; +} + +static int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + int32_t inOutLen; + int32_t osAccountId; + bool bRet = false; + const char *appId = nullptr; + const char *udid = nullptr; + const char *groupId = nullptr; + + LOGI("starting ..."); + inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&udid, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + bRet = g_devGroupMgrMethod.isDeviceInGroup(osAccountId, appId, groupId, udid); + callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceGmCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + int64_t requestId = 0; + const char *appId = nullptr; + + LOGI("starting ..."); + int32_t inOutLen = sizeof(int64_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d", PARAM_TYPE_REQID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + g_devGroupMgrMethod.cancelRequest(requestId, appId); + LOGI("process done, ipc ret %d", ret); + return ret; +} + +static int32_t IpcServiceGaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + const DeviceAuthCallback *gaCallback = nullptr; + int64_t reqId = 0; + uint8_t *data = nullptr; + uint32_t dataLen = 0; + int32_t inOutLen; + int32_t cbObjIdx = -1; + + LOGI("starting ..."); + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)&dataLen); + if ((data == nullptr) || (dataLen == 0) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA); + return HC_ERR_IPC_BAD_PARAM; + } + inOutLen = sizeof(DeviceAuthCallback); + ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + /* add call back */ + ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)gaCallback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH); + if (ret != HC_SUCCESS) { + LOGE("add ipc callback failed"); + return ret; + } + inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT); + DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true); + return HC_ERR_IPC_BAD_PARAM; + } + AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH); + InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH); + callRet = g_groupAuthMgrMethod.processData(reqId, data, dataLen, &g_authCbAdt); + if (callRet != HC_SUCCESS) { + DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true); + } + return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); +} + +static int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + DeviceAuthCallback *gaCallback = nullptr; + int32_t osAccountId; + int64_t reqId = 0; + const char *authParams = nullptr; + int32_t cbObjIdx = -1; + + int32_t inOutLen = sizeof(int32_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&reqId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + inOutLen = sizeof(DeviceAuthCallback); + ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + + ret = AddIpcCallBackByReqId(reqId, (const uint8_t *)gaCallback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH); + if (ret != HC_SUCCESS) { + return ret; + } + + inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT); + DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true); + return ret; + } + + AddIpcCbObjByReqId(reqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH); + InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH); + ret = g_groupAuthMgrMethod.authDevice(osAccountId, reqId, authParams, &g_authCbAdt); + if (ret != HC_SUCCESS) { + DelIpcCallBackByReqId(reqId, CB_TYPE_TMP_DEV_AUTH, true); + } + + return IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&ret), sizeof(int32_t)); +} + +static int32_t IpcServiceGaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + int64_t requestId = 0; + const char *appId = nullptr; + + LOGI("starting ..."); + int32_t inOutLen = sizeof(int64_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d", PARAM_TYPE_REQID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + g_groupAuthMgrMethod.cancelRequest(requestId, appId); + DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true); + LOGI("process done, ipc ret %d", ret); + return ret; +} + +static int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + int32_t osAccountId; + const char *pseudonymId = nullptr; + + LOGI("starting ..."); + int32_t inOutLen = sizeof(int64_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_PSEUDONYM_ID, (uint8_t *)&pseudonymId, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + char *realInfo = nullptr; + ret = g_groupAuthMgrMethod.getRealInfo(osAccountId, pseudonymId, &realInfo); + if ((realInfo != nullptr) && (ret == HC_SUCCESS)) { + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)realInfo, + HcStrlen(realInfo) + 1); + HcFree(realInfo); + } else { + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, nullptr, 0); + } + LOGI("process done, ipc ret %d", ret); + return ret; +} + +static int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + int32_t osAccountId; + const char *indexKey = nullptr; + + LOGI("starting ..."); + int32_t inOutLen = sizeof(int64_t); + ret = GetAndValSize32Param(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_INDEX_KEY, (uint8_t *)&indexKey, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + + char *pseudonymId = nullptr; + ret = g_groupAuthMgrMethod.getPseudonymId(osAccountId, indexKey, &pseudonymId); + if ((pseudonymId != nullptr) && (ret == HC_SUCCESS)) { + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)pseudonymId, + HcStrlen(pseudonymId) + 1); + HcFree(pseudonymId); + } else { + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, nullptr, 0); + } + LOGI("process done, ipc ret %d", ret); + return ret; +} + +static int32_t IpcServiceDaProcessCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + int32_t operationCode = 0; + const char *reqJsonStr = nullptr; + char *returnData = nullptr; + + LOGI("starting ..."); + int32_t inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OPCODE, (uint8_t *)&operationCode, &inOutLen); + if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d", PARAM_TYPE_OPCODE); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = ProcessCredential(operationCode, reqJsonStr, &returnData); + if (ret != HC_SUCCESS) { + LOGI("call ProcessCredential failed %d", ret); + } + if (returnData != nullptr) { + ret = IpcEncodeCallReply( + outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnData, HcStrlen(returnData) + 1); + HcFree(returnData); + } else { + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, nullptr, 0); + } + LOGI("process done, ipc ret %d", ret); + return ret; +} + +static int32_t IpcServiceDaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + const DeviceAuthCallback *callback = nullptr; + int64_t authReqId = 0; + const char *authParams = nullptr; + int32_t inOutLen; + int32_t cbObjIdx = -1; + + LOGI("starting ..."); + inOutLen = sizeof(int64_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen); + if ((ret != HC_SUCCESS) || (inOutLen != sizeof(authReqId))) { + LOGE("get param error, type %d", PARAM_TYPE_REQID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(DeviceAuthCallback); + ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = AddIpcCallBackByReqId( + authReqId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT); + DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true); + return HC_ERR_IPC_BAD_PARAM; + } + AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH); + InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH); + callRet = ProcessAuthDevice(authReqId, authParams, &g_authCbAdt); + if (callRet != HC_SUCCESS) { + DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true); + } + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceDaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t callRet; + int32_t ret; + DeviceAuthCallback *callback = nullptr; + int64_t authReqId = 0; + const char *authParams = nullptr; + int32_t inOutLen; + int32_t cbObjIdx = -1; + + LOGI("starting ..."); + inOutLen = sizeof(int64_t); + ret = GetAndValSize64Param(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + inOutLen = sizeof(DeviceAuthCallback); + ret = GetAndValSizeCbParam(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, &inOutLen); + if (ret != HC_SUCCESS) { + return ret; + } + ret = AddIpcCallBackByReqId( + authReqId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH); + if (ret != HC_SUCCESS) { + LOGE("add ipc callback failed"); + return ret; + } + inOutLen = sizeof(int32_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen); + if (ret != HC_SUCCESS) { + LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT); + DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true); + return HC_ERR_IPC_BAD_PARAM; + } + AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH); + InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH); + callRet = StartAuthDevice(authReqId, authParams, &g_authCbAdt); + if (callRet != HC_SUCCESS) { + DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true); + } + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, + reinterpret_cast(&callRet), sizeof(int32_t)); + LOGI("process done, call ret %d, ipc ret %d", callRet, ret); + return ret; +} + +static int32_t IpcServiceDaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) +{ + int32_t ret; + int64_t requestId = 0; + const char *authParams = nullptr; + + LOGI("starting ..."); + int32_t inOutLen = sizeof(int64_t); + ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen); + if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) { + LOGE("get param error, type %d", PARAM_TYPE_REQID); + return HC_ERR_IPC_BAD_PARAM; + } + ret = GetAndValNullParam(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, nullptr); + if (ret != HC_SUCCESS) { + return ret; + } + ret = CancelAuthRequest(requestId, authParams); + DelIpcCallBackByReqId(requestId, CB_TYPE_TMP_DEV_AUTH, true); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, reinterpret_cast(&ret), sizeof(int32_t)); + LOGI("process done, ipc ret %d", ret); + return ret; +} + +static int32_t MainRescInit(void) +{ + int32_t ret; + + LOGI("DeviceAuthAbility MainRescInit starting ..."); + ret = InitIpcCallBackList(); + if (ret != HC_SUCCESS) { + return ret; + } + const DeviceGroupManager *gmInst = GetGmInstance(); + const GroupAuthManager *gaInst = GetGaInstance(); + if ((gmInst == nullptr) || (gaInst == nullptr)) { + DeInitIpcCallBackList(); + LOGE("DeviceAuthAbility MainInit GetGmInstance or GetGaInstance failed"); + return HC_ERROR; + } + g_devGroupMgrMethod = (DeviceGroupManager)(*gmInst); + g_groupAuthMgrMethod = (GroupAuthManager)(*gaInst); + InitDevAuthListenerCbCtx(&g_listenCbAdt); + ret = gmInst->regDataChangeListener(SERVICE_APP_ID, &g_listenCbAdt); + if (ret != HC_SUCCESS) { + DeInitIpcCallBackList(); + LOGE("DeviceAuthAbility MainInit, register ipc listener failed, ret %d", ret); + return HC_ERROR; + } + + LOGI("DeviceAuthAbility MainRescInit process done"); + return HC_SUCCESS; +} + +#ifndef DEV_AUTH_FUZZ_TEST +static void DeMainRescInit(void) +{ + if (g_devGroupMgrMethod.unRegDataChangeListener != nullptr) { + (void)g_devGroupMgrMethod.unRegDataChangeListener(SERVICE_APP_ID); + } + DeInitIpcCallBackList(); +} +#endif + +__attribute__((no_sanitize("cfi"))) static uint32_t SaSetIpcCallMap( + uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId) +{ + if ((method == nullptr) || (methodId <= 0)) { + return static_cast(HC_ERR_INVALID_PARAMS); + } + + DeviceAuthAbility *service = reinterpret_cast(ipcInstance); + return static_cast(service->SetCallMap(method, methodId)); +} + +int32_t SaAddMethodMap(uintptr_t ipcInstance) +{ + uint32_t ret = 0; + using IpcCallMap = struct { + int32_t (*func)(const IpcDataInfo*, int32_t, uintptr_t); + uint32_t id; + }; + + IpcCallMap ipcCallMaps[] = { + {IpcServiceGmRegCallback, IPC_CALL_ID_REG_CB}, + {IpcServiceGmUnRegCallback, IPC_CALL_ID_UNREG_CB}, + {IpcServiceGmRegDataChangeListener, IPC_CALL_ID_REG_LISTENER}, + {IpcServiceGmUnRegDataChangeListener, IPC_CALL_ID_UNREG_LISTENER}, + {IpcServiceGmCreateGroup, IPC_CALL_ID_CREATE_GROUP}, + {IpcServiceGmDelGroup, IPC_CALL_ID_DEL_GROUP}, + {IpcServiceGmAddMemberToGroup, IPC_CALL_ID_ADD_GROUP_MEMBER}, + {IpcServiceGmDelMemberFromGroup, IPC_CALL_ID_DEL_GROUP_MEMBER}, + {IpcServiceGmAddMultiMembersToGroup, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS}, + {IpcServiceGmDelMultiMembersFromGroup, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS}, + {IpcServiceGmProcessData, IPC_CALL_ID_GM_PROC_DATA}, + {IpcServiceGmApplyRegisterInfo, IPC_CALL_ID_APPLY_REG_INFO}, + {IpcServiceGmCheckAccessToGroup, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP}, + {IpcServiceGmGetPkInfoList, IPC_CALL_ID_GET_PK_INFO_LIST}, + {IpcServiceGmGetGroupInfoById, IPC_CALL_ID_GET_GROUP_INFO}, + {IpcServiceGmGetGroupInfo, IPC_CALL_ID_SEARCH_GROUPS}, + {IpcServiceGmGetJoinedGroups, IPC_CALL_ID_GET_JOINED_GROUPS}, + {IpcServiceGmGetRelatedGroups, IPC_CALL_ID_GET_RELATED_GROUPS}, + {IpcServiceGmGetDeviceInfoById, IPC_CALL_ID_GET_DEV_INFO_BY_ID}, + {IpcServiceGmGetTrustedDevices, IPC_CALL_ID_GET_TRUST_DEVICES}, + {IpcServiceGmIsDeviceInGroup, IPC_CALL_ID_IS_DEV_IN_GROUP}, + {IpcServiceGmCancelRequest, IPC_CALL_GM_CANCEL_REQUEST}, + {IpcServiceGaProcessData, IPC_CALL_ID_GA_PROC_DATA}, + {IpcServiceGaAuthDevice, IPC_CALL_ID_AUTH_DEVICE}, + {IpcServiceGaCancelRequest, IPC_CALL_GA_CANCEL_REQUEST}, + {IpcServiceGaGetRealInfo, IPC_CALL_ID_GET_REAL_INFO}, + {IpcServiceGaGetPseudonymId, IPC_CALL_ID_GET_PSEUDONYM_ID}, + {IpcServiceDaProcessCredential, IPC_CALL_ID_PROCESS_CREDENTIAL}, + {IpcServiceDaAuthDevice, IPC_CALL_ID_DA_AUTH_DEVICE}, + {IpcServiceDaProcessData, IPC_CALL_ID_DA_PROC_DATA}, + {IpcServiceDaCancelRequest, IPC_CALL_ID_DA_CANCEL_REQUEST}, + }; + + for (uint32_t i = 0; i < sizeof(ipcCallMaps)/sizeof(ipcCallMaps[0]); i++) { + ret &= SaSetIpcCallMap(ipcInstance, ipcCallMaps[i].func, ipcCallMaps[i].id); + } + + return ret; +} + +sptr DeviceAuthAbility::GetInstance() +{ + std::lock_guard autoLock(g_instanceLock); + if (g_instance == nullptr) { + g_instance = new (std::nothrow) DeviceAuthAbility(SA_ID_DEVAUTH_SERVICE, true); + } + return g_instance; +} + +void DeviceAuthAbility::DestroyInstance() +{ + std::lock_guard autoLock(g_instanceLock); + if (g_instance != nullptr) { + delete g_instance; + g_instance = nullptr; + } + LOGI("DeviceAuthAbility DestroyInstance done"); +} + +int32_t DeviceAuthAbility::Dump(int32_t fd, const std::vector &args) +{ + std::vector strArgs; + for (auto arg : args) { + strArgs.emplace_back(Str16ToStr8(arg)); + } + uint32_t argc = strArgs.size(); + StringVector strArgVec = CreateStrVector(); + for (uint32_t i = 0; i < argc; i++) { + HcString strArg = CreateString(); + if (!StringSetPointer(&strArg, strArgs[i].c_str())) { + LOGE("Failed to set strArg!"); + DeleteString(&strArg); + continue; + } + if (strArgVec.pushBackT(&strArgVec, strArg) == nullptr) { + LOGE("Failed to push strArg to strArgVec!"); + DeleteString(&strArg); + } + } + DEV_AUTH_DUMP(fd, &strArgVec); + DestroyStrVector(&strArgVec); + return 0; +} + +void DeviceAuthAbility::OnStart() +{ + LOGI("DeviceAuthAbility starting ..."); + int32_t ret = InitDeviceAuthService(); + if (ret != HC_SUCCESS) { + LOGE("DeviceAuthAbility InitDeviceAuthService failed, ret %d", ret); + return; + } + + ret = MainRescInit(); + if (ret != HC_SUCCESS) { + DestroyDeviceAuthService(); + LOGE("device auth service main, init work failed"); + return; + } + + sptr serviceInstance = DeviceAuthAbility::GetInstance(); + if (serviceInstance == nullptr) { + LOGE("DeviceAuthAbility GetInstance Failed"); + DeMainRescInit(); + DestroyDeviceAuthService(); + return; + } + + uintptr_t serviceInstanceAddress = reinterpret_cast(serviceInstance.GetRefPtr()); + ret = SaAddMethodMap(serviceInstanceAddress); + if (ret != HC_SUCCESS) { + LOGW("DeviceAuthAbility SaAddMethodMap failed at least once."); + } + + if (!Publish(serviceInstance)) { + LOGE("DeviceAuthAbility Publish failed"); + DeviceAuthAbility::DestroyInstance(); + DeMainRescInit(); + DestroyDeviceAuthService(); + return; + } + LOGI("DeviceAuthAbility start success."); +} + +int32_t DeviceAuthAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + std::u16string readToken = data.ReadInterfaceToken(); + + bool isRestoreCall = ((code == RESTORE_CODE) && (readToken == std::u16string(u"OHOS.Updater.RestoreData"))); + if (readToken != GetDescriptor() && !isRestoreCall) { + LOGE("DeviceAuthAbility [IPC][C->S]: The proxy interface token is invalid!"); + return -1; + } + if (isRestoreCall) { + return HandleRestoreCall(data, reply); + } else { + return HandleDeviceAuthCall(code, data, reply, option); + } +} + +void DeviceAuthAbility::OnStop() +{ + LOGI("DeviceAuthAbility OnStop"); + DeviceAuthAbility::DestroyInstance(); + DeMainRescInit(); + DestroyDeviceAuthService(); +} + +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/src/lite/ipc_callback_proxy.c b/frameworks/src/lite/client/ipc_callback_proxy.c similarity index 96% rename from frameworks/src/lite/ipc_callback_proxy.c rename to frameworks/src/lite/client/ipc_callback_proxy.c index cedf9c65..4f653439 100644 --- a/frameworks/src/lite/ipc_callback_proxy.c +++ b/frameworks/src/lite/client/ipc_callback_proxy.c @@ -1,90 +1,90 @@ -/* - * 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. - */ - -#include "ipc_callback_proxy.h" -#include "hc_log.h" -#include "hc_types.h" -#include "ipc_adapt.h" -#include "ipc_skeleton.h" -#include "securec.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static void CbProxyFormReplyData(int32_t reqRetVal, IpcIo *replyDst, const IpcIo *replySrc) -{ - errno_t eno; - - if (reqRetVal != 0) { - *(int32_t *)(replyDst->bufferCur) = reqRetVal; - replyDst->bufferLeft = sizeof(int32_t); - return; - } - - LOGI("with reply data, length(%zu), flag(%u)", replySrc->bufferLeft, replySrc->flag); - eno = memcpy_s(replyDst->bufferCur, replyDst->bufferLeft, replySrc->bufferCur, replySrc->bufferLeft); - if (eno != EOK) { - replyDst->flag = 0; - LOGE("memory copy reply data failed"); - return; - } - replyDst->bufferLeft = replySrc->bufferLeft; - LOGI("out reply data, length(%zu)", replyDst->bufferLeft); - return; -} - -void CbProxySendRequest(SvcIdentity sid, int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo *reply) -{ - int32_t ret; - IpcIo *reqData = NULL; - int32_t dataSz; - uintptr_t outMsg = 0x0; - IpcIo replyTmp; - - ShowIpcSvcInfo(&(sid)); - reqData = (IpcIo *)InitIpcDataCache(IPC_DATA_BUFF_MAX_SZ); - if (reqData == NULL) { - return; - } - WriteInt32(reqData, callbackId); - WritePointer(reqData, cbHook); - dataSz = GetIpcIoDataLength((const IpcIo *)data); - LOGI("to form callback params data length(%d)", dataSz); - if (dataSz > 0) { - WriteUint32(reqData, dataSz); - if (!WriteBuffer(reqData, data->bufferBase + IpcIoBufferOffset(), dataSz)) { - HcFree((void *)reqData); - return; - } - } - /* callFlag: ipc mode is blocking or non blocking. */ - MessageOption option; - MessageOptionInit(&option); - option.flags = ((reply != NULL) ? TF_OP_SYNC : TF_OP_ASYNC); - ret = SendRequest(sid, DEV_AUTH_CALLBACK_REQUEST, reqData, &replyTmp, option, &outMsg); - LOGI("SendRequest(%d) done, return(%d)", option.flags, ret); - HcFree((void *)reqData); - if (reply == NULL) { - return; - } - CbProxyFormReplyData(ret, reply, &replyTmp); - FreeBuffer((void *)outMsg); - return; -} - -#ifdef __cplusplus -} -#endif +/* + * 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. + */ + +#include "ipc_callback_proxy.h" +#include "hc_log.h" +#include "hc_types.h" +#include "ipc_adapt.h" +#include "ipc_skeleton.h" +#include "securec.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static void CbProxyFormReplyData(int32_t reqRetVal, IpcIo *replyDst, const IpcIo *replySrc) +{ + errno_t eno; + + if (reqRetVal != 0) { + *(int32_t *)(replyDst->bufferCur) = reqRetVal; + replyDst->bufferLeft = sizeof(int32_t); + return; + } + + LOGI("with reply data, length(%zu), flag(%u)", replySrc->bufferLeft, replySrc->flag); + eno = memcpy_s(replyDst->bufferCur, replyDst->bufferLeft, replySrc->bufferCur, replySrc->bufferLeft); + if (eno != EOK) { + replyDst->flag = 0; + LOGE("memory copy reply data failed"); + return; + } + replyDst->bufferLeft = replySrc->bufferLeft; + LOGI("out reply data, length(%zu)", replyDst->bufferLeft); + return; +} + +void CbProxySendRequest(SvcIdentity sid, int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo *reply) +{ + int32_t ret; + IpcIo *reqData = NULL; + int32_t dataSz; + uintptr_t outMsg = 0x0; + IpcIo replyTmp; + + ShowIpcSvcInfo(&(sid)); + reqData = (IpcIo *)InitIpcDataCache(IPC_DATA_BUFF_MAX_SZ); + if (reqData == NULL) { + return; + } + WriteInt32(reqData, callbackId); + WritePointer(reqData, cbHook); + dataSz = GetIpcIoDataLength((const IpcIo *)data); + LOGI("to form callback params data length(%d)", dataSz); + if (dataSz > 0) { + WriteUint32(reqData, dataSz); + if (!WriteBuffer(reqData, data->bufferBase + IpcIoBufferOffset(), dataSz)) { + HcFree((void *)reqData); + return; + } + } + /* callFlag: ipc mode is blocking or non blocking. */ + MessageOption option; + MessageOptionInit(&option); + option.flags = ((reply != NULL) ? TF_OP_SYNC : TF_OP_ASYNC); + ret = SendRequest(sid, DEV_AUTH_CALLBACK_REQUEST, reqData, &replyTmp, option, &outMsg); + LOGI("SendRequest(%d) done, return(%d)", option.flags, ret); + HcFree((void *)reqData); + if (reply == NULL) { + return; + } + CbProxyFormReplyData(ret, reply, &replyTmp); + FreeBuffer((void *)outMsg); + return; +} + +#ifdef __cplusplus +} +#endif diff --git a/frameworks/src/lite/ipc_dev_auth_proxy.c b/frameworks/src/lite/client/ipc_dev_auth_proxy.c similarity index 100% rename from frameworks/src/lite/ipc_dev_auth_proxy.c rename to frameworks/src/lite/client/ipc_dev_auth_proxy.c diff --git a/frameworks/src/lite/ipc_callback_stub.c b/frameworks/src/lite/server/ipc_callback_stub.c similarity index 96% rename from frameworks/src/lite/ipc_callback_stub.c rename to frameworks/src/lite/server/ipc_callback_stub.c index 2239efc0..1538e36a 100644 --- a/frameworks/src/lite/ipc_callback_stub.c +++ b/frameworks/src/lite/server/ipc_callback_stub.c @@ -1,83 +1,83 @@ -/* - * 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. - */ - -#include "ipc_callback_stub.h" -#include "common_defs.h" -#include "device_auth_defines.h" -#include "hc_log.h" -#include "ipc_adapt.h" -#include "ipc_iface.h" -#include "ipc_skeleton.h" -#include "securec.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static void DoCallBack(int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo *reply) -{ - int32_t ret; - int32_t i; - IpcDataInfo cbDataCache[MAX_REQUEST_PARAMS_NUM] = { { 0 } }; - - if (cbHook == 0x0) { - LOGE("Invalid call back hook"); - return; - } - - uint32_t len = 0; - ReadUint32(data, &len); /* skip flat object length information */ - for (i = 0; i < MAX_REQUEST_PARAMS_NUM; i++) { - ret = DecodeIpcData((uintptr_t)(data), &(cbDataCache[i].type), - &(cbDataCache[i].val), &(cbDataCache[i].valSz)); - if (ret != HC_SUCCESS) { - LOGE("decode failed, ret %d", ret); - return; - } - } - ProcCbHook(callbackId, cbHook, cbDataCache, MAX_REQUEST_PARAMS_NUM, (uintptr_t)(reply)); - return; -} - -int32_t CbStubOnRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) -{ - (void)option; - int32_t callbackId; - uintptr_t cbHook = 0x0; - - LOGI("enter invoking callback..."); - if (data == NULL) { - LOGE("invalid param"); - return -1; - } - - LOGI("receive ipc transact code(%u)", code); - switch (code) { - case DEV_AUTH_CALLBACK_REQUEST: - ReadInt32(data, &callbackId); - cbHook = ReadPointer(data); - DoCallBack(callbackId, cbHook, data, reply); - break; - default: - LOGE("Invoke callback cmd code(%u) error", code); - break; - } - LOGI("Invoke callback done, result(%d)", HC_SUCCESS); - return HC_SUCCESS; -} - -#ifdef __cplusplus -} -#endif +/* + * 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. + */ + +#include "ipc_callback_stub.h" +#include "common_defs.h" +#include "device_auth_defines.h" +#include "hc_log.h" +#include "ipc_adapt.h" +#include "ipc_iface.h" +#include "ipc_skeleton.h" +#include "securec.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static void DoCallBack(int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo *reply) +{ + int32_t ret; + int32_t i; + IpcDataInfo cbDataCache[MAX_REQUEST_PARAMS_NUM] = { { 0 } }; + + if (cbHook == 0x0) { + LOGE("Invalid call back hook"); + return; + } + + uint32_t len = 0; + ReadUint32(data, &len); /* skip flat object length information */ + for (i = 0; i < MAX_REQUEST_PARAMS_NUM; i++) { + ret = DecodeIpcData((uintptr_t)(data), &(cbDataCache[i].type), + &(cbDataCache[i].val), &(cbDataCache[i].valSz)); + if (ret != HC_SUCCESS) { + LOGE("decode failed, ret %d", ret); + return; + } + } + ProcCbHook(callbackId, cbHook, cbDataCache, MAX_REQUEST_PARAMS_NUM, (uintptr_t)(reply)); + return; +} + +int32_t CbStubOnRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) +{ + (void)option; + int32_t callbackId; + uintptr_t cbHook = 0x0; + + LOGI("enter invoking callback..."); + if (data == NULL) { + LOGE("invalid param"); + return -1; + } + + LOGI("receive ipc transact code(%u)", code); + switch (code) { + case DEV_AUTH_CALLBACK_REQUEST: + ReadInt32(data, &callbackId); + cbHook = ReadPointer(data); + DoCallBack(callbackId, cbHook, data, reply); + break; + default: + LOGE("Invoke callback cmd code(%u) error", code); + break; + } + LOGI("Invoke callback done, result(%d)", HC_SUCCESS); + return HC_SUCCESS; +} + +#ifdef __cplusplus +} +#endif diff --git a/frameworks/src/lite/ipc_dev_auth_stub.c b/frameworks/src/lite/server/ipc_dev_auth_stub.c similarity index 100% rename from frameworks/src/lite/ipc_dev_auth_stub.c rename to frameworks/src/lite/server/ipc_dev_auth_stub.c diff --git a/frameworks/src/standard/ipc_callback_proxy.cpp b/frameworks/src/standard/client/ipc_callback_proxy.cpp similarity index 100% rename from frameworks/src/standard/ipc_callback_proxy.cpp rename to frameworks/src/standard/client/ipc_callback_proxy.cpp diff --git a/frameworks/src/standard/ipc_dev_auth_proxy.cpp b/frameworks/src/standard/client/ipc_dev_auth_proxy.cpp similarity index 98% rename from frameworks/src/standard/ipc_dev_auth_proxy.cpp rename to frameworks/src/standard/client/ipc_dev_auth_proxy.cpp index f5c240f8..f7185adb 100644 --- a/frameworks/src/standard/ipc_dev_auth_proxy.cpp +++ b/frameworks/src/standard/client/ipc_dev_auth_proxy.cpp @@ -47,7 +47,7 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re ret = remote->SendRequest(static_cast(DevAuthInterfaceCode::DEV_AUTH_CALL_REQUEST), dataParcel, replyParcel, option); if (ret != ERR_NONE) { - LOGE("SendRequest fail."); + LOGE("ProxyDevAuth::DoCallRequest SendRequest fail. ret = %d", ret); ret = HC_ERR_IPC_INTERNAL_FAILED; } else { replyParcel.ReadInt32(ret); diff --git a/frameworks/src/standard/ipc_adapt.cpp b/frameworks/src/standard/ipc_adapt.cpp index 846a74b5..6e2af115 100644 --- a/frameworks/src/standard/ipc_adapt.cpp +++ b/frameworks/src/standard/ipc_adapt.cpp @@ -22,7 +22,6 @@ #include "ipc_dev_auth_proxy.h" #include "ipc_dev_auth_stub.h" #include "ipc_sdk.h" -#include "ipc_service.h" #include "ipc_skeleton.h" #include "iservice_registry.h" #include "securec.h" diff --git a/frameworks/src/standard/ipc_callback_stub.cpp b/frameworks/src/standard/server/ipc_callback_stub.cpp similarity index 100% rename from frameworks/src/standard/ipc_callback_stub.cpp rename to frameworks/src/standard/server/ipc_callback_stub.cpp diff --git a/frameworks/src/standard/ipc_dev_auth_stub.cpp b/frameworks/src/standard/server/ipc_dev_auth_stub.cpp similarity index 89% rename from frameworks/src/standard/ipc_dev_auth_stub.cpp rename to frameworks/src/standard/server/ipc_dev_auth_stub.cpp index aff2d241..d46ee262 100644 --- a/frameworks/src/standard/ipc_dev_auth_stub.cpp +++ b/frameworks/src/standard/server/ipc_dev_auth_stub.cpp @@ -57,14 +57,14 @@ ServiceDevAuth::ServiceDevAuth(bool serialInvokeFlag) : IRemoteStub(serialInvoke ServiceDevAuth::~ServiceDevAuth() { maxCallMapSz = MAX_CALLMAP_SIZE; - if (callMapTable != nullptr) { - delete[] callMapTable; - callMapTable = nullptr; + if (standardCallMapTable != nullptr) { + delete[] standardCallMapTable; + standardCallMapTable = nullptr; } callMapElemNum = 0; } -int32_t ServiceDevAuth::Dump(int32_t fd, const std::vector& args) +int32_t ServiceDevAuth::Dump(int32_t fd, const std::vector &args) { std::vector strArgs; for (auto arg : args) { @@ -93,13 +93,13 @@ IpcServiceCall ServiceDevAuth::GetCallMethodByMethodId(int32_t methodId) { int32_t i; - if (callMapTable == nullptr) { + if (standardCallMapTable == nullptr) { return nullptr; } for (i = 0; i < maxCallMapSz; i++) { - if ((callMapTable[i].methodId == methodId) && (callMapTable[i].method != nullptr)) { - return callMapTable[i].method; + if ((standardCallMapTable[i].methodId == methodId) && (standardCallMapTable[i].method != nullptr)) { + return standardCallMapTable[i].method; } } return nullptr; @@ -202,7 +202,7 @@ static void InitCbStubTable() return; } -static int32_t HandleRestoreCall(MessageParcel &data, MessageParcel &reply) +int32_t ServiceDevAuth::HandleRestoreCall(MessageParcel &data, MessageParcel &reply) { #ifdef DEV_AUTH_SERVICE_BUILD int32_t osAccountId = DEFAULT_UPGRADE_OS_ACCOUNT_ID; @@ -245,11 +245,13 @@ int32_t ServiceDevAuth::HandleDeviceAuthCall(uint32_t code, MessageParcel &data, } serviceCall = GetCallMethodByMethodId(methodId); if (serviceCall == nullptr) { + LOGE("ServiceDevAuth::HandleDeviceAuthCall serviceCall is nullptr, methodId: %d", methodId); ret = HC_ERR_IPC_METHOD_ID_INVALID; break; } ret = DecodeCallRequest(data, reqParams, MAX_REQUEST_PARAMS_NUM, reqParamNum); if (ret != HC_SUCCESS) { + LOGE("ServiceDevAuth::HandleDeviceAuthCall DecodeCallRequest ret: %d", ret); break; } if (reqParamNum < (MAX_REQUEST_PARAMS_NUM - 1)) { @@ -294,23 +296,23 @@ int32_t ServiceDevAuth::SetCallMap(IpcServiceCall method, int32_t methodId) if ((1 + callMapElemNum) > maxCallMapSz) { maxCallMapSz += MAX_CALLMAP_SIZE; - if (callMapTable != nullptr) { - callMapTmp = callMapTable; - callMapTable = nullptr; + if (standardCallMapTable != nullptr) { + callMapTmp = standardCallMapTable; + standardCallMapTable = nullptr; } } - if (callMapTable == nullptr) { - callMapTable = new(std::nothrow) IpcServiceCallMap[maxCallMapSz]; - if (callMapTable == nullptr) { + if (standardCallMapTable == nullptr) { + standardCallMapTable = new(std::nothrow) IpcServiceCallMap[maxCallMapSz]; + if (standardCallMapTable == nullptr) { return HC_ERR_ALLOC_MEMORY; } len = sizeof(IpcServiceCallMap) * maxCallMapSz; - (void)memset_s(callMapTable, len, 0, len); + (void)memset_s(standardCallMapTable, len, 0, len); if (callMapTmp != nullptr) { - eno = memcpy_s(callMapTable, len, callMapTmp, (sizeof(IpcServiceCallMap) * callMapElemNum)); + eno = memcpy_s(standardCallMapTable, len, callMapTmp, (sizeof(IpcServiceCallMap) * callMapElemNum)); if (eno != EOK) { - delete[] callMapTable; - callMapTable = callMapTmp; + delete[] standardCallMapTable; + standardCallMapTable = callMapTmp; maxCallMapSz -= MAX_CALLMAP_SIZE; return HC_ERR_MEMORY_COPY; } @@ -318,8 +320,9 @@ int32_t ServiceDevAuth::SetCallMap(IpcServiceCall method, int32_t methodId) callMapTmp = nullptr; } } - callMapTable[callMapElemNum].method = method; - callMapTable[callMapElemNum].methodId = methodId; + + standardCallMapTable[callMapElemNum].method = method; + standardCallMapTable[callMapElemNum].methodId = methodId; callMapElemNum++; return HC_SUCCESS; } diff --git a/services/BUILD.gn b/services/BUILD.gn index 2ae72f6c..ea4086ac 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -238,68 +238,13 @@ if (os_level == "mini" || os_level == "small") { } } - ohos_prebuilt_etc("auth_service.rc") { - source = "${frameworks_path}/src/standard/deviceauth_service.cfg" + ohos_prebuilt_etc("pre_deviceauth_service") { + source = "${deviceauth_path}/services/deviceauth_service.cfg" relative_install_dir = "init" subsystem_name = "security" part_name = "device_auth" } - group("etc") { - deps = [ ":auth_service.rc" ] - } - - ohos_executable("deviceauth_service") { - subsystem_name = "security" - part_name = "device_auth" - install_enable = true - - include_dirs += [ - "${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 += [ "${frameworks_path}/src/ipc_service.c" ] - - defines = [ "HILOG_ENABLE" ] - defines += [ "DEV_AUTH_HIVIEW_ENABLE" ] - defines += [ "DEV_AUTH_SERVICE_BUILD" ] - cflags = build_flags - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - integer_overflow = true - boundary_sanitize = true - ubsan = true - debug = false - } - - deps = [ - ":auth_service.rc", - ":deviceauth", - "${deps_adapter_path}:${hal_module_name}", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "bounds_checking_function:libsec_shared", - "cJSON:cjson", - "c_utils:utils", - "hilog:libhilog", - "init:libbegetutil", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] - } - ohos_shared_library("deviceauth_sdk") { subsystem_name = "security" part_name = "device_auth" @@ -352,4 +297,61 @@ if (os_level == "mini" || os_level == "small") { "samgr:samgr_proxy", ] } + + ohos_shared_library("deviceauth_service") { + subsystem_name = "security" + part_name = "device_auth" + version_script = "device_auth.map" + public_configs = [ ":deviceauth_config" ] + branch_protector_ret = "pac_ret" + + sanitize = { + cfi = true + cfi_cross_dso = true + integer_overflow = true + boundary_sanitize = true + ubsan = true + debug = false + } + + cflags = build_flags + cflags += [ "-fPIC" ] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + include_dirs += [ + "${frameworks_path}/inc", + "${frameworks_path}/inc/standard", + "${dev_frameworks_path}/inc/permission_adapter", + "${dev_frameworks_path}/inc/hiview_adapter", + ] + + defines = [ "HILOG_ENABLE" ] + defines += [ "DEV_AUTH_HIVIEW_ENABLE" ] + defines += [ "DEV_AUTH_SERVICE_BUILD" ] + + sources = deviceauth_ipc_files + sources += permission_adapter_files + sources += [ "${frameworks_path}/src/deviceauth_sa.cpp" ] + + deps = [ + ":deviceauth", + ":pre_deviceauth_service", + "${deps_adapter_path}:${hal_module_name}", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "bounds_checking_function:libsec_shared", + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + } } diff --git a/services/deviceauth.gni b/services/deviceauth.gni index f5b2b980..78aca60d 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -436,10 +436,10 @@ if (defined(ohos_lite)) { deviceauth_ipc_files = [ "${frameworks_path}/src/${ipc_adapt_path}/ipc_adapt.${ipc_src_suffix}", - "${frameworks_path}/src/${ipc_adapt_path}/ipc_dev_auth_proxy.${ipc_src_suffix}", - "${frameworks_path}/src/${ipc_adapt_path}/ipc_dev_auth_stub.${ipc_src_suffix}", - "${frameworks_path}/src/${ipc_adapt_path}/ipc_callback_proxy.${ipc_src_suffix}", - "${frameworks_path}/src/${ipc_adapt_path}/ipc_callback_stub.${ipc_src_suffix}", + "${frameworks_path}/src/${ipc_adapt_path}/client/ipc_dev_auth_proxy.${ipc_src_suffix}", + "${frameworks_path}/src/${ipc_adapt_path}/server/ipc_dev_auth_stub.${ipc_src_suffix}", + "${frameworks_path}/src/${ipc_adapt_path}/client/ipc_callback_proxy.${ipc_src_suffix}", + "${frameworks_path}/src/${ipc_adapt_path}/server/ipc_callback_stub.${ipc_src_suffix}", ] identity_manager_inc = [ "${identity_manager_path}/inc" ] diff --git a/services/deviceauth_service.cfg b/services/deviceauth_service.cfg new file mode 100644 index 00000000..e94e8643 --- /dev/null +++ b/services/deviceauth_service.cfg @@ -0,0 +1,28 @@ +{ + "jobs" : [{ + "name" : "post-fs-data", + "cmds" : [ + "mkdir /data/service/el1/public/deviceauth 0711 deviceauth deviceauth", + "mkdir /data/service/el1/public/deviceauth/account 0711 deviceauth deviceauth", + "mkdir /data/service/el1/public/deviceauth/pseudonym 0711 deviceauth deviceauth", + "start deviceauth_service" + ] + } + ], + "services" : [{ + "name" : "deviceauth_service", + "path" : ["/system/bin/sa_main", "/system/profile/deviceauth_service.json"], + "uid" : "deviceauth", + "gid" : ["deviceauth", "shell", "netsys_socket"], + "secon" : "u:r:deviceauth_service:s0", + "permission" : [ + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.GET_NETWORK_INFO", + "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS", + "ohos.permission.MANAGE_DEVICE_AUTH_CRED", + "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + ] + } + ] +} diff --git a/services/sa/sa_profile/4701.json b/services/sa/sa_profile/4701.json new file mode 100644 index 00000000..6cf2ac46 --- /dev/null +++ b/services/sa/sa_profile/4701.json @@ -0,0 +1,12 @@ +{ + "process": "deviceauth_service", + "systemability": [ + { + "name": 4701, + "libpath": "libdeviceauth_service.z.so", + "run-on-create": true, + "distributed": false, + "dump_level": 1 + } + ] +} \ No newline at end of file diff --git a/services/sa/sa_profile/BUILD.gn b/services/sa/sa_profile/BUILD.gn new file mode 100644 index 00000000..92b9b448 --- /dev/null +++ b/services/sa/sa_profile/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2024-2024 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. + +import("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("deviceauth_sa_profile") { + part_name = "device_auth" + sources = [ "4701.json" ] +}