117fd14ceSopenharmony_ci/* 217fd14ceSopenharmony_ci * Copyright (C) 2021-2023 Huawei Device Co., Ltd. 317fd14ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 417fd14ceSopenharmony_ci * you may not use this file except in compliance with the License. 517fd14ceSopenharmony_ci * You may obtain a copy of the License at 617fd14ceSopenharmony_ci * 717fd14ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 817fd14ceSopenharmony_ci * 917fd14ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1017fd14ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1117fd14ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1217fd14ceSopenharmony_ci * See the License for the specific language governing permissions and 1317fd14ceSopenharmony_ci * limitations under the License. 1417fd14ceSopenharmony_ci */ 1517fd14ceSopenharmony_ci 1617fd14ceSopenharmony_ci#include "ipc_sdk.h" 1717fd14ceSopenharmony_ci 1817fd14ceSopenharmony_ci#include "common_defs.h" 1917fd14ceSopenharmony_ci#include "device_auth_defines.h" 2017fd14ceSopenharmony_ci#include "device_auth.h" 2117fd14ceSopenharmony_ci#include "hc_log.h" 2217fd14ceSopenharmony_ci#include "hc_mutex.h" 2317fd14ceSopenharmony_ci 2417fd14ceSopenharmony_ci#include "ipc_adapt.h" 2517fd14ceSopenharmony_ci#include "securec.h" 2617fd14ceSopenharmony_ci 2717fd14ceSopenharmony_ci#ifdef __cplusplus 2817fd14ceSopenharmony_ciextern "C" { 2917fd14ceSopenharmony_ci#endif 3017fd14ceSopenharmony_ci 3117fd14ceSopenharmony_ci#define IPC_DATA_CACHES_1 1 3217fd14ceSopenharmony_ci#define IPC_DATA_CACHES_3 3 3317fd14ceSopenharmony_ci#define IPC_DATA_CACHES_4 4 3417fd14ceSopenharmony_ci#define REPLAY_CACHE_NUM(caches) (sizeof(caches) / sizeof(IpcDataInfo)) 3517fd14ceSopenharmony_ci#define IPC_APPID_LEN 128 3617fd14ceSopenharmony_ci 3717fd14ceSopenharmony_ci#define IS_COMM_DATA_VALID(dPtr, dLen) (((dPtr) != NULL) && ((dLen) > 0) && ((dLen) <= 4096)) 3817fd14ceSopenharmony_ci 3917fd14ceSopenharmony_cistatic const int32_t IPC_RESULT_NUM_1 = 1; 4017fd14ceSopenharmony_cistatic const int32_t IPC_RESULT_NUM_2 = 2; 4117fd14ceSopenharmony_ci 4217fd14ceSopenharmony_citypedef struct { 4317fd14ceSopenharmony_ci uintptr_t inst; 4417fd14ceSopenharmony_ci char appId[IPC_APPID_LEN]; 4517fd14ceSopenharmony_ci} IpcProxyCbInfo; 4617fd14ceSopenharmony_cistatic IpcProxyCbInfo g_ipcProxyCbList = { 0 }; 4717fd14ceSopenharmony_cistatic IpcProxyCbInfo g_ipcListenerCbList = { 0 }; 4817fd14ceSopenharmony_cistatic HcMutex g_ipcMutex; 4917fd14ceSopenharmony_ci 5017fd14ceSopenharmony_cistatic bool IsStrInvalid(const char *str) 5117fd14ceSopenharmony_ci{ 5217fd14ceSopenharmony_ci return (str == NULL || str[0] == 0); 5317fd14ceSopenharmony_ci} 5417fd14ceSopenharmony_ci 5517fd14ceSopenharmony_cistatic void DelIpcCliCallbackCtx(const char *appId, IpcProxyCbInfo *cbCache) 5617fd14ceSopenharmony_ci{ 5717fd14ceSopenharmony_ci int32_t ret; 5817fd14ceSopenharmony_ci 5917fd14ceSopenharmony_ci if (cbCache->appId[0] == 0) { 6017fd14ceSopenharmony_ci return; 6117fd14ceSopenharmony_ci } 6217fd14ceSopenharmony_ci (void)LockHcMutex(&g_ipcMutex); 6317fd14ceSopenharmony_ci ret = memcmp(appId, cbCache->appId, HcStrlen(cbCache->appId) + 1); 6417fd14ceSopenharmony_ci if (ret == 0) { 6517fd14ceSopenharmony_ci cbCache->appId[0] = 0; 6617fd14ceSopenharmony_ci } 6717fd14ceSopenharmony_ci UnlockHcMutex(&g_ipcMutex); 6817fd14ceSopenharmony_ci return; 6917fd14ceSopenharmony_ci} 7017fd14ceSopenharmony_ci 7117fd14ceSopenharmony_cistatic void AddIpcCliCallbackCtx(const char *appId, uintptr_t cbInst, IpcProxyCbInfo *cbCache) 7217fd14ceSopenharmony_ci{ 7317fd14ceSopenharmony_ci errno_t eno; 7417fd14ceSopenharmony_ci 7517fd14ceSopenharmony_ci (void)LockHcMutex(&g_ipcMutex); 7617fd14ceSopenharmony_ci eno = memcpy_s(cbCache->appId, IPC_APPID_LEN, appId, HcStrlen(appId) + 1); 7717fd14ceSopenharmony_ci if (eno != EOK) { 7817fd14ceSopenharmony_ci UnlockHcMutex(&g_ipcMutex); 7917fd14ceSopenharmony_ci LOGE("memory copy failed"); 8017fd14ceSopenharmony_ci return; 8117fd14ceSopenharmony_ci } 8217fd14ceSopenharmony_ci cbCache->inst = cbInst; 8317fd14ceSopenharmony_ci UnlockHcMutex(&g_ipcMutex); 8417fd14ceSopenharmony_ci} 8517fd14ceSopenharmony_ci 8617fd14ceSopenharmony_cistatic void GetIpcReplyByType(const IpcDataInfo *ipcData, 8717fd14ceSopenharmony_ci int32_t dataNum, int32_t type, uint8_t *outCache, int32_t *cacheLen) 8817fd14ceSopenharmony_ci{ 8917fd14ceSopenharmony_ci int32_t i; 9017fd14ceSopenharmony_ci errno_t eno; 9117fd14ceSopenharmony_ci 9217fd14ceSopenharmony_ci for (i = 0; i < dataNum; i++) { 9317fd14ceSopenharmony_ci if (ipcData[i].type != type) { 9417fd14ceSopenharmony_ci continue; 9517fd14ceSopenharmony_ci } 9617fd14ceSopenharmony_ci switch (type) { 9717fd14ceSopenharmony_ci case PARAM_TYPE_REG_INFO: 9817fd14ceSopenharmony_ci case PARAM_TYPE_DEVICE_INFO: 9917fd14ceSopenharmony_ci case PARAM_TYPE_GROUP_INFO: 10017fd14ceSopenharmony_ci case PARAM_TYPE_RETURN_DATA: 10117fd14ceSopenharmony_ci *(uint8_t **)outCache = ipcData[i].val; 10217fd14ceSopenharmony_ci break; 10317fd14ceSopenharmony_ci case PARAM_TYPE_IPC_RESULT: 10417fd14ceSopenharmony_ci case PARAM_TYPE_IPC_RESULT_NUM: 10517fd14ceSopenharmony_ci case PARAM_TYPE_COMM_DATA: 10617fd14ceSopenharmony_ci case PARAM_TYPE_DATA_NUM: 10717fd14ceSopenharmony_ci eno = memcpy_s(outCache, *cacheLen, ipcData[i].val, ipcData[i].valSz); 10817fd14ceSopenharmony_ci if (eno != EOK) { 10917fd14ceSopenharmony_ci break; 11017fd14ceSopenharmony_ci } 11117fd14ceSopenharmony_ci *cacheLen = ipcData[i].valSz; 11217fd14ceSopenharmony_ci break; 11317fd14ceSopenharmony_ci default: 11417fd14ceSopenharmony_ci LOGE("un-expectation type case"); 11517fd14ceSopenharmony_ci break; 11617fd14ceSopenharmony_ci } 11717fd14ceSopenharmony_ci } 11817fd14ceSopenharmony_ci return; 11917fd14ceSopenharmony_ci} 12017fd14ceSopenharmony_ci 12117fd14ceSopenharmony_cistatic int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *callback) 12217fd14ceSopenharmony_ci{ 12317fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 12417fd14ceSopenharmony_ci int32_t ret; 12517fd14ceSopenharmony_ci 12617fd14ceSopenharmony_ci LOGI("starting ..."); 12717fd14ceSopenharmony_ci if (IsStrInvalid(appId) || callback == NULL) { 12817fd14ceSopenharmony_ci LOGE("invalid params"); 12917fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 13017fd14ceSopenharmony_ci } 13117fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 13217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 13317fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 13417fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 13517fd14ceSopenharmony_ci } 13617fd14ceSopenharmony_ci 13717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 13817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 13917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_APPID); 14017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 14117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 14217fd14ceSopenharmony_ci } 14317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); 14417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 14517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB); 14617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 14717fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 14817fd14ceSopenharmony_ci } 14917fd14ceSopenharmony_ci SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID); 15017fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_CB, true); 15117fd14ceSopenharmony_ci if (ret == HC_SUCCESS) { 15217fd14ceSopenharmony_ci AddIpcCliCallbackCtx(appId, 0, &g_ipcProxyCbList); 15317fd14ceSopenharmony_ci } 15417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 15517fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 15617fd14ceSopenharmony_ci return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED; 15717fd14ceSopenharmony_ci} 15817fd14ceSopenharmony_ci 15917fd14ceSopenharmony_cistatic int32_t IpcGmUnRegCallback(const char *appId) 16017fd14ceSopenharmony_ci{ 16117fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 16217fd14ceSopenharmony_ci int32_t ret; 16317fd14ceSopenharmony_ci 16417fd14ceSopenharmony_ci LOGI("starting ..."); 16517fd14ceSopenharmony_ci if (IsStrInvalid(appId)) { 16617fd14ceSopenharmony_ci LOGE("invalid params"); 16717fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 16817fd14ceSopenharmony_ci } 16917fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 17017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 17117fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 17217fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 17317fd14ceSopenharmony_ci } 17417fd14ceSopenharmony_ci 17517fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 17617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 17717fd14ceSopenharmony_ci LOGE("set request param failed, ret %d", ret); 17817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 17917fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 18017fd14ceSopenharmony_ci } 18117fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_CB, true); 18217fd14ceSopenharmony_ci if (ret == HC_SUCCESS) { 18317fd14ceSopenharmony_ci DelIpcCliCallbackCtx(appId, &g_ipcProxyCbList); 18417fd14ceSopenharmony_ci } 18517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 18617fd14ceSopenharmony_ci LOGI("process done, ret %d", HC_SUCCESS); 18717fd14ceSopenharmony_ci return HC_SUCCESS; 18817fd14ceSopenharmony_ci} 18917fd14ceSopenharmony_ci 19017fd14ceSopenharmony_cistatic int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeListener *listener) 19117fd14ceSopenharmony_ci{ 19217fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 19317fd14ceSopenharmony_ci int32_t ret; 19417fd14ceSopenharmony_ci 19517fd14ceSopenharmony_ci LOGI("starting ..."); 19617fd14ceSopenharmony_ci if (IsStrInvalid(appId) || (listener == NULL)) { 19717fd14ceSopenharmony_ci LOGE("invalid params"); 19817fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 19917fd14ceSopenharmony_ci } 20017fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 20117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 20217fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 20317fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 20417fd14ceSopenharmony_ci } 20517fd14ceSopenharmony_ci 20617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 20717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 20817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_APPID); 20917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 21017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 21117fd14ceSopenharmony_ci } 21217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_LISTERNER, (const uint8_t *)listener, sizeof(*listener)); 21317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 21417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_LISTERNER); 21517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 21617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 21717fd14ceSopenharmony_ci } 21817fd14ceSopenharmony_ci SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID); 21917fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_LISTENER, true); 22017fd14ceSopenharmony_ci if (ret == HC_SUCCESS) { 22117fd14ceSopenharmony_ci AddIpcCliCallbackCtx(appId, 0, &g_ipcListenerCbList); 22217fd14ceSopenharmony_ci } 22317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 22417fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 22517fd14ceSopenharmony_ci return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED; 22617fd14ceSopenharmony_ci} 22717fd14ceSopenharmony_ci 22817fd14ceSopenharmony_cistatic int32_t IpcGmUnRegDataChangeListener(const char *appId) 22917fd14ceSopenharmony_ci{ 23017fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 23117fd14ceSopenharmony_ci int32_t ret; 23217fd14ceSopenharmony_ci 23317fd14ceSopenharmony_ci LOGI("starting ..."); 23417fd14ceSopenharmony_ci if (IsStrInvalid(appId)) { 23517fd14ceSopenharmony_ci LOGE("invalid params"); 23617fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 23717fd14ceSopenharmony_ci } 23817fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 23917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 24017fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 24117fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 24217fd14ceSopenharmony_ci } 24317fd14ceSopenharmony_ci 24417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 24517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 24617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d", ret); 24717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 24817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 24917fd14ceSopenharmony_ci } 25017fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_LISTENER, true); 25117fd14ceSopenharmony_ci if (ret == HC_SUCCESS) { 25217fd14ceSopenharmony_ci DelIpcCliCallbackCtx(appId, &g_ipcListenerCbList); 25317fd14ceSopenharmony_ci } 25417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 25517fd14ceSopenharmony_ci LOGI("process done"); 25617fd14ceSopenharmony_ci return HC_SUCCESS; 25717fd14ceSopenharmony_ci} 25817fd14ceSopenharmony_ci 25917fd14ceSopenharmony_cistatic int32_t EncodeCreateGroupParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, 26017fd14ceSopenharmony_ci const char *appId, const char *createParams) 26117fd14ceSopenharmony_ci{ 26217fd14ceSopenharmony_ci int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 26317fd14ceSopenharmony_ci sizeof(osAccountId)); 26417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 26517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 26617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 26717fd14ceSopenharmony_ci } 26817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); 26917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 27017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID); 27117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 27217fd14ceSopenharmony_ci } 27317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 27417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 27517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 27617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 27717fd14ceSopenharmony_ci } 27817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_CREATE_PARAMS, 27917fd14ceSopenharmony_ci (const uint8_t *)createParams, HcStrlen(createParams) + 1); 28017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 28117fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_CREATE_PARAMS); 28217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 28317fd14ceSopenharmony_ci } 28417fd14ceSopenharmony_ci return HC_SUCCESS; 28517fd14ceSopenharmony_ci} 28617fd14ceSopenharmony_ci 28717fd14ceSopenharmony_cistatic int32_t IpcGmCreateGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams) 28817fd14ceSopenharmony_ci{ 28917fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 29017fd14ceSopenharmony_ci int32_t ret; 29117fd14ceSopenharmony_ci int32_t inOutLen; 29217fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 29317fd14ceSopenharmony_ci 29417fd14ceSopenharmony_ci LOGI("starting ..."); 29517fd14ceSopenharmony_ci if (IsStrInvalid(createParams) || IsStrInvalid(appId)) { 29617fd14ceSopenharmony_ci LOGE("invalid params"); 29717fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 29817fd14ceSopenharmony_ci } 29917fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 30017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 30117fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 30217fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 30317fd14ceSopenharmony_ci } 30417fd14ceSopenharmony_ci ret = EncodeCreateGroupParams(callCtx, osAccountId, requestId, appId, createParams); 30517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 30617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 30717fd14ceSopenharmony_ci return ret; 30817fd14ceSopenharmony_ci } 30917fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_CREATE_GROUP, true); 31017fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 31117fd14ceSopenharmony_ci LOGE("ipc call failed"); 31217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 31317fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 31417fd14ceSopenharmony_ci } 31517fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 31617fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 31717fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 31817fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 31917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 32017fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 32117fd14ceSopenharmony_ci return ret; 32217fd14ceSopenharmony_ci} 32317fd14ceSopenharmony_ci 32417fd14ceSopenharmony_cistatic int32_t EncodeDeleteGroupParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, 32517fd14ceSopenharmony_ci const char *appId, const char *delParams) 32617fd14ceSopenharmony_ci{ 32717fd14ceSopenharmony_ci int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 32817fd14ceSopenharmony_ci sizeof(osAccountId)); 32917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 33017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 33117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 33217fd14ceSopenharmony_ci } 33317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); 33417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 33517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID); 33617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 33717fd14ceSopenharmony_ci } 33817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, HcStrlen(delParams) + 1); 33917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 34017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS); 34117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 34217fd14ceSopenharmony_ci } 34317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 34417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 34517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 34617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 34717fd14ceSopenharmony_ci } 34817fd14ceSopenharmony_ci return HC_SUCCESS; 34917fd14ceSopenharmony_ci} 35017fd14ceSopenharmony_ci 35117fd14ceSopenharmony_cistatic int32_t IpcGmDeleteGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams) 35217fd14ceSopenharmony_ci{ 35317fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 35417fd14ceSopenharmony_ci int32_t ret; 35517fd14ceSopenharmony_ci int32_t inOutLen; 35617fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 35717fd14ceSopenharmony_ci 35817fd14ceSopenharmony_ci LOGI("starting ..."); 35917fd14ceSopenharmony_ci if (IsStrInvalid(delParams) || IsStrInvalid(appId)) { 36017fd14ceSopenharmony_ci LOGE("invalid params"); 36117fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 36217fd14ceSopenharmony_ci } 36317fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 36417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 36517fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 36617fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 36717fd14ceSopenharmony_ci } 36817fd14ceSopenharmony_ci ret = EncodeDeleteGroupParams(callCtx, osAccountId, requestId, appId, delParams); 36917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 37017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 37117fd14ceSopenharmony_ci return ret; 37217fd14ceSopenharmony_ci } 37317fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP, true); 37417fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 37517fd14ceSopenharmony_ci LOGE("ipc call failed"); 37617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 37717fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 37817fd14ceSopenharmony_ci } 37917fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 38017fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 38117fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 38217fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 38317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 38417fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 38517fd14ceSopenharmony_ci return ret; 38617fd14ceSopenharmony_ci} 38717fd14ceSopenharmony_ci 38817fd14ceSopenharmony_cistatic int32_t EncodeAddMemberParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, 38917fd14ceSopenharmony_ci const char *appId, const char *addParams) 39017fd14ceSopenharmony_ci{ 39117fd14ceSopenharmony_ci int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 39217fd14ceSopenharmony_ci sizeof(osAccountId)); 39317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 39417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 39517fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 39617fd14ceSopenharmony_ci } 39717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); 39817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 39917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID); 40017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 40117fd14ceSopenharmony_ci } 40217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 40317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 40417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 40517fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 40617fd14ceSopenharmony_ci } 40717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, HcStrlen(addParams) + 1); 40817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 40917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_ADD_PARAMS); 41017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 41117fd14ceSopenharmony_ci } 41217fd14ceSopenharmony_ci return HC_SUCCESS; 41317fd14ceSopenharmony_ci} 41417fd14ceSopenharmony_ci 41517fd14ceSopenharmony_cistatic int32_t IpcGmAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) 41617fd14ceSopenharmony_ci{ 41717fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 41817fd14ceSopenharmony_ci int32_t ret; 41917fd14ceSopenharmony_ci int32_t inOutLen; 42017fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 42117fd14ceSopenharmony_ci 42217fd14ceSopenharmony_ci LOGI("starting ..."); 42317fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(addParams)) { 42417fd14ceSopenharmony_ci LOGE("invalid params"); 42517fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 42617fd14ceSopenharmony_ci } 42717fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 42817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 42917fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 43017fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 43117fd14ceSopenharmony_ci } 43217fd14ceSopenharmony_ci ret = EncodeAddMemberParams(callCtx, osAccountId, requestId, appId, addParams); 43317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 43417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 43517fd14ceSopenharmony_ci return ret; 43617fd14ceSopenharmony_ci } 43717fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_GROUP_MEMBER, true); 43817fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 43917fd14ceSopenharmony_ci LOGE("ipc call failed"); 44017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 44117fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 44217fd14ceSopenharmony_ci } 44317fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 44417fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 44517fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 44617fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 44717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 44817fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 44917fd14ceSopenharmony_ci return ret; 45017fd14ceSopenharmony_ci} 45117fd14ceSopenharmony_ci 45217fd14ceSopenharmony_cistatic int32_t EncodeDeleteMemberParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, 45317fd14ceSopenharmony_ci const char *appId, const char *delParams) 45417fd14ceSopenharmony_ci{ 45517fd14ceSopenharmony_ci int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 45617fd14ceSopenharmony_ci sizeof(osAccountId)); 45717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 45817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 45917fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 46017fd14ceSopenharmony_ci } 46117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); 46217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 46317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID); 46417fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 46517fd14ceSopenharmony_ci } 46617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 46717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 46817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 46917fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 47017fd14ceSopenharmony_ci } 47117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, HcStrlen(delParams) + 1); 47217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 47317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS); 47417fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 47517fd14ceSopenharmony_ci } 47617fd14ceSopenharmony_ci return HC_SUCCESS; 47717fd14ceSopenharmony_ci} 47817fd14ceSopenharmony_ci 47917fd14ceSopenharmony_cistatic int32_t IpcGmDelMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams) 48017fd14ceSopenharmony_ci{ 48117fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 48217fd14ceSopenharmony_ci int32_t ret; 48317fd14ceSopenharmony_ci int32_t inOutLen; 48417fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 48517fd14ceSopenharmony_ci 48617fd14ceSopenharmony_ci LOGI("starting ..."); 48717fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(delParams)) { 48817fd14ceSopenharmony_ci LOGE("invalid params"); 48917fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 49017fd14ceSopenharmony_ci } 49117fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 49217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 49317fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 49417fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 49517fd14ceSopenharmony_ci } 49617fd14ceSopenharmony_ci ret = EncodeDeleteMemberParams(callCtx, osAccountId, requestId, appId, delParams); 49717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 49817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 49917fd14ceSopenharmony_ci return ret; 50017fd14ceSopenharmony_ci } 50117fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP_MEMBER, true); 50217fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 50317fd14ceSopenharmony_ci LOGE("ipc call failed"); 50417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 50517fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 50617fd14ceSopenharmony_ci } 50717fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 50817fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 50917fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 51017fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 51117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 51217fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 51317fd14ceSopenharmony_ci return ret; 51417fd14ceSopenharmony_ci} 51517fd14ceSopenharmony_ci 51617fd14ceSopenharmony_cistatic int32_t IpcGmAddMultiMembersToGroup(int32_t osAccountId, const char *appId, const char *addParams) 51717fd14ceSopenharmony_ci{ 51817fd14ceSopenharmony_ci LOGI("starting ..."); 51917fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(addParams)) { 52017fd14ceSopenharmony_ci LOGE("Invalid params"); 52117fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 52217fd14ceSopenharmony_ci } 52317fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 52417fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 52517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 52617fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 52717fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 52817fd14ceSopenharmony_ci } 52917fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 53017fd14ceSopenharmony_ci sizeof(osAccountId)); 53117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 53217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 53317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 53417fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 53517fd14ceSopenharmony_ci } 53617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 53717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 53817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 53917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 54017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 54117fd14ceSopenharmony_ci } 54217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, HcStrlen(addParams) + 1); 54317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 54417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_ADD_PARAMS); 54517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 54617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 54717fd14ceSopenharmony_ci } 54817fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS, true); 54917fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 55017fd14ceSopenharmony_ci LOGE("ipc call failed"); 55117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 55217fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 55317fd14ceSopenharmony_ci } 55417fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 55517fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 55617fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 55717fd14ceSopenharmony_ci int32_t inOutLen = sizeof(int32_t); 55817fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 55917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 56017fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 56117fd14ceSopenharmony_ci return ret; 56217fd14ceSopenharmony_ci} 56317fd14ceSopenharmony_ci 56417fd14ceSopenharmony_cistatic int32_t IpcGmDelMultiMembersFromGroup(int32_t osAccountId, const char *appId, const char *delParams) 56517fd14ceSopenharmony_ci{ 56617fd14ceSopenharmony_ci LOGI("starting ..."); 56717fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(delParams)) { 56817fd14ceSopenharmony_ci LOGE("Invalid params"); 56917fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 57017fd14ceSopenharmony_ci } 57117fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 57217fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 57317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 57417fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 57517fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 57617fd14ceSopenharmony_ci } 57717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 57817fd14ceSopenharmony_ci sizeof(osAccountId)); 57917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 58017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 58117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 58217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 58317fd14ceSopenharmony_ci } 58417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 58517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 58617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 58717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 58817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 58917fd14ceSopenharmony_ci } 59017fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, HcStrlen(delParams) + 1); 59117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 59217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS); 59317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 59417fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 59517fd14ceSopenharmony_ci } 59617fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS, true); 59717fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 59817fd14ceSopenharmony_ci LOGE("ipc call failed"); 59917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 60017fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 60117fd14ceSopenharmony_ci } 60217fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 60317fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 60417fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 60517fd14ceSopenharmony_ci int32_t inOutLen = sizeof(int32_t); 60617fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 60717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 60817fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 60917fd14ceSopenharmony_ci return ret; 61017fd14ceSopenharmony_ci} 61117fd14ceSopenharmony_ci 61217fd14ceSopenharmony_cistatic int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t dataLen) 61317fd14ceSopenharmony_ci{ 61417fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 61517fd14ceSopenharmony_ci int32_t ret; 61617fd14ceSopenharmony_ci int32_t inOutLen; 61717fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 61817fd14ceSopenharmony_ci 61917fd14ceSopenharmony_ci LOGI("starting ..."); 62017fd14ceSopenharmony_ci if (!IS_COMM_DATA_VALID(data, dataLen)) { 62117fd14ceSopenharmony_ci LOGE("invalid params"); 62217fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 62317fd14ceSopenharmony_ci } 62417fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 62517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 62617fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 62717fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 62817fd14ceSopenharmony_ci } 62917fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); 63017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 63117fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID); 63217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 63317fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 63417fd14ceSopenharmony_ci } 63517fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen); 63617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 63717fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA); 63817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 63917fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 64017fd14ceSopenharmony_ci } 64117fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GM_PROC_DATA, true); 64217fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 64317fd14ceSopenharmony_ci LOGE("ipc call failed"); 64417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 64517fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 64617fd14ceSopenharmony_ci } 64717fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 64817fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 64917fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 65017fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 65117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 65217fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 65317fd14ceSopenharmony_ci return ret; 65417fd14ceSopenharmony_ci} 65517fd14ceSopenharmony_ci 65617fd14ceSopenharmony_cistatic int32_t IpcGmGetRegisterInfo(const char *reqJsonStr, char **registerInfo) 65717fd14ceSopenharmony_ci{ 65817fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 65917fd14ceSopenharmony_ci int32_t inOutLen; 66017fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; 66117fd14ceSopenharmony_ci char *outInfo = NULL; 66217fd14ceSopenharmony_ci 66317fd14ceSopenharmony_ci if (IsStrInvalid(reqJsonStr) || (registerInfo == NULL)) { 66417fd14ceSopenharmony_ci LOGE("Invalid params."); 66517fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 66617fd14ceSopenharmony_ci } 66717fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 66817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 66917fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 67017fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 67117fd14ceSopenharmony_ci } 67217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQ_JSON, (const uint8_t *)reqJsonStr, HcStrlen(reqJsonStr) + 1); 67317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 67417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQ_JSON); 67517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 67617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 67717fd14ceSopenharmony_ci } 67817fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_APPLY_REG_INFO, true); 67917fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 68017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 68117fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 68217fd14ceSopenharmony_ci } 68317fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 68417fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 68517fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 68617fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 68717fd14ceSopenharmony_ci if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) { 68817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 68917fd14ceSopenharmony_ci return HC_ERR_IPC_BAD_PARAM; 69017fd14ceSopenharmony_ci } 69117fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 69217fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) { 69317fd14ceSopenharmony_ci LOGE("done, ret %d", HC_ERR_IPC_OUT_DATA_NUM); 69417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 69517fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 69617fd14ceSopenharmony_ci } 69717fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_REG_INFO, (uint8_t *)&outInfo, NULL); 69817fd14ceSopenharmony_ci if ((outInfo == NULL) || (HcStrlen(outInfo) == 0)) { 69917fd14ceSopenharmony_ci LOGE("done, ret %d", HC_ERR_IPC_OUT_DATA); 70017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 70117fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 70217fd14ceSopenharmony_ci } 70317fd14ceSopenharmony_ci *registerInfo = strdup(outInfo); 70417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 70517fd14ceSopenharmony_ci return (*registerInfo != NULL) ? HC_SUCCESS : HC_ERR_NULL_PTR; 70617fd14ceSopenharmony_ci} 70717fd14ceSopenharmony_ci 70817fd14ceSopenharmony_cistatic int32_t IpcGmCheckAccessToGroup(int32_t osAccountId, const char *appId, const char *groupId) 70917fd14ceSopenharmony_ci{ 71017fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 71117fd14ceSopenharmony_ci int32_t ret; 71217fd14ceSopenharmony_ci int32_t inOutLen; 71317fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 71417fd14ceSopenharmony_ci 71517fd14ceSopenharmony_ci LOGI("starting ..."); 71617fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(groupId)) { 71717fd14ceSopenharmony_ci LOGE("Invalid params."); 71817fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 71917fd14ceSopenharmony_ci } 72017fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 72117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 72217fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 72317fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 72417fd14ceSopenharmony_ci } 72517fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 72617fd14ceSopenharmony_ci sizeof(osAccountId)); 72717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 72817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 72917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 73017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 73117fd14ceSopenharmony_ci } 73217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 73317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 73417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 73517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 73617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 73717fd14ceSopenharmony_ci } 73817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); 73917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 74017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID); 74117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 74217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 74317fd14ceSopenharmony_ci } 74417fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP, true); 74517fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 74617fd14ceSopenharmony_ci LOGE("ipc call failed"); 74717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 74817fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 74917fd14ceSopenharmony_ci } 75017fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 75117fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 75217fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 75317fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 75417fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 75517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 75617fd14ceSopenharmony_ci return ret; 75717fd14ceSopenharmony_ci} 75817fd14ceSopenharmony_ci 75917fd14ceSopenharmony_cistatic int32_t ParseReturnResult(const IpcDataInfo *replies, int32_t cacheNum, char **returnData, uint32_t *returnNum) 76017fd14ceSopenharmony_ci{ 76117fd14ceSopenharmony_ci int32_t ret; 76217fd14ceSopenharmony_ci int32_t inOutLen; 76317fd14ceSopenharmony_ci 76417fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 76517fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 76617fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { 76717fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 76817fd14ceSopenharmony_ci } 76917fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)returnData, NULL); 77017fd14ceSopenharmony_ci if (*returnData == NULL) { 77117fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 77217fd14ceSopenharmony_ci } 77317fd14ceSopenharmony_ci *returnData = strdup(*returnData); 77417fd14ceSopenharmony_ci if (*returnData == NULL) { 77517fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 77617fd14ceSopenharmony_ci } 77717fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 77817fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)returnNum, &inOutLen); 77917fd14ceSopenharmony_ci return HC_SUCCESS; 78017fd14ceSopenharmony_ci} 78117fd14ceSopenharmony_ci 78217fd14ceSopenharmony_cistatic int32_t IpcGmGetPkInfoList(int32_t osAccountId, const char *appId, const char *queryParams, 78317fd14ceSopenharmony_ci char **returnInfoList, uint32_t *returnInfoNum) 78417fd14ceSopenharmony_ci{ 78517fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 78617fd14ceSopenharmony_ci int32_t ret; 78717fd14ceSopenharmony_ci int32_t inOutLen; 78817fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; 78917fd14ceSopenharmony_ci 79017fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(queryParams) || (returnInfoList == NULL) || (returnInfoNum == NULL)) { 79117fd14ceSopenharmony_ci LOGE("Invalid params."); 79217fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 79317fd14ceSopenharmony_ci } 79417fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 79517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 79617fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 79717fd14ceSopenharmony_ci } 79817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, 79917fd14ceSopenharmony_ci (const uint8_t *)&osAccountId, sizeof(osAccountId)); 80017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 80117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 80217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 80317fd14ceSopenharmony_ci } 80417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 80517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 80617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 80717fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 80817fd14ceSopenharmony_ci } 80917fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS, 81017fd14ceSopenharmony_ci (const uint8_t *)queryParams, HcStrlen(queryParams) + 1); 81117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 81217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 81317fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 81417fd14ceSopenharmony_ci } 81517fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PK_INFO_LIST, true); 81617fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 81717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 81817fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 81917fd14ceSopenharmony_ci } 82017fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 82117fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 82217fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 82317fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 82417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 82517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 82617fd14ceSopenharmony_ci return ret; 82717fd14ceSopenharmony_ci } 82817fd14ceSopenharmony_ci ret = ParseReturnResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnInfoList, returnInfoNum); 82917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 83017fd14ceSopenharmony_ci return ret; 83117fd14ceSopenharmony_ci} 83217fd14ceSopenharmony_ci 83317fd14ceSopenharmony_cistatic int32_t GroupInfoIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outGroupInfo) 83417fd14ceSopenharmony_ci{ 83517fd14ceSopenharmony_ci int32_t inOutLen; 83617fd14ceSopenharmony_ci int32_t ret; 83717fd14ceSopenharmony_ci 83817fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 83917fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 84017fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) { 84117fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 84217fd14ceSopenharmony_ci } 84317fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupInfo, NULL); 84417fd14ceSopenharmony_ci if (*outGroupInfo == NULL) { 84517fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 84617fd14ceSopenharmony_ci } 84717fd14ceSopenharmony_ci *outGroupInfo = strdup(*outGroupInfo); 84817fd14ceSopenharmony_ci if (*outGroupInfo == NULL) { 84917fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 85017fd14ceSopenharmony_ci } 85117fd14ceSopenharmony_ci return HC_SUCCESS; 85217fd14ceSopenharmony_ci} 85317fd14ceSopenharmony_ci 85417fd14ceSopenharmony_cistatic int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId, char **outGroupInfo) 85517fd14ceSopenharmony_ci{ 85617fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 85717fd14ceSopenharmony_ci int32_t inOutLen; 85817fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; 85917fd14ceSopenharmony_ci 86017fd14ceSopenharmony_ci if (IsStrInvalid(groupId) || IsStrInvalid(appId) || (outGroupInfo == NULL)) { 86117fd14ceSopenharmony_ci LOGE("Invalid params."); 86217fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 86317fd14ceSopenharmony_ci } 86417fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 86517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 86617fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 86717fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 86817fd14ceSopenharmony_ci } 86917fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 87017fd14ceSopenharmony_ci sizeof(osAccountId)); 87117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 87217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 87317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 87417fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 87517fd14ceSopenharmony_ci } 87617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 87717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 87817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 87917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 88017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 88117fd14ceSopenharmony_ci } 88217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); 88317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 88417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID); 88517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 88617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 88717fd14ceSopenharmony_ci } 88817fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_GROUP_INFO, true); 88917fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 89017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 89117fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 89217fd14ceSopenharmony_ci } 89317fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 89417fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 89517fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 89617fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 89717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 89817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 89917fd14ceSopenharmony_ci return ret; 90017fd14ceSopenharmony_ci } 90117fd14ceSopenharmony_ci ret = GroupInfoIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupInfo); 90217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 90317fd14ceSopenharmony_ci return ret; 90417fd14ceSopenharmony_ci} 90517fd14ceSopenharmony_ci 90617fd14ceSopenharmony_cistatic int32_t SearchGroupsIpcResult(const IpcDataInfo *replies, 90717fd14ceSopenharmony_ci int32_t cacheNum, char **outGroupVec, uint32_t *groupNum) 90817fd14ceSopenharmony_ci{ 90917fd14ceSopenharmony_ci int32_t ret; 91017fd14ceSopenharmony_ci int32_t inOutLen; 91117fd14ceSopenharmony_ci 91217fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 91317fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 91417fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { 91517fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 91617fd14ceSopenharmony_ci } 91717fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL); 91817fd14ceSopenharmony_ci if (*outGroupVec == NULL) { 91917fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 92017fd14ceSopenharmony_ci } 92117fd14ceSopenharmony_ci *outGroupVec = strdup(*outGroupVec); 92217fd14ceSopenharmony_ci if (*outGroupVec == NULL) { 92317fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 92417fd14ceSopenharmony_ci } 92517fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 92617fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen); 92717fd14ceSopenharmony_ci return HC_SUCCESS; 92817fd14ceSopenharmony_ci} 92917fd14ceSopenharmony_ci 93017fd14ceSopenharmony_cistatic int32_t IpcGmGetGroupInfo(int32_t osAccountId, const char *appId, const char *queryParams, 93117fd14ceSopenharmony_ci char **outGroupVec, uint32_t *groupNum) 93217fd14ceSopenharmony_ci{ 93317fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 93417fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; 93517fd14ceSopenharmony_ci 93617fd14ceSopenharmony_ci if (IsStrInvalid(queryParams) || IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL)) { 93717fd14ceSopenharmony_ci LOGE("Invalid params."); 93817fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 93917fd14ceSopenharmony_ci } 94017fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 94117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 94217fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 94317fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 94417fd14ceSopenharmony_ci } 94517fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 94617fd14ceSopenharmony_ci sizeof(osAccountId)); 94717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 94817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 94917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 95017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 95117fd14ceSopenharmony_ci } 95217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 95317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 95417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 95517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 95617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 95717fd14ceSopenharmony_ci } 95817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS, 95917fd14ceSopenharmony_ci (const uint8_t *)queryParams, HcStrlen(queryParams) + 1); 96017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 96117fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_QUERY_PARAMS); 96217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 96317fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 96417fd14ceSopenharmony_ci } 96517fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_SEARCH_GROUPS, true); 96617fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 96717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 96817fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 96917fd14ceSopenharmony_ci } 97017fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 97117fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 97217fd14ceSopenharmony_ci int32_t inOutLen = sizeof(int32_t); 97317fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 97417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 97517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 97617fd14ceSopenharmony_ci return ret; 97717fd14ceSopenharmony_ci } 97817fd14ceSopenharmony_ci ret = SearchGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum); 97917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 98017fd14ceSopenharmony_ci return ret; 98117fd14ceSopenharmony_ci} 98217fd14ceSopenharmony_ci 98317fd14ceSopenharmony_cistatic int32_t JoinedGroupsIpcResult(const IpcDataInfo *replies, 98417fd14ceSopenharmony_ci int32_t cacheNum, char **outGroupVec, uint32_t *groupNum) 98517fd14ceSopenharmony_ci{ 98617fd14ceSopenharmony_ci int32_t ret; 98717fd14ceSopenharmony_ci int32_t inOutLen; 98817fd14ceSopenharmony_ci 98917fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 99017fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 99117fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { 99217fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 99317fd14ceSopenharmony_ci } 99417fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL); 99517fd14ceSopenharmony_ci if (*outGroupVec == NULL) { 99617fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 99717fd14ceSopenharmony_ci } 99817fd14ceSopenharmony_ci *outGroupVec = strdup(*outGroupVec); 99917fd14ceSopenharmony_ci if (*outGroupVec == NULL) { 100017fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 100117fd14ceSopenharmony_ci } 100217fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 100317fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen); 100417fd14ceSopenharmony_ci return HC_SUCCESS; 100517fd14ceSopenharmony_ci} 100617fd14ceSopenharmony_ci 100717fd14ceSopenharmony_cistatic int32_t IpcGmGetJoinedGroups(int32_t osAccountId, const char *appId, int32_t groupType, 100817fd14ceSopenharmony_ci char **outGroupVec, uint32_t *groupNum) 100917fd14ceSopenharmony_ci{ 101017fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 101117fd14ceSopenharmony_ci int32_t inOutLen; 101217fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; 101317fd14ceSopenharmony_ci 101417fd14ceSopenharmony_ci if (IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL)) { 101517fd14ceSopenharmony_ci LOGE("Invalid params."); 101617fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 101717fd14ceSopenharmony_ci } 101817fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 101917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 102017fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 102117fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 102217fd14ceSopenharmony_ci } 102317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 102417fd14ceSopenharmony_ci sizeof(osAccountId)); 102517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 102617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 102717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 102817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 102917fd14ceSopenharmony_ci } 103017fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 103117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 103217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 103317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 103417fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 103517fd14ceSopenharmony_ci } 103617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUP_TYPE, (const uint8_t *)&groupType, sizeof(groupType)); 103717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 103817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUP_TYPE); 103917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 104017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 104117fd14ceSopenharmony_ci } 104217fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_JOINED_GROUPS, true); 104317fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 104417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 104517fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 104617fd14ceSopenharmony_ci } 104717fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 104817fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 104917fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 105017fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 105117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 105217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 105317fd14ceSopenharmony_ci return ret; 105417fd14ceSopenharmony_ci } 105517fd14ceSopenharmony_ci ret = JoinedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum); 105617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 105717fd14ceSopenharmony_ci return ret; 105817fd14ceSopenharmony_ci} 105917fd14ceSopenharmony_ci 106017fd14ceSopenharmony_cistatic int32_t RelatedGroupsIpcResult(const IpcDataInfo *replies, 106117fd14ceSopenharmony_ci int32_t cacheNum, char **outGroupVec, uint32_t *groupNum) 106217fd14ceSopenharmony_ci{ 106317fd14ceSopenharmony_ci int32_t ret; 106417fd14ceSopenharmony_ci int32_t inOutLen; 106517fd14ceSopenharmony_ci 106617fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 106717fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 106817fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { 106917fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 107017fd14ceSopenharmony_ci } 107117fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL); 107217fd14ceSopenharmony_ci if (*outGroupVec == NULL) { 107317fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 107417fd14ceSopenharmony_ci } 107517fd14ceSopenharmony_ci *outGroupVec = strdup(*outGroupVec); 107617fd14ceSopenharmony_ci if (*outGroupVec == NULL) { 107717fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 107817fd14ceSopenharmony_ci } 107917fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 108017fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen); 108117fd14ceSopenharmony_ci return HC_SUCCESS; 108217fd14ceSopenharmony_ci} 108317fd14ceSopenharmony_ci 108417fd14ceSopenharmony_cistatic int32_t IpcGmGetRelatedGroups(int32_t osAccountId, const char *appId, const char *peerUdid, 108517fd14ceSopenharmony_ci char **outGroupVec, uint32_t *groupNum) 108617fd14ceSopenharmony_ci{ 108717fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 108817fd14ceSopenharmony_ci int32_t ret; 108917fd14ceSopenharmony_ci int32_t inOutLen; 109017fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; 109117fd14ceSopenharmony_ci 109217fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(peerUdid) || (outGroupVec == NULL) || (groupNum == NULL)) { 109317fd14ceSopenharmony_ci LOGE("Invalid params."); 109417fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 109517fd14ceSopenharmony_ci } 109617fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 109717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 109817fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 109917fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 110017fd14ceSopenharmony_ci } 110117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, sizeof(int32_t)); 110217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 110317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 110417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 110517fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 110617fd14ceSopenharmony_ci } 110717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 110817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 110917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 111017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 111117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 111217fd14ceSopenharmony_ci } 111317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, HcStrlen(peerUdid) + 1); 111417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 111517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID); 111617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 111717fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 111817fd14ceSopenharmony_ci } 111917fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_RELATED_GROUPS, true); 112017fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 112117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 112217fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 112317fd14ceSopenharmony_ci } 112417fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 112517fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 112617fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 112717fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 112817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 112917fd14ceSopenharmony_ci LOGE("Service return exception, ret: %d", ret); 113017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 113117fd14ceSopenharmony_ci return ret; 113217fd14ceSopenharmony_ci } 113317fd14ceSopenharmony_ci ret = RelatedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum); 113417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 113517fd14ceSopenharmony_ci return ret; 113617fd14ceSopenharmony_ci} 113717fd14ceSopenharmony_ci 113817fd14ceSopenharmony_cistatic int32_t DevInfoByIdIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfo) 113917fd14ceSopenharmony_ci{ 114017fd14ceSopenharmony_ci int32_t ret; 114117fd14ceSopenharmony_ci int32_t inOutLen; 114217fd14ceSopenharmony_ci 114317fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 114417fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 114517fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) { 114617fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 114717fd14ceSopenharmony_ci } 114817fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfo, NULL); 114917fd14ceSopenharmony_ci if (*outDevInfo == NULL) { 115017fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 115117fd14ceSopenharmony_ci } 115217fd14ceSopenharmony_ci *outDevInfo = strdup(*outDevInfo); 115317fd14ceSopenharmony_ci if (*outDevInfo == NULL) { 115417fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 115517fd14ceSopenharmony_ci } 115617fd14ceSopenharmony_ci return HC_SUCCESS; 115717fd14ceSopenharmony_ci} 115817fd14ceSopenharmony_ci 115917fd14ceSopenharmony_cistatic int32_t FormParamsForGettingDeviceInfo(int32_t osAccountId, const char *appId, 116017fd14ceSopenharmony_ci const char *peerUdid, const char *groupId, uintptr_t callCtx) 116117fd14ceSopenharmony_ci{ 116217fd14ceSopenharmony_ci int32_t ret; 116317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 116417fd14ceSopenharmony_ci sizeof(osAccountId)); 116517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 116617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 116717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 116817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 116917fd14ceSopenharmony_ci } 117017fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 117117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 117217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 117317fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 117417fd14ceSopenharmony_ci } 117517fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, HcStrlen(peerUdid) + 1); 117617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 117717fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID); 117817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 117917fd14ceSopenharmony_ci } 118017fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); 118117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 118217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID); 118317fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 118417fd14ceSopenharmony_ci } 118517fd14ceSopenharmony_ci return HC_SUCCESS; 118617fd14ceSopenharmony_ci} 118717fd14ceSopenharmony_ci 118817fd14ceSopenharmony_cistatic int32_t IpcGmGetDeviceInfoById(int32_t osAccountId, const char *appId, const char *peerUdid, const char *groupId, 118917fd14ceSopenharmony_ci char **outDevInfo) 119017fd14ceSopenharmony_ci{ 119117fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 119217fd14ceSopenharmony_ci int32_t ret; 119317fd14ceSopenharmony_ci int32_t inOutLen; 119417fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; 119517fd14ceSopenharmony_ci 119617fd14ceSopenharmony_ci LOGI("starting ..."); 119717fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(peerUdid) || IsStrInvalid(groupId) || (outDevInfo == NULL)) { 119817fd14ceSopenharmony_ci LOGE("Invalid params."); 119917fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 120017fd14ceSopenharmony_ci } 120117fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 120217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 120317fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 120417fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 120517fd14ceSopenharmony_ci } 120617fd14ceSopenharmony_ci ret = FormParamsForGettingDeviceInfo(osAccountId, appId, peerUdid, groupId, callCtx); 120717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 120817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 120917fd14ceSopenharmony_ci return ret; 121017fd14ceSopenharmony_ci } 121117fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_DEV_INFO_BY_ID, true); 121217fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 121317fd14ceSopenharmony_ci LOGE("ipc call failed"); 121417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 121517fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 121617fd14ceSopenharmony_ci } 121717fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 121817fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 121917fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 122017fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 122117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 122217fd14ceSopenharmony_ci LOGE("Service return exception, ret: %d", ret); 122317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 122417fd14ceSopenharmony_ci return ret; 122517fd14ceSopenharmony_ci } 122617fd14ceSopenharmony_ci ret = DevInfoByIdIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfo); 122717fd14ceSopenharmony_ci LOGI("proc result done, ret %d", ret); 122817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 122917fd14ceSopenharmony_ci return ret; 123017fd14ceSopenharmony_ci} 123117fd14ceSopenharmony_ci 123217fd14ceSopenharmony_cistatic int32_t TrustedDevIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfoVec, uint32_t *devNum) 123317fd14ceSopenharmony_ci{ 123417fd14ceSopenharmony_ci int32_t ret; 123517fd14ceSopenharmony_ci int32_t inOutLen; 123617fd14ceSopenharmony_ci 123717fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 123817fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); 123917fd14ceSopenharmony_ci if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { 124017fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA_NUM; 124117fd14ceSopenharmony_ci } 124217fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfoVec, NULL); 124317fd14ceSopenharmony_ci if (*outDevInfoVec == NULL) { 124417fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 124517fd14ceSopenharmony_ci } 124617fd14ceSopenharmony_ci *outDevInfoVec = strdup(*outDevInfoVec); 124717fd14ceSopenharmony_ci if (*outDevInfoVec == NULL) { 124817fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 124917fd14ceSopenharmony_ci } 125017fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 125117fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)devNum, &inOutLen); 125217fd14ceSopenharmony_ci return HC_SUCCESS; 125317fd14ceSopenharmony_ci} 125417fd14ceSopenharmony_ci 125517fd14ceSopenharmony_cistatic int32_t IpcGmGetTrustedDevices(int32_t osAccountId, const char *appId, 125617fd14ceSopenharmony_ci const char *groupId, char **outDevInfoVec, uint32_t *deviceNum) 125717fd14ceSopenharmony_ci{ 125817fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 125917fd14ceSopenharmony_ci int32_t inOutLen; 126017fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; 126117fd14ceSopenharmony_ci 126217fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(groupId) || (outDevInfoVec == NULL) || (deviceNum == NULL)) { 126317fd14ceSopenharmony_ci LOGE("Invalid params."); 126417fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 126517fd14ceSopenharmony_ci } 126617fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 126717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 126817fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 126917fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 127017fd14ceSopenharmony_ci } 127117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 127217fd14ceSopenharmony_ci sizeof(osAccountId)); 127317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 127417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 127517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 127617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 127717fd14ceSopenharmony_ci } 127817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 127917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 128017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 128117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 128217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 128317fd14ceSopenharmony_ci } 128417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); 128517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 128617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID); 128717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 128817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 128917fd14ceSopenharmony_ci } 129017fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_TRUST_DEVICES, true); 129117fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 129217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 129317fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 129417fd14ceSopenharmony_ci } 129517fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 129617fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 129717fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 129817fd14ceSopenharmony_ci GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 129917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 130017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 130117fd14ceSopenharmony_ci return ret; 130217fd14ceSopenharmony_ci } 130317fd14ceSopenharmony_ci ret = TrustedDevIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfoVec, deviceNum); 130417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 130517fd14ceSopenharmony_ci return ret; 130617fd14ceSopenharmony_ci} 130717fd14ceSopenharmony_ci 130817fd14ceSopenharmony_cistatic bool IpcGmIsDeviceInGroup(int32_t osAccountId, const char *appId, const char *groupId, const char *udid) 130917fd14ceSopenharmony_ci{ 131017fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 131117fd14ceSopenharmony_ci int32_t inOutLen; 131217fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 131317fd14ceSopenharmony_ci 131417fd14ceSopenharmony_ci if (IsStrInvalid(appId) || IsStrInvalid(groupId) || IsStrInvalid(udid)) { 131517fd14ceSopenharmony_ci LOGE("Invalid params."); 131617fd14ceSopenharmony_ci return false; 131717fd14ceSopenharmony_ci } 131817fd14ceSopenharmony_ci int32_t ret = CreateCallCtx(&callCtx, NULL); 131917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 132017fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 132117fd14ceSopenharmony_ci return false; 132217fd14ceSopenharmony_ci } 132317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 132417fd14ceSopenharmony_ci sizeof(osAccountId)); 132517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 132617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 132717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 132817fd14ceSopenharmony_ci return false; 132917fd14ceSopenharmony_ci } 133017fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 133117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 133217fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 133317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 133417fd14ceSopenharmony_ci return false; 133517fd14ceSopenharmony_ci } 133617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); 133717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 133817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID); 133917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 134017fd14ceSopenharmony_ci return false; 134117fd14ceSopenharmony_ci } 134217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)udid, HcStrlen(udid) + 1); 134317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 134417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID); 134517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 134617fd14ceSopenharmony_ci return false; 134717fd14ceSopenharmony_ci } 134817fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_IS_DEV_IN_GROUP, true); 134917fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 135017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 135117fd14ceSopenharmony_ci return false; 135217fd14ceSopenharmony_ci } 135317fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 135417fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 135517fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 135617fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 135717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 135817fd14ceSopenharmony_ci return (ret == HC_SUCCESS) ? true : false; 135917fd14ceSopenharmony_ci} 136017fd14ceSopenharmony_ci 136117fd14ceSopenharmony_cistatic void IpcGmDestroyInfo(char **returnInfo) 136217fd14ceSopenharmony_ci{ 136317fd14ceSopenharmony_ci if ((returnInfo == NULL) || (*returnInfo == NULL)) { 136417fd14ceSopenharmony_ci return; 136517fd14ceSopenharmony_ci } 136617fd14ceSopenharmony_ci FreeJsonString(*returnInfo); 136717fd14ceSopenharmony_ci *returnInfo = NULL; 136817fd14ceSopenharmony_ci} 136917fd14ceSopenharmony_ci 137017fd14ceSopenharmony_cistatic void IpcGmCancelRequest(int64_t requestId, const char *appId) 137117fd14ceSopenharmony_ci{ 137217fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 137317fd14ceSopenharmony_ci int32_t ret; 137417fd14ceSopenharmony_ci 137517fd14ceSopenharmony_ci LOGI("starting ..."); 137617fd14ceSopenharmony_ci if (IsStrInvalid(appId)) { 137717fd14ceSopenharmony_ci LOGE("Invalid params."); 137817fd14ceSopenharmony_ci return; 137917fd14ceSopenharmony_ci } 138017fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 138117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 138217fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 138317fd14ceSopenharmony_ci return; 138417fd14ceSopenharmony_ci } 138517fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); 138617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 138717fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 138817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 138917fd14ceSopenharmony_ci return; 139017fd14ceSopenharmony_ci } 139117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 139217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 139317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 139417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 139517fd14ceSopenharmony_ci return; 139617fd14ceSopenharmony_ci } 139717fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_GM_CANCEL_REQUEST, true); 139817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 139917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 140017fd14ceSopenharmony_ci LOGE("ipc call failed"); 140117fd14ceSopenharmony_ci } else { 140217fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 140317fd14ceSopenharmony_ci } 140417fd14ceSopenharmony_ci} 140517fd14ceSopenharmony_ci 140617fd14ceSopenharmony_cistatic void InitIpcGmMethods(DeviceGroupManager *gmMethodObj) 140717fd14ceSopenharmony_ci{ 140817fd14ceSopenharmony_ci gmMethodObj->regCallback = IpcGmRegCallback; 140917fd14ceSopenharmony_ci gmMethodObj->unRegCallback = IpcGmUnRegCallback; 141017fd14ceSopenharmony_ci gmMethodObj->regDataChangeListener = IpcGmRegDataChangeListener; 141117fd14ceSopenharmony_ci gmMethodObj->unRegDataChangeListener = IpcGmUnRegDataChangeListener; 141217fd14ceSopenharmony_ci gmMethodObj->createGroup = IpcGmCreateGroup; 141317fd14ceSopenharmony_ci gmMethodObj->deleteGroup = IpcGmDeleteGroup; 141417fd14ceSopenharmony_ci gmMethodObj->addMemberToGroup = IpcGmAddMemberToGroup; 141517fd14ceSopenharmony_ci gmMethodObj->deleteMemberFromGroup = IpcGmDelMemberFromGroup; 141617fd14ceSopenharmony_ci gmMethodObj->addMultiMembersToGroup = IpcGmAddMultiMembersToGroup; 141717fd14ceSopenharmony_ci gmMethodObj->delMultiMembersFromGroup = IpcGmDelMultiMembersFromGroup; 141817fd14ceSopenharmony_ci gmMethodObj->processData = IpcGmProcessData; 141917fd14ceSopenharmony_ci gmMethodObj->getRegisterInfo = IpcGmGetRegisterInfo; 142017fd14ceSopenharmony_ci gmMethodObj->checkAccessToGroup = IpcGmCheckAccessToGroup; 142117fd14ceSopenharmony_ci gmMethodObj->getPkInfoList = IpcGmGetPkInfoList; 142217fd14ceSopenharmony_ci gmMethodObj->getGroupInfoById = IpcGmGetGroupInfoById; 142317fd14ceSopenharmony_ci gmMethodObj->getGroupInfo = IpcGmGetGroupInfo; 142417fd14ceSopenharmony_ci gmMethodObj->getJoinedGroups = IpcGmGetJoinedGroups; 142517fd14ceSopenharmony_ci gmMethodObj->getRelatedGroups = IpcGmGetRelatedGroups; 142617fd14ceSopenharmony_ci gmMethodObj->getDeviceInfoById = IpcGmGetDeviceInfoById; 142717fd14ceSopenharmony_ci gmMethodObj->getTrustedDevices = IpcGmGetTrustedDevices; 142817fd14ceSopenharmony_ci gmMethodObj->isDeviceInGroup = IpcGmIsDeviceInGroup; 142917fd14ceSopenharmony_ci gmMethodObj->cancelRequest = IpcGmCancelRequest; 143017fd14ceSopenharmony_ci gmMethodObj->destroyInfo = IpcGmDestroyInfo; 143117fd14ceSopenharmony_ci return; 143217fd14ceSopenharmony_ci} 143317fd14ceSopenharmony_ci 143417fd14ceSopenharmony_cistatic int32_t EncodeProcessDataParams(uintptr_t callCtx, int64_t authReqId, 143517fd14ceSopenharmony_ci const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback) 143617fd14ceSopenharmony_ci{ 143717fd14ceSopenharmony_ci int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId)); 143817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 143917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 144017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 144117fd14ceSopenharmony_ci } 144217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, (const uint8_t *)data, dataLen); 144317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 144417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_COMM_DATA); 144517fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 144617fd14ceSopenharmony_ci } 144717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); 144817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 144917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB); 145017fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 145117fd14ceSopenharmony_ci } 145217fd14ceSopenharmony_ci SetCbCtxToDataCtx(callCtx, 0x0); 145317fd14ceSopenharmony_ci return HC_SUCCESS; 145417fd14ceSopenharmony_ci} 145517fd14ceSopenharmony_ci 145617fd14ceSopenharmony_cistatic int32_t IpcGaProcessData(int64_t authReqId, 145717fd14ceSopenharmony_ci const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback) 145817fd14ceSopenharmony_ci{ 145917fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 146017fd14ceSopenharmony_ci int32_t ret; 146117fd14ceSopenharmony_ci int32_t inOutLen; 146217fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 146317fd14ceSopenharmony_ci 146417fd14ceSopenharmony_ci LOGI("starting ..."); 146517fd14ceSopenharmony_ci if (!IS_COMM_DATA_VALID(data, dataLen) || (callback == NULL)) { 146617fd14ceSopenharmony_ci LOGE("invalid params"); 146717fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 146817fd14ceSopenharmony_ci } 146917fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 147017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 147117fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 147217fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 147317fd14ceSopenharmony_ci } 147417fd14ceSopenharmony_ci ret = EncodeProcessDataParams(callCtx, authReqId, data, dataLen, callback); 147517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 147617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 147717fd14ceSopenharmony_ci return ret; 147817fd14ceSopenharmony_ci } 147917fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GA_PROC_DATA, true); 148017fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 148117fd14ceSopenharmony_ci LOGE("ipc call failed"); 148217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 148317fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 148417fd14ceSopenharmony_ci } 148517fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 148617fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 148717fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 148817fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 148917fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 149017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 149117fd14ceSopenharmony_ci return ret; 149217fd14ceSopenharmony_ci} 149317fd14ceSopenharmony_ci 149417fd14ceSopenharmony_cistatic int32_t EncodeAuthDeviceParams(uintptr_t callCtx, int32_t osAccountId, int64_t authReqId, 149517fd14ceSopenharmony_ci const char *authParams, const DeviceAuthCallback *callback) 149617fd14ceSopenharmony_ci{ 149717fd14ceSopenharmony_ci int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 149817fd14ceSopenharmony_ci sizeof(osAccountId)); 149917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 150017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 150117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 150217fd14ceSopenharmony_ci } 150317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId)); 150417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 150517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 150617fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 150717fd14ceSopenharmony_ci } 150817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, 150917fd14ceSopenharmony_ci HcStrlen(authParams) + 1); 151017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 151117fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_AUTH_PARAMS); 151217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 151317fd14ceSopenharmony_ci } 151417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); 151517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 151617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB); 151717fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 151817fd14ceSopenharmony_ci } 151917fd14ceSopenharmony_ci SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_AUTH_ID); 152017fd14ceSopenharmony_ci return HC_SUCCESS; 152117fd14ceSopenharmony_ci} 152217fd14ceSopenharmony_ci 152317fd14ceSopenharmony_cistatic int32_t IpcGaAuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams, 152417fd14ceSopenharmony_ci const DeviceAuthCallback *callback) 152517fd14ceSopenharmony_ci{ 152617fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 152717fd14ceSopenharmony_ci int32_t ret; 152817fd14ceSopenharmony_ci int32_t inOutLen; 152917fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 153017fd14ceSopenharmony_ci 153117fd14ceSopenharmony_ci LOGI("starting ..."); 153217fd14ceSopenharmony_ci if (IsStrInvalid(authParams) || (callback == NULL)) { 153317fd14ceSopenharmony_ci LOGE("invalid params"); 153417fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 153517fd14ceSopenharmony_ci } 153617fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 153717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 153817fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 153917fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 154017fd14ceSopenharmony_ci } 154117fd14ceSopenharmony_ci ret = EncodeAuthDeviceParams(callCtx, osAccountId, authReqId, authParams, callback); 154217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 154317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 154417fd14ceSopenharmony_ci return ret; 154517fd14ceSopenharmony_ci } 154617fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_AUTH_DEVICE, true); 154717fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 154817fd14ceSopenharmony_ci LOGE("ipc call failed"); 154917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 155017fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 155117fd14ceSopenharmony_ci } 155217fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 155317fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 155417fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 155517fd14ceSopenharmony_ci GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 155617fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 155717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 155817fd14ceSopenharmony_ci return ret; 155917fd14ceSopenharmony_ci} 156017fd14ceSopenharmony_ci 156117fd14ceSopenharmony_cistatic void IpcGaCancelRequest(int64_t requestId, const char *appId) 156217fd14ceSopenharmony_ci{ 156317fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 156417fd14ceSopenharmony_ci int32_t ret; 156517fd14ceSopenharmony_ci 156617fd14ceSopenharmony_ci LOGI("starting ..."); 156717fd14ceSopenharmony_ci if (IsStrInvalid(appId)) { 156817fd14ceSopenharmony_ci LOGE("Invalid params."); 156917fd14ceSopenharmony_ci return; 157017fd14ceSopenharmony_ci } 157117fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 157217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 157317fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 157417fd14ceSopenharmony_ci return; 157517fd14ceSopenharmony_ci } 157617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); 157717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 157817fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 157917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 158017fd14ceSopenharmony_ci return; 158117fd14ceSopenharmony_ci } 158217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); 158317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 158417fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID); 158517fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 158617fd14ceSopenharmony_ci return; 158717fd14ceSopenharmony_ci } 158817fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_GA_CANCEL_REQUEST, true); 158917fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 159017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 159117fd14ceSopenharmony_ci LOGE("ipc call failed"); 159217fd14ceSopenharmony_ci } else { 159317fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 159417fd14ceSopenharmony_ci } 159517fd14ceSopenharmony_ci} 159617fd14ceSopenharmony_ci 159717fd14ceSopenharmony_cistatic int32_t GetIpcReplyByTypeInner(const IpcDataInfo *replies, int32_t cacheNum, char **outInfo) 159817fd14ceSopenharmony_ci{ 159917fd14ceSopenharmony_ci GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)outInfo, NULL); 160017fd14ceSopenharmony_ci if (*outInfo == NULL) { 160117fd14ceSopenharmony_ci return HC_ERR_IPC_OUT_DATA; 160217fd14ceSopenharmony_ci } 160317fd14ceSopenharmony_ci *outInfo = strdup(*outInfo); 160417fd14ceSopenharmony_ci if (*outInfo == NULL) { 160517fd14ceSopenharmony_ci return HC_ERR_ALLOC_MEMORY; 160617fd14ceSopenharmony_ci } 160717fd14ceSopenharmony_ci return HC_SUCCESS; 160817fd14ceSopenharmony_ci} 160917fd14ceSopenharmony_ci 161017fd14ceSopenharmony_cistatic int32_t IpcGaGetRealInfo(int32_t osAccountId, const char *pseudonymId, char **realInfo) 161117fd14ceSopenharmony_ci{ 161217fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 161317fd14ceSopenharmony_ci int32_t ret; 161417fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; 161517fd14ceSopenharmony_ci 161617fd14ceSopenharmony_ci LOGI("starting ..."); 161717fd14ceSopenharmony_ci if (IsStrInvalid(pseudonymId) || (realInfo == NULL)) { 161817fd14ceSopenharmony_ci LOGE("Invalid params."); 161917fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 162017fd14ceSopenharmony_ci } 162117fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 162217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 162317fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 162417fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 162517fd14ceSopenharmony_ci } 162617fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 162717fd14ceSopenharmony_ci sizeof(osAccountId)); 162817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 162917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 163017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 163117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 163217fd14ceSopenharmony_ci } 163317fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_PSEUDONYM_ID, (const uint8_t *)pseudonymId, 163417fd14ceSopenharmony_ci HcStrlen(pseudonymId) + 1); 163517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 163617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_PSEUDONYM_ID); 163717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 163817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 163917fd14ceSopenharmony_ci } 164017fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_REAL_INFO, true); 164117fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 164217fd14ceSopenharmony_ci LOGE("ipc call failed"); 164317fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 164417fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 164517fd14ceSopenharmony_ci } 164617fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 164717fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 164817fd14ceSopenharmony_ci ret = GetIpcReplyByTypeInner(replyCache, REPLAY_CACHE_NUM(replyCache), realInfo); 164917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 165017fd14ceSopenharmony_ci LOGE("GetIpcReplyByType failed, ret %d", ret); 165117fd14ceSopenharmony_ci } 165217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 165317fd14ceSopenharmony_ci return ret; 165417fd14ceSopenharmony_ci} 165517fd14ceSopenharmony_ci 165617fd14ceSopenharmony_cistatic int32_t IpcGaGetPseudonymId(int32_t osAccountId, const char *indexKey, char **pseudonymId) 165717fd14ceSopenharmony_ci{ 165817fd14ceSopenharmony_ci uintptr_t callCtx = 0x0; 165917fd14ceSopenharmony_ci int32_t ret; 166017fd14ceSopenharmony_ci IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; 166117fd14ceSopenharmony_ci 166217fd14ceSopenharmony_ci LOGI("starting ..."); 166317fd14ceSopenharmony_ci if (IsStrInvalid(indexKey) || (pseudonymId == NULL)) { 166417fd14ceSopenharmony_ci LOGE("Invalid params."); 166517fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 166617fd14ceSopenharmony_ci } 166717fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 166817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 166917fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 167017fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 167117fd14ceSopenharmony_ci } 167217fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, 167317fd14ceSopenharmony_ci sizeof(osAccountId)); 167417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 167517fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID); 167617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 167717fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 167817fd14ceSopenharmony_ci } 167917fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_INDEX_KEY, (const uint8_t *)indexKey, HcStrlen(indexKey) + 1); 168017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 168117fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_INDEX_KEY); 168217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 168317fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 168417fd14ceSopenharmony_ci } 168517fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PSEUDONYM_ID, true); 168617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 168717fd14ceSopenharmony_ci LOGE("ipc call failed"); 168817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 168917fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 169017fd14ceSopenharmony_ci } 169117fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 169217fd14ceSopenharmony_ci DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); 169317fd14ceSopenharmony_ci ret = GetIpcReplyByTypeInner(replyCache, REPLAY_CACHE_NUM(replyCache), pseudonymId); 169417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 169517fd14ceSopenharmony_ci LOGE("GetIpcReplyByType failed, ret %d", ret); 169617fd14ceSopenharmony_ci } 169717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 169817fd14ceSopenharmony_ci return ret; 169917fd14ceSopenharmony_ci} 170017fd14ceSopenharmony_ci 170117fd14ceSopenharmony_cistatic void InitIpcGaMethods(GroupAuthManager *gaMethodObj) 170217fd14ceSopenharmony_ci{ 170317fd14ceSopenharmony_ci gaMethodObj->processData = IpcGaProcessData; 170417fd14ceSopenharmony_ci gaMethodObj->authDevice = IpcGaAuthDevice; 170517fd14ceSopenharmony_ci gaMethodObj->cancelRequest = IpcGaCancelRequest; 170617fd14ceSopenharmony_ci gaMethodObj->getRealInfo = IpcGaGetRealInfo; 170717fd14ceSopenharmony_ci gaMethodObj->getPseudonymId = IpcGaGetPseudonymId; 170817fd14ceSopenharmony_ci return; 170917fd14ceSopenharmony_ci} 171017fd14ceSopenharmony_ci 171117fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC int32_t ProcessCredential(int32_t operationCode, const char *reqJsonStr, char **returnData) 171217fd14ceSopenharmony_ci{ 171317fd14ceSopenharmony_ci uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; 171417fd14ceSopenharmony_ci int32_t ret; 171517fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 171617fd14ceSopenharmony_ci 171717fd14ceSopenharmony_ci LOGI("starting ..."); 171817fd14ceSopenharmony_ci if (IsStrInvalid(reqJsonStr) || (returnData == NULL)) { 171917fd14ceSopenharmony_ci LOGE("Invalid params."); 172017fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 172117fd14ceSopenharmony_ci } 172217fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 172317fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 172417fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 172517fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 172617fd14ceSopenharmony_ci } 172717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo( 172817fd14ceSopenharmony_ci callCtx, PARAM_TYPE_OPCODE, (const uint8_t *)&operationCode, sizeof(operationCode)); 172917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 173017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OPCODE); 173117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 173217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 173317fd14ceSopenharmony_ci } 173417fd14ceSopenharmony_ci ret = 173517fd14ceSopenharmony_ci SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQ_JSON, (const uint8_t *)reqJsonStr, HcStrlen(reqJsonStr) + 1); 173617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 173717fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQ_JSON); 173817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 173917fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 174017fd14ceSopenharmony_ci } 174117fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_PROCESS_CREDENTIAL, true); 174217fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 174317fd14ceSopenharmony_ci LOGE("ipc call failed"); 174417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 174517fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 174617fd14ceSopenharmony_ci } 174717fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 174817fd14ceSopenharmony_ci ret = GetIpcReplyByTypeInner(&replyCache, REPLAY_CACHE_NUM(replyCache), returnData); 174917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 175017fd14ceSopenharmony_ci LOGE("GetIpcReplyByType failed, ret %d", ret); 175117fd14ceSopenharmony_ci } 175217fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 175317fd14ceSopenharmony_ci return ret; 175417fd14ceSopenharmony_ci} 175517fd14ceSopenharmony_ci 175617fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC int32_t ProcessAuthDevice( 175717fd14ceSopenharmony_ci int64_t requestId, const char *authParams, const DeviceAuthCallback *callback) 175817fd14ceSopenharmony_ci{ 175917fd14ceSopenharmony_ci uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; 176017fd14ceSopenharmony_ci int32_t ret; 176117fd14ceSopenharmony_ci int32_t inOutLen; 176217fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 176317fd14ceSopenharmony_ci 176417fd14ceSopenharmony_ci LOGI("starting ..."); 176517fd14ceSopenharmony_ci if (IsStrInvalid(authParams) || (callback == NULL)) { 176617fd14ceSopenharmony_ci LOGE("invalid params"); 176717fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 176817fd14ceSopenharmony_ci } 176917fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 177017fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 177117fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 177217fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 177317fd14ceSopenharmony_ci } 177417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); 177517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 177617fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 177717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 177817fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 177917fd14ceSopenharmony_ci } 178017fd14ceSopenharmony_ci ret = SetCallRequestParamInfo( 178117fd14ceSopenharmony_ci callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, HcStrlen(authParams) + 1); 178217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 178317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_AUTH_PARAMS); 178417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 178517fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 178617fd14ceSopenharmony_ci } 178717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); 178817fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 178917fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB); 179017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 179117fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 179217fd14ceSopenharmony_ci } 179317fd14ceSopenharmony_ci SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_DIRECT_AUTH_ID); 179417fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_DA_PROC_DATA, true); 179517fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 179617fd14ceSopenharmony_ci LOGE("ipc call failed"); 179717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 179817fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 179917fd14ceSopenharmony_ci } 180017fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 180117fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 180217fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 180317fd14ceSopenharmony_ci GetIpcReplyByType( 180417fd14ceSopenharmony_ci &replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 180517fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 180617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 180717fd14ceSopenharmony_ci return ret; 180817fd14ceSopenharmony_ci} 180917fd14ceSopenharmony_ci 181017fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC int32_t StartAuthDevice( 181117fd14ceSopenharmony_ci int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback) 181217fd14ceSopenharmony_ci{ 181317fd14ceSopenharmony_ci uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; 181417fd14ceSopenharmony_ci int32_t ret; 181517fd14ceSopenharmony_ci int32_t inOutLen; 181617fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 181717fd14ceSopenharmony_ci 181817fd14ceSopenharmony_ci LOGI("starting ..."); 181917fd14ceSopenharmony_ci if (IsStrInvalid(authParams) || (callback == NULL)) { 182017fd14ceSopenharmony_ci LOGE("invalid params"); 182117fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 182217fd14ceSopenharmony_ci } 182317fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 182417fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 182517fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 182617fd14ceSopenharmony_ci return HC_ERR_IPC_INIT; 182717fd14ceSopenharmony_ci } 182817fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId)); 182917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 183017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 183117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 183217fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 183317fd14ceSopenharmony_ci } 183417fd14ceSopenharmony_ci ret = SetCallRequestParamInfo( 183517fd14ceSopenharmony_ci callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, HcStrlen(authParams) + 1); 183617fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 183717fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_AUTH_PARAMS); 183817fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 183917fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 184017fd14ceSopenharmony_ci } 184117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); 184217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 184317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB); 184417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 184517fd14ceSopenharmony_ci return HC_ERR_IPC_BUILD_PARAM; 184617fd14ceSopenharmony_ci } 184717fd14ceSopenharmony_ci SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_DIRECT_AUTH_ID); 184817fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_DA_AUTH_DEVICE, true); 184917fd14ceSopenharmony_ci if (ret == HC_ERR_IPC_INTERNAL_FAILED) { 185017fd14ceSopenharmony_ci LOGE("ipc call failed"); 185117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 185217fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 185317fd14ceSopenharmony_ci } 185417fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 185517fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 185617fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 185717fd14ceSopenharmony_ci GetIpcReplyByType( 185817fd14ceSopenharmony_ci &replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 185917fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 186017fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 186117fd14ceSopenharmony_ci return ret; 186217fd14ceSopenharmony_ci} 186317fd14ceSopenharmony_ci 186417fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC int32_t CancelAuthRequest(int64_t requestId, const char *authParams) 186517fd14ceSopenharmony_ci{ 186617fd14ceSopenharmony_ci uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; 186717fd14ceSopenharmony_ci int32_t ret; 186817fd14ceSopenharmony_ci int32_t inOutLen; 186917fd14ceSopenharmony_ci IpcDataInfo replyCache = { 0 }; 187017fd14ceSopenharmony_ci 187117fd14ceSopenharmony_ci LOGI("starting ..."); 187217fd14ceSopenharmony_ci if (IsStrInvalid(authParams)) { 187317fd14ceSopenharmony_ci LOGE("Invalid params."); 187417fd14ceSopenharmony_ci return HC_ERR_INVALID_PARAMS; 187517fd14ceSopenharmony_ci } 187617fd14ceSopenharmony_ci ret = CreateCallCtx(&callCtx, NULL); 187717fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 187817fd14ceSopenharmony_ci LOGE("CreateCallCtx failed, ret %d", ret); 187917fd14ceSopenharmony_ci return HC_ERR_NULL_PTR; 188017fd14ceSopenharmony_ci } 188117fd14ceSopenharmony_ci ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); 188217fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 188317fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID); 188417fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 188517fd14ceSopenharmony_ci return HC_ERR_NULL_PTR; 188617fd14ceSopenharmony_ci } 188717fd14ceSopenharmony_ci ret = SetCallRequestParamInfo( 188817fd14ceSopenharmony_ci callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, HcStrlen(authParams) + 1); 188917fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 189017fd14ceSopenharmony_ci LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_AUTH_PARAMS); 189117fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 189217fd14ceSopenharmony_ci return HC_ERR_NULL_PTR; 189317fd14ceSopenharmony_ci } 189417fd14ceSopenharmony_ci ret = DoBinderCall(callCtx, IPC_CALL_ID_DA_CANCEL_REQUEST, true); 189517fd14ceSopenharmony_ci if (ret != HC_SUCCESS) { 189617fd14ceSopenharmony_ci LOGE("ipc call failed"); 189717fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 189817fd14ceSopenharmony_ci return HC_ERR_IPC_PROC_FAILED; 189917fd14ceSopenharmony_ci } 190017fd14ceSopenharmony_ci DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); 190117fd14ceSopenharmony_ci ret = HC_ERR_IPC_UNKNOW_REPLY; 190217fd14ceSopenharmony_ci inOutLen = sizeof(int32_t); 190317fd14ceSopenharmony_ci GetIpcReplyByType( 190417fd14ceSopenharmony_ci &replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); 190517fd14ceSopenharmony_ci LOGI("process done, ret %d", ret); 190617fd14ceSopenharmony_ci DestroyCallCtx(&callCtx, NULL); 190717fd14ceSopenharmony_ci return ret; 190817fd14ceSopenharmony_ci} 190917fd14ceSopenharmony_ci 191017fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) 191117fd14ceSopenharmony_ci{ 191217fd14ceSopenharmony_ci InitHcMutex(&g_ipcMutex); 191317fd14ceSopenharmony_ci return InitProxyAdapt(); 191417fd14ceSopenharmony_ci} 191517fd14ceSopenharmony_ci 191617fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void) 191717fd14ceSopenharmony_ci{ 191817fd14ceSopenharmony_ci UnInitProxyAdapt(); 191917fd14ceSopenharmony_ci DestroyHcMutex(&g_ipcMutex); 192017fd14ceSopenharmony_ci} 192117fd14ceSopenharmony_ci 192217fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void) 192317fd14ceSopenharmony_ci{ 192417fd14ceSopenharmony_ci static GroupAuthManager gaInstCtx; 192517fd14ceSopenharmony_ci static GroupAuthManager *gaInstPtr = NULL; 192617fd14ceSopenharmony_ci 192717fd14ceSopenharmony_ci if (gaInstPtr == NULL) { 192817fd14ceSopenharmony_ci InitIpcGaMethods(&gaInstCtx); 192917fd14ceSopenharmony_ci gaInstPtr = &gaInstCtx; 193017fd14ceSopenharmony_ci } 193117fd14ceSopenharmony_ci return (const GroupAuthManager *)(gaInstPtr); 193217fd14ceSopenharmony_ci} 193317fd14ceSopenharmony_ci 193417fd14ceSopenharmony_ciDEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void) 193517fd14ceSopenharmony_ci{ 193617fd14ceSopenharmony_ci static DeviceGroupManager gmInstCtx; 193717fd14ceSopenharmony_ci static DeviceGroupManager *gmInstPtr = NULL; 193817fd14ceSopenharmony_ci 193917fd14ceSopenharmony_ci if (gmInstPtr == NULL) { 194017fd14ceSopenharmony_ci InitIpcGmMethods(&gmInstCtx); 194117fd14ceSopenharmony_ci gmInstPtr = &gmInstCtx; 194217fd14ceSopenharmony_ci } 194317fd14ceSopenharmony_ci return (const DeviceGroupManager *)(gmInstPtr); 194417fd14ceSopenharmony_ci} 194517fd14ceSopenharmony_ci 194617fd14ceSopenharmony_ci#ifdef __cplusplus 194717fd14ceSopenharmony_ci} 194817fd14ceSopenharmony_ci#endif 1949