From 92de07ff639a9324daeb856110a92f0e9a8f981d Mon Sep 17 00:00:00 2001 From: fuzikun Date: Fri, 28 Mar 2025 16:45:15 +0800 Subject: [PATCH] optimize IPC code Signed-off-by: fuzikun --- frameworks/inc/lite/ipc_adapt.h | 4 +- frameworks/inc/standard/ipc_adapt.h | 4 +- frameworks/src/identity_service_ipc_sdk.c | 146 +- frameworks/src/ipc_sdk.c | 2102 +++++------------ frameworks/src/ipc_service_common.c | 49 +- frameworks/src/lite/ipc_adapt.c | 13 +- frameworks/src/standard/ipc_adapt.cpp | 11 +- services/frameworks/inc/common_defs.h | 1 - .../pake_v1_client_protocol_task.c | 2 +- 9 files changed, 699 insertions(+), 1633 deletions(-) diff --git a/frameworks/inc/lite/ipc_adapt.h b/frameworks/inc/lite/ipc_adapt.h index 7672730f..4e420385 100755 --- a/frameworks/inc/lite/ipc_adapt.h +++ b/frameworks/inc/lite/ipc_adapt.h @@ -64,8 +64,8 @@ int32_t IpcEncodeCallReply(uintptr_t replayCache, int32_t type, const uint8_t *r uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId); void SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx); -int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); -void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); +int32_t CreateCallCtx(uintptr_t *callCtx); +void DestroyCallCtx(uintptr_t *callCtx); int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync); int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz); diff --git a/frameworks/inc/standard/ipc_adapt.h b/frameworks/inc/standard/ipc_adapt.h index e6aca4ae..ac546bb2 100755 --- a/frameworks/inc/standard/ipc_adapt.h +++ b/frameworks/inc/standard/ipc_adapt.h @@ -61,8 +61,8 @@ int32_t IpcEncodeCallReply(uintptr_t replayCache, int32_t type, const uint8_t *r uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId); void SetCbCtxToDataCtx(uintptr_t callCtx, int32_t cbIdx); -int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); -void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx); +int32_t CreateCallCtx(uintptr_t *callCtx); +void DestroyCallCtx(uintptr_t *callCtx); int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync); int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t *param, int32_t paramSz); diff --git a/frameworks/src/identity_service_ipc_sdk.c b/frameworks/src/identity_service_ipc_sdk.c index 0c721137..eef704e0 100644 --- a/frameworks/src/identity_service_ipc_sdk.c +++ b/frameworks/src/identity_service_ipc_sdk.c @@ -192,20 +192,20 @@ static int32_t IpcCmAddCredential(int32_t osAccountId, const char *requestParams LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeAddCredentialParams(callCtx, osAccountId, requestParams); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_ADD_CREDENTIAL, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -213,12 +213,12 @@ static int32_t IpcCmAddCredential(int32_t osAccountId, const char *requestParams int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = AddCredentialIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnData); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -232,7 +232,7 @@ static int32_t IpcCmRegChangeListener(const char *appId, CredChangeListener *lis LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; @@ -241,14 +241,14 @@ static int32_t IpcCmRegChangeListener(const char *appId, CredChangeListener *lis HcStrlen(appId) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_LISTERNER, (const uint8_t *)listener, sizeof(*listener)); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_LISTERNER); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } // why do this ? @@ -257,8 +257,8 @@ static int32_t IpcCmRegChangeListener(const char *appId, CredChangeListener *lis if (ret == HC_SUCCESS) { AddIpcCliCallbackCtx(appId, 0, &g_ipcCredListenerCbList); } - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED; } @@ -272,7 +272,7 @@ static int32_t IpcCmUnRegChangeListener(const char *appId) LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; @@ -281,15 +281,15 @@ static int32_t IpcCmUnRegChangeListener(const char *appId) HcStrlen(appId) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_UNREG_LISTENER, true); if (ret == HC_SUCCESS) { DelIpcCliCallbackCtx(appId, &g_ipcCredListenerCbList); } - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return HC_SUCCESS; } @@ -342,20 +342,20 @@ static int32_t IpcCmExportCredential(int32_t osAccountId, const char *credId, ch LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeExportCredentialParams(callCtx, osAccountId, credId); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_EXPORT_CREDENTIAL, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -363,12 +363,12 @@ static int32_t IpcCmExportCredential(int32_t osAccountId, const char *credId, ch int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = ExportCredentialIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnData); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -403,7 +403,7 @@ static int32_t IpcCmQueryCredByParams(int32_t osAccountId, const char *requestPa LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - int32_t ret = CreateCallCtx(&callCtx, NULL); + int32_t ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; @@ -412,21 +412,21 @@ static int32_t IpcCmQueryCredByParams(int32_t osAccountId, const char *requestPa sizeof(osAccountId)); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS, (const uint8_t *)requestParams, HcStrlen(requestParams) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_QUERY_PARAMS); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_QUERY_CREDENTIAL_BY_PARAMS, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -434,12 +434,12 @@ static int32_t IpcCmQueryCredByParams(int32_t osAccountId, const char *requestPa int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = SearchCredsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnCredList); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -474,7 +474,7 @@ static int32_t IpcCmQueryCredInfoByCredId(int32_t osAccountId, const char *credI LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - int32_t ret = CreateCallCtx(&callCtx, NULL); + int32_t ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; @@ -483,21 +483,21 @@ static int32_t IpcCmQueryCredInfoByCredId(int32_t osAccountId, const char *credI sizeof(osAccountId)); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_CRED_ID, (const uint8_t *)credId, HcStrlen(credId) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_QUERY_PARAMS); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_QUERY_CREDENTIAL_BY_CRED_ID, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -505,12 +505,12 @@ static int32_t IpcCmQueryCredInfoByCredId(int32_t osAccountId, const char *credI int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = SearchCredInfoIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnCredInfo); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + LOGI("process done, ret: %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); return ret; } @@ -541,28 +541,28 @@ static int32_t IpcCmDeleteCredential(int32_t osAccountId, const char *credId) LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeDeleteCredentialParams(callCtx, osAccountId, credId); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_DEL_CREDENTIAL, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); ret = HC_ERR_IPC_UNKNOW_REPLY; int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -599,28 +599,28 @@ static int32_t IpcCmUpdateCredInfo(int32_t osAccountId, const char *credId, cons LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeUpdateParams(callCtx, osAccountId, credId, requestParams); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_UPDATE_CRED_INFO, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); ret = HC_ERR_IPC_UNKNOW_REPLY; int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -659,20 +659,20 @@ static int32_t IpcCmAgreeCredential(int32_t osAccountId, const char *selfCredId, LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeAgreeCredentialParams(callCtx, osAccountId, selfCredId, requestParams); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_AGREE_CREDENTIAL, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -680,12 +680,12 @@ static int32_t IpcCmAgreeCredential(int32_t osAccountId, const char *selfCredId, int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = AgreeCredentialIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnData); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -738,20 +738,20 @@ static int32_t IpcCmDelCredByParams(int32_t osAccountId, const char *requestPara LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeDelCredByParams(callCtx, osAccountId, requestParams); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_DEL_CRED_BY_PARAMS, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -759,12 +759,12 @@ static int32_t IpcCmDelCredByParams(int32_t osAccountId, const char *requestPara int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DelCredByParamsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnData); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -817,20 +817,20 @@ static int32_t IpcCmBatchUpdateCredentials(int32_t osAccountId, const char *requ LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeBatchUpdateParam(callCtx, osAccountId, requestParams); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CM_BATCH_UPDATE_CREDENTIALS, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); @@ -838,12 +838,12 @@ static int32_t IpcCmBatchUpdateCredentials(int32_t osAccountId, const char *requ int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = BatchUpdateCredIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnData); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } @@ -930,28 +930,28 @@ static int32_t IpcCmAuthCredential(int32_t osAccountId, int64_t authReqId, const LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeAuthDeviceParams(callCtx, osAccountId, authReqId, authParams, caCallback); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CA_AUTH_DEVICE, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); ret = HC_ERR_IPC_UNKNOW_REPLY; inOutLen = sizeof(int32_t); GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + LOGI("process done, ret: %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); return ret; } @@ -990,28 +990,28 @@ static int32_t IpcCmProcessCredData(int64_t authReqId, const uint8_t *data, uint LOGE("invalid params"); return HC_ERR_INVALID_PARAMS; } - ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; } ret = EncodeProcessDataParams(callCtx, authReqId, data, dataLen, callback); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = DoBinderCall(callCtx, IPC_CALL_ID_CA_PROCESS_CRED_DATA, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); ret = HC_ERR_IPC_UNKNOW_REPLY; inOutLen = sizeof(int32_t); GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + LOGI("process done, ret: %" LOG_PUB "d", ret); + DestroyCallCtx(&callCtx); return ret; } diff --git a/frameworks/src/ipc_sdk.c b/frameworks/src/ipc_sdk.c index f5d20e98..bb190a3b 100644 --- a/frameworks/src/ipc_sdk.c +++ b/frameworks/src/ipc_sdk.c @@ -32,6 +32,7 @@ extern "C" { #endif #define IPC_DATA_CACHES_1 1 +#define IPC_DATA_CACHES_2 2 #define IPC_DATA_CACHES_3 3 #define IPC_DATA_CACHES_4 4 #define IPC_DATA_CACHES_6 6 @@ -52,6 +53,51 @@ static IpcProxyCbInfo g_ipcProxyCbList = { 0 }; static IpcProxyCbInfo g_ipcListenerCbList = { 0 }; static HcMutex g_ipcMutex; +#define CHECK_IPC_PARAMS(cond) do { \ + if ((cond)) { \ + LOGE("Invalid params"); \ + return HC_ERR_INVALID_PARAMS; \ + } \ +} while (0) + +#define CREATE_IPC_CTX(callCtx) \ +ret = CreateCallCtx(&(callCtx)); \ +if (ret != HC_SUCCESS) { \ + return HC_ERR_IPC_INIT; \ +} + +#define SET_IPC_PARAM(callCtx, paramType, paramValue, valueSize) \ +ret = SetCallRequestParamInfo((callCtx), (paramType), (const uint8_t *)(paramValue), (valueSize)); \ +if (ret != HC_SUCCESS) { \ + break; \ +} + +#define DO_IPC_CALL(callCtx, callFunc, isSync) \ +ret = DoBinderCall((callCtx), (callFunc), (isSync)); \ +if (ret != HC_SUCCESS) { \ + break; \ +} + +#define CHECK_IPC_RESULT(cache, ret) \ +(ret) = HC_ERR_IPC_UNKNOW_REPLY; \ +inOutLen = sizeof(int32_t); \ +GetIpcReplyByType((cache), REPLAY_CACHE_NUM((cache)), PARAM_TYPE_IPC_RESULT, (uint8_t *)&(ret), &inOutLen); \ +if ((inOutLen != sizeof(int32_t)) || (ret) != HC_SUCCESS) { \ + break; \ +} + +#define GET_IPC_REPLY_STR(cache, paramType, outVar) \ +GetIpcReplyByType((cache), REPLAY_CACHE_NUM(cache), (paramType), (uint8_t *)&(outVar), NULL); \ +if ((outVar) == NULL || HcStrlen((outVar)) == 0) { \ + break; \ +} + +#define GET_IPC_REPLY_INT(cache, paramType, outVar) \ +inOutLen = sizeof(int32_t); \ +GetIpcReplyByType((cache), REPLAY_CACHE_NUM(cache), (paramType), (uint8_t *)(outVar), &inOutLen); \ + +#define DESTROY_IPC_CTX(callCtx) DestroyCallCtx(&(callCtx)) + static bool IsStrInvalid(const char *str) { return (str == NULL || str[0] == 0); @@ -133,1287 +179,563 @@ static void GetIpcReplyByType(const IpcDataInfo *ipcData, static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *callback) { - uintptr_t callCtx = 0x0; - int32_t ret; - LOGI("starting ..."); - if (IsStrInvalid(appId) || callback == NULL) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } + int32_t ret; + uintptr_t callCtx = 0x0; - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_DEV_AUTH_CB); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID); - ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_CB, true); - if (ret == HC_SUCCESS) { + CHECK_IPC_PARAMS((IsStrInvalid(appId) || callback == NULL)); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); + SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID); + DO_IPC_CALL(callCtx, IPC_CALL_ID_REG_CB, true); AddIpcCliCallbackCtx(appId, 0, &g_ipcProxyCbList); - } - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); - return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED; + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); + return ret; } static int32_t IpcGmUnRegCallback(const char *appId) { - uintptr_t callCtx = 0x0; - int32_t ret; - LOGI("starting ..."); - if (IsStrInvalid(appId)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } + int32_t ret; + uintptr_t callCtx = 0x0; - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_CB, true); - if (ret == HC_SUCCESS) { + CHECK_IPC_PARAMS(IsStrInvalid(appId)); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_UNREG_CB, true); DelIpcCliCallbackCtx(appId, &g_ipcProxyCbList); - } - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", HC_SUCCESS); - return HC_SUCCESS; + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); + return ret; } static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeListener *listener) { - uintptr_t callCtx = 0x0; - int32_t ret; - LOGI("starting ..."); - if (IsStrInvalid(appId) || (listener == NULL)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } + int32_t ret; + uintptr_t callCtx = 0x0; - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_LISTERNER, (const uint8_t *)listener, sizeof(*listener)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_LISTERNER); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID); - ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_LISTENER, true); - if (ret == HC_SUCCESS) { + CHECK_IPC_PARAMS((IsStrInvalid(appId) || (listener == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_LISTERNER, listener, sizeof(*listener)); + SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID); + DO_IPC_CALL(callCtx, IPC_CALL_ID_REG_LISTENER, true); AddIpcCliCallbackCtx(appId, 0, &g_ipcListenerCbList); - } - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); - return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED; + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); + return ret; } static int32_t IpcGmUnRegDataChangeListener(const char *appId) { - uintptr_t callCtx = 0x0; - int32_t ret; - LOGI("starting ..."); - if (IsStrInvalid(appId)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } + int32_t ret; + uintptr_t callCtx = 0x0; - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_LISTENER, true); - if (ret == HC_SUCCESS) { + CHECK_IPC_PARAMS(IsStrInvalid(appId)); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_UNREG_LISTENER, true); DelIpcCliCallbackCtx(appId, &g_ipcListenerCbList); - } - DestroyCallCtx(&callCtx, NULL); - LOGI("process done"); - return HC_SUCCESS; -} + } while(0); + DESTROY_IPC_CTX(callCtx); -static int32_t EncodeCreateGroupParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, - const char *appId, const char *createParams) -{ - int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_CREATE_PARAMS, - (const uint8_t *)createParams, HcStrlen(createParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_CREATE_PARAMS); - return HC_ERR_IPC_BUILD_PARAM; - } - return HC_SUCCESS; + LOGI("process done, ret: %" LOG_PUB "d", ret); + return ret; } static int32_t IpcGmCreateGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(createParams) || IsStrInvalid(appId)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = EncodeCreateGroupParams(callCtx, osAccountId, requestId, appId, createParams); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_CREATE_GROUP, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(createParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_CREATE_PARAMS, createParams, HcStrlen(createParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_CREATE_GROUP, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } -static int32_t EncodeDeleteGroupParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, - const char *appId, const char *delParams) -{ - int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, HcStrlen(delParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_DEL_PARAMS); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - return HC_ERR_IPC_BUILD_PARAM; - } - return HC_SUCCESS; -} - static int32_t IpcGmDeleteGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(delParams) || IsStrInvalid(appId)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = EncodeDeleteGroupParams(callCtx, osAccountId, requestId, appId, delParams); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(delParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEL_PARAMS, delParams, HcStrlen(delParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_DEL_GROUP, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } -static int32_t EncodeAddMemberParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, - const char *appId, const char *addParams) -{ - int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, HcStrlen(addParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_ADD_PARAMS); - return HC_ERR_IPC_BUILD_PARAM; - } - return HC_SUCCESS; -} - static int32_t IpcGmAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(appId) || IsStrInvalid(addParams)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = EncodeAddMemberParams(callCtx, osAccountId, requestId, appId, addParams); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_GROUP_MEMBER, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(addParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_ADD_PARAMS, addParams, HcStrlen(addParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_ADD_GROUP_MEMBER, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } -static int32_t EncodeDeleteMemberParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId, - const char *appId, const char *delParams) -{ - int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, HcStrlen(delParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_DEL_PARAMS); - return HC_ERR_IPC_BUILD_PARAM; - } - return HC_SUCCESS; -} - static int32_t IpcGmDelMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(appId) || IsStrInvalid(delParams)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = EncodeDeleteMemberParams(callCtx, osAccountId, requestId, appId, delParams); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP_MEMBER, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(delParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEL_PARAMS, delParams, HcStrlen(delParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_DEL_GROUP_MEMBER, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } static int32_t IpcGmAddMultiMembersToGroup(int32_t osAccountId, const char *appId, const char *addParams) { LOGI("starting ..."); - if (IsStrInvalid(appId) || IsStrInvalid(addParams)) { - LOGE("Invalid params"); - return HC_ERR_INVALID_PARAMS; - } + int32_t ret; uintptr_t callCtx = 0x0; - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, HcStrlen(addParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_ADD_PARAMS); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } IpcDataInfo replyCache = { 0 }; - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - int32_t inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(addParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_ADD_PARAMS, addParams, HcStrlen(addParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } static int32_t IpcGmDelMultiMembersFromGroup(int32_t osAccountId, const char *appId, const char *delParams) { LOGI("starting ..."); - if (IsStrInvalid(appId) || IsStrInvalid(delParams)) { - LOGE("Invalid params"); - return HC_ERR_INVALID_PARAMS; - } + int32_t ret; uintptr_t callCtx = 0x0; - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, HcStrlen(delParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_DEL_PARAMS); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } IpcDataInfo replyCache = { 0 }; - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - int32_t inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(delParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEL_PARAMS, delParams, HcStrlen(delParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t dataLen) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (!IS_COMM_DATA_VALID(data, dataLen)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_COMM_DATA); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GM_PROC_DATA, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); - LOGI("process done, ret %" LOG_PUB "d", ret); + CHECK_IPC_PARAMS((!IS_COMM_DATA_VALID(data, dataLen))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GM_PROC_DATA, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } static int32_t IpcGmGetRegisterInfo(const char *reqJsonStr, char **registerInfo) { + LOGI("starting ..."); + int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; - IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; + IpcDataInfo replyCache[IPC_DATA_CACHES_2] = { { 0 } }; char *outInfo = NULL; - if (IsStrInvalid(reqJsonStr) || (registerInfo == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQ_JSON, (const uint8_t *)reqJsonStr, HcStrlen(reqJsonStr) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQ_JSON); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_APPLY_REG_INFO, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BAD_PARAM; - } - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) { - LOGE("done, ret %" LOG_PUB "d", HC_ERR_IPC_OUT_DATA_NUM); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_REG_INFO, (uint8_t *)&outInfo, NULL); - if ((outInfo == NULL) || (HcStrlen(outInfo) == 0)) { - LOGE("done, ret %" LOG_PUB "d", HC_ERR_IPC_OUT_DATA); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_OUT_DATA; - } - *registerInfo = strdup(outInfo); - DestroyCallCtx(&callCtx, NULL); - return (*registerInfo != NULL) ? HC_SUCCESS : HC_ERR_NULL_PTR; + CHECK_IPC_PARAMS((IsStrInvalid(reqJsonStr) || (registerInfo == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQ_JSON, reqJsonStr, HcStrlen(reqJsonStr) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_APPLY_REG_INFO, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_REG_INFO, outInfo); + *registerInfo = strdup(outInfo); + if (registerInfo == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + } + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); + return ret; } static int32_t IpcGmCheckAccessToGroup(int32_t osAccountId, const char *appId, const char *groupId) { - uintptr_t callCtx = 0x0; int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(appId) || IsStrInvalid(groupId)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_GROUPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); - return ret; -} - -static int32_t ParseReturnResult(const IpcDataInfo *replies, int32_t cacheNum, char **returnData, uint32_t *returnNum) -{ - int32_t ret; - int32_t inOutLen; + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(groupId))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_GROUPID, groupId, HcStrlen(groupId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)returnData, NULL); - if (*returnData == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *returnData = strdup(*returnData); - if (*returnData == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)returnNum, &inOutLen); - return HC_SUCCESS; + return ret; } static int32_t IpcGmGetPkInfoList(int32_t osAccountId, const char *appId, const char *queryParams, char **returnInfoList, uint32_t *returnInfoNum) { - uintptr_t callCtx = 0x0; - int32_t ret; - int32_t inOutLen; - IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; - - if (IsStrInvalid(appId) || IsStrInvalid(queryParams) || (returnInfoList == NULL) || (returnInfoNum == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, - (const uint8_t *)&osAccountId, sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS, - (const uint8_t *)queryParams, HcStrlen(queryParams) + 1); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PK_INFO_LIST, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = ParseReturnResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnInfoList, returnInfoNum); - DestroyCallCtx(&callCtx, NULL); - return ret; -} - -static int32_t GroupInfoIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outGroupInfo) -{ - int32_t inOutLen; int32_t ret; - - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupInfo, NULL); - if (*outGroupInfo == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outGroupInfo = strdup(*outGroupInfo); - if (*outGroupInfo == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - return HC_SUCCESS; -} - -static int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId, char **outGroupInfo) -{ uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; + char *outInfo = NULL; + + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(queryParams) || (returnInfoList == NULL) || (returnInfoNum == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_QUERY_PARAMS, queryParams, HcStrlen(queryParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_PK_INFO_LIST, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_RETURN_DATA, outInfo); + *returnInfoList = strdup(outInfo); + if (returnInfoList == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + break; + } + GET_IPC_REPLY_INT(replyCache, PARAM_TYPE_DATA_NUM, returnInfoNum); + } while(0); + DESTROY_IPC_CTX(callCtx); - if (IsStrInvalid(groupId) || IsStrInvalid(appId) || (outGroupInfo == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_GROUPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_GROUP_INFO, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = GroupInfoIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupInfo); - DestroyCallCtx(&callCtx, NULL); return ret; } -static int32_t SearchGroupsIpcResult(const IpcDataInfo *replies, - int32_t cacheNum, char **outGroupVec, uint32_t *groupNum) +static int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId, char **outGroupInfo) { int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; + IpcDataInfo replyCache[IPC_DATA_CACHES_2] = { { 0 } }; + char *outInfo = NULL; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL); - if (*outGroupVec == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outGroupVec = strdup(*outGroupVec); - if (*outGroupVec == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen); - return HC_SUCCESS; + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(groupId) || (outGroupInfo == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_GROUPID, groupId, HcStrlen(groupId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_GROUP_INFO, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_GROUP_INFO, outInfo); + *outGroupInfo = strdup(outInfo); + if (outGroupInfo == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + } + } while(0); + DESTROY_IPC_CTX(callCtx); + + return ret; } static int32_t IpcGmGetGroupInfo(int32_t osAccountId, const char *appId, const char *queryParams, char **outGroupVec, uint32_t *groupNum) { + int32_t ret; uintptr_t callCtx = 0x0; - IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; - - if (IsStrInvalid(queryParams) || IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS, - (const uint8_t *)queryParams, HcStrlen(queryParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_QUERY_PARAMS); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_SEARCH_GROUPS, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - int32_t inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = SearchGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum); - DestroyCallCtx(&callCtx, NULL); - return ret; -} + IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; + char *outInfo = NULL; -static int32_t JoinedGroupsIpcResult(const IpcDataInfo *replies, - int32_t cacheNum, char **outGroupVec, uint32_t *groupNum) -{ - int32_t ret; - int32_t inOutLen; + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(queryParams) || (outGroupVec == NULL) || (groupNum == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_QUERY_PARAMS, queryParams, HcStrlen(queryParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_SEARCH_GROUPS, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_GROUP_INFO, outInfo); + *outGroupVec = strdup(outInfo); + if (outGroupVec == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + break; + } + GET_IPC_REPLY_INT(replyCache, PARAM_TYPE_DATA_NUM, groupNum); + } while(0); + DESTROY_IPC_CTX(callCtx); - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL); - if (*outGroupVec == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outGroupVec = strdup(*outGroupVec); - if (*outGroupVec == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen); - return HC_SUCCESS; + return ret; } static int32_t IpcGmGetJoinedGroups(int32_t osAccountId, const char *appId, int32_t groupType, char **outGroupVec, uint32_t *groupNum) { + int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; - IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; - - if (IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUP_TYPE, (const uint8_t *)&groupType, sizeof(groupType)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_GROUP_TYPE); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_JOINED_GROUPS, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = JoinedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum); - DestroyCallCtx(&callCtx, NULL); - return ret; -} + IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; + char *outInfo = NULL; -static int32_t RelatedGroupsIpcResult(const IpcDataInfo *replies, - int32_t cacheNum, char **outGroupVec, uint32_t *groupNum) -{ - int32_t ret; - int32_t inOutLen; + CHECK_IPC_PARAMS((IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_GROUP_TYPE, &groupType, sizeof(groupType)); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_JOINED_GROUPS, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_GROUP_INFO, outInfo); + *outGroupVec = strdup(outInfo); + if (outGroupVec == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + break; + } + GET_IPC_REPLY_INT(replyCache, PARAM_TYPE_DATA_NUM, groupNum); + } while(0); + DESTROY_IPC_CTX(callCtx); - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL); - if (*outGroupVec == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outGroupVec = strdup(*outGroupVec); - if (*outGroupVec == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen); - return HC_SUCCESS; + return ret; } static int32_t IpcGmGetRelatedGroups(int32_t osAccountId, const char *appId, const char *peerUdid, char **outGroupVec, uint32_t *groupNum) -{ - uintptr_t callCtx = 0x0; - int32_t ret; - int32_t inOutLen; - IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; - - if (IsStrInvalid(appId) || IsStrInvalid(peerUdid) || (outGroupVec == NULL) || (groupNum == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, sizeof(int32_t)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, HcStrlen(peerUdid) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_UDID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_RELATED_GROUPS, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - LOGE("Service return exception, ret: %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = RelatedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum); - DestroyCallCtx(&callCtx, NULL); - return ret; -} - -static int32_t DevInfoByIdIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfo) { int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; + IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; + char *outInfo = NULL; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfo, NULL); - if (*outDevInfo == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outDevInfo = strdup(*outDevInfo); - if (*outDevInfo == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - return HC_SUCCESS; -} + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(peerUdid) || (outGroupVec == NULL) || (groupNum == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_UDID, peerUdid, HcStrlen(peerUdid) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_RELATED_GROUPS, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_GROUP_INFO, outInfo); + *outGroupVec = strdup(outInfo); + if (outGroupVec == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + break; + } + GET_IPC_REPLY_INT(replyCache, PARAM_TYPE_DATA_NUM, groupNum); + } while(0); + DESTROY_IPC_CTX(callCtx); -static int32_t FormParamsForGettingDeviceInfo(int32_t osAccountId, const char *appId, - const char *peerUdid, const char *groupId, uintptr_t callCtx) -{ - int32_t ret; - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, HcStrlen(peerUdid) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_UDID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_GROUPID); - return HC_ERR_IPC_BUILD_PARAM; - } - return HC_SUCCESS; + return ret; } static int32_t IpcGmGetDeviceInfoById(int32_t osAccountId, const char *appId, const char *peerUdid, const char *groupId, char **outDevInfo) { - uintptr_t callCtx = 0x0; int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; - IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; - - LOGI("starting ..."); - if (IsStrInvalid(appId) || IsStrInvalid(peerUdid) || IsStrInvalid(groupId) || (outDevInfo == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = FormParamsForGettingDeviceInfo(osAccountId, appId, peerUdid, groupId, callCtx); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_DEV_INFO_BY_ID, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - LOGE("Service return exception, ret: %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DevInfoByIdIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfo); - LOGI("proc result done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); - return ret; -} + IpcDataInfo replyCache[IPC_DATA_CACHES_2] = { { 0 } }; + char *outInfo = NULL; -static int32_t TrustedDevIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfoVec, uint32_t *devNum) -{ - int32_t ret; - int32_t inOutLen; + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(peerUdid) || IsStrInvalid(groupId) || (outDevInfo == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_UDID, peerUdid, HcStrlen(peerUdid) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_GROUPID, groupId, HcStrlen(groupId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_DEV_INFO_BY_ID, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_DEVICE_INFO, outInfo); + *outDevInfo = strdup(outInfo); + if (outDevInfo == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + } + } while(0); + DESTROY_IPC_CTX(callCtx); - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen); - if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) { - return HC_ERR_IPC_OUT_DATA_NUM; - } - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfoVec, NULL); - if (*outDevInfoVec == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outDevInfoVec = strdup(*outDevInfoVec); - if (*outDevInfoVec == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)devNum, &inOutLen); - return HC_SUCCESS; + return ret; } static int32_t IpcGmGetTrustedDevices(int32_t osAccountId, const char *appId, const char *groupId, char **outDevInfoVec, uint32_t *deviceNum) { + int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; - IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; + IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } }; + char *outInfo = NULL; + + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(groupId) || (outDevInfoVec == NULL) || (deviceNum == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_GROUPID, groupId, HcStrlen(groupId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_TRUST_DEVICES, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_DEVICE_INFO, outInfo); + *outDevInfoVec = strdup(outInfo); + if (outDevInfoVec == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + break; + } + GET_IPC_REPLY_INT(replyCache, PARAM_TYPE_DATA_NUM, deviceNum); + } while(0); + DESTROY_IPC_CTX(callCtx); - if (IsStrInvalid(appId) || IsStrInvalid(groupId) || (outDevInfoVec == NULL) || (deviceNum == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_GROUPID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_TRUST_DEVICES, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = TrustedDevIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfoVec, deviceNum); - DestroyCallCtx(&callCtx, NULL); return ret; } static bool IpcGmIsDeviceInGroup(int32_t osAccountId, const char *appId, const char *groupId, const char *udid) { + int32_t ret; uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - if (IsStrInvalid(appId) || IsStrInvalid(groupId) || IsStrInvalid(udid)) { - LOGE("Invalid params."); - return false; - } - int32_t ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return false; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return false; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return false; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, HcStrlen(groupId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_GROUPID); - DestroyCallCtx(&callCtx, NULL); - return false; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)udid, HcStrlen(udid) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_UDID); - DestroyCallCtx(&callCtx, NULL); - return false; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_IS_DEV_IN_GROUP, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); - return false; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((IsStrInvalid(appId) || IsStrInvalid(groupId) || IsStrInvalid(udid))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_GROUPID, groupId, HcStrlen(groupId) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_UDID, udid, HcStrlen(udid) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_IS_DEV_IN_GROUP, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + return (ret == HC_SUCCESS) ? true : false; } static void IpcGmDestroyInfo(char **returnInfo) { - if ((returnInfo == NULL) || (*returnInfo == NULL)) { - return; - } - FreeJsonString(*returnInfo); - *returnInfo = NULL; -} - -static void IpcGmCancelRequest(int64_t requestId, const char *appId) -{ - uintptr_t callCtx = 0x0; - int32_t ret; - - LOGI("starting ..."); - if (IsStrInvalid(appId)) { - LOGE("Invalid params."); - return; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - DestroyCallCtx(&callCtx, NULL); - return; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); + if ((returnInfo == NULL) || (*returnInfo == NULL)) { return; } - ret = DoBinderCall(callCtx, IPC_CALL_GM_CANCEL_REQUEST, true); - DestroyCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("ipc call failed"); - } else { - LOGI("process done, ret %" LOG_PUB "d", ret); - } + FreeJsonString(*returnInfo); + *returnInfo = NULL; +} + +static void IpcGmCancelRequest(int64_t requestId, const char *appId) +{ + LOGI("starting ..."); + int32_t ret; + uintptr_t callCtx = 0x0; + + CHECK_IPC_PARAMS((IsStrInvalid(appId))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_GM_CANCEL_REQUEST, true); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); } static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj) @@ -1444,270 +766,128 @@ static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj) return; } -static int32_t EncodeProcessDataParams(uintptr_t callCtx, int64_t authReqId, - const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback) -{ - int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, (const uint8_t *)data, dataLen); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_COMM_DATA); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_DEV_AUTH_CB); - return HC_ERR_IPC_BUILD_PARAM; - } - SetCbCtxToDataCtx(callCtx, 0x0); - return HC_SUCCESS; -} - static int32_t IpcGaProcessData(int64_t authReqId, const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (!IS_COMM_DATA_VALID(data, dataLen) || (callback == NULL)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = EncodeProcessDataParams(callCtx, authReqId, data, dataLen, callback); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GA_PROC_DATA, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((!IS_COMM_DATA_VALID(data, dataLen) || (callback == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &authReqId, sizeof(authReqId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEV_AUTH_CB, callback, sizeof(*callback)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_UDID, udid, HcStrlen(udid) + 1); + SetCbCtxToDataCtx(callCtx, 0x0); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GA_PROC_DATA, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } -static int32_t EncodeAuthDeviceParams(uintptr_t callCtx, int32_t osAccountId, int64_t authReqId, - const char *authParams, const DeviceAuthCallback *callback) -{ - int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, - HcStrlen(authParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_AUTH_PARAMS); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_DEV_AUTH_CB); - return HC_ERR_IPC_BUILD_PARAM; - } - SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_AUTH_ID); - return HC_SUCCESS; -} - static int32_t IpcGaAuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(authParams) || (callback == NULL)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = EncodeAuthDeviceParams(callCtx, osAccountId, authReqId, authParams, callback); - if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); - return ret; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_AUTH_DEVICE, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((IsStrInvalid(authParams) || (callback == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &authReqId, sizeof(authReqId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_AUTH_PARAMS, authParams, HcStrlen(authParams) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEV_AUTH_CB, callback, sizeof(*callback)); + SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_AUTH_ID); + DO_IPC_CALL(callCtx, IPC_CALL_ID_AUTH_DEVICE, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } static void IpcGaCancelRequest(int64_t requestId, const char *appId) { - uintptr_t callCtx = 0x0; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; - LOGI("starting ..."); - if (IsStrInvalid(appId)) { - LOGE("Invalid params."); - return; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - DestroyCallCtx(&callCtx, NULL); - return; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, HcStrlen(appId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_APPID); - DestroyCallCtx(&callCtx, NULL); - return; - } - ret = DoBinderCall(callCtx, IPC_CALL_GA_CANCEL_REQUEST, true); - DestroyCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("ipc call failed"); - } else { - LOGI("process done, ret %" LOG_PUB "d", ret); - } -} + CHECK_IPC_PARAMS((IsStrInvalid(appId))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_APPID, appId, HcStrlen(appId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_GA_CANCEL_REQUEST, true); + } while(0); + DESTROY_IPC_CTX(callCtx); -static int32_t GetIpcReplyByTypeInner(const IpcDataInfo *replies, int32_t cacheNum, char **outInfo) -{ - GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)outInfo, NULL); - if (*outInfo == NULL) { - return HC_ERR_IPC_OUT_DATA; - } - *outInfo = strdup(*outInfo); - if (*outInfo == NULL) { - return HC_ERR_ALLOC_MEMORY; - } - return HC_SUCCESS; + LOGI("process done, ret: %" LOG_PUB "d", ret); } static int32_t IpcGaGetRealInfo(int32_t osAccountId, const char *pseudonymId, char **realInfo) { - uintptr_t callCtx = 0x0; int32_t ret; - IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; + uintptr_t callCtx = 0x0; + int32_t inOutLen; + IpcDataInfo replyCache[IPC_DATA_CACHES_2] = { { 0 } }; + char *outInfo = NULL; + + CHECK_IPC_PARAMS((IsStrInvalid(pseudonymId) || (realInfo == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_PSEUDONYM_ID, pseudonymId, HcStrlen(pseudonymId) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_REAL_INFO, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_RETURN_DATA, outInfo); + *realInfo = strdup(outInfo); + if (realInfo == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + } + } while(0); + DESTROY_IPC_CTX(callCtx); - LOGI("starting ..."); - if (IsStrInvalid(pseudonymId) || (realInfo == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_PSEUDONYM_ID, (const uint8_t *)pseudonymId, - HcStrlen(pseudonymId) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_PSEUDONYM_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_REAL_INFO, true); - if (ret != HC_SUCCESS) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - LOGI("process done, ret %" LOG_PUB "d", ret); - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = GetIpcReplyByTypeInner(replyCache, REPLAY_CACHE_NUM(replyCache), realInfo); - if (ret != HC_SUCCESS) { - LOGE("GetIpcReplyByType failed, ret %" LOG_PUB "d", ret); - } - DestroyCallCtx(&callCtx, NULL); return ret; } static int32_t IpcGaGetPseudonymId(int32_t osAccountId, const char *indexKey, char **pseudonymId) { - uintptr_t callCtx = 0x0; int32_t ret; - IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } }; + uintptr_t callCtx = 0x0; + IpcDataInfo replyCache[IPC_DATA_CACHES_2] = { { 0 } }; + char *outInfo = NULL; + + CHECK_IPC_PARAMS((IsStrInvalid(indexKey) || (pseudonymId == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, &osAccountId, sizeof(osAccountId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_INDEX_KEY, indexKey, HcStrlen(indexKey) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_GET_PSEUDONYM_ID, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_RETURN_DATA, outInfo); + *pseudonymId = strdup(outInfo); + if (pseudonymId == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + } + } while(0); + DESTROY_IPC_CTX(callCtx); - LOGI("starting ..."); - if (IsStrInvalid(indexKey) || (pseudonymId == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId, - sizeof(osAccountId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OS_ACCOUNT_ID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_INDEX_KEY, (const uint8_t *)indexKey, HcStrlen(indexKey) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_INDEX_KEY); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PSEUDONYM_ID, true); - if (ret != HC_SUCCESS) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - LOGI("process done, ret %" LOG_PUB "d", ret); - DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = GetIpcReplyByTypeInner(replyCache, REPLAY_CACHE_NUM(replyCache), pseudonymId); - if (ret != HC_SUCCESS) { - LOGE("GetIpcReplyByType failed, ret %" LOG_PUB "d", ret); - } - DestroyCallCtx(&callCtx, NULL); return ret; } @@ -1812,12 +992,15 @@ static int32_t GetSharedKeyAndRandom(const IpcDataInfo *replies, int32_t cacheNu static int32_t IpcAvGetClientSharedKey(const char *peerPk, const char *serviceId, DataBuff *returnSharedKey, DataBuff *returnRandom) { + LOGI("starting ..."); + int32_t ret; + uintptr_t callCtx = 0x0; + if ((peerPk == NULL) || (serviceId == NULL) || (returnSharedKey == NULL) || (returnRandom == NULL)) { LOGE("Invalid params."); return HC_ERR_INVALID_PARAMS; } - uintptr_t callCtx = 0x0; - int32_t ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; @@ -1825,18 +1008,18 @@ static int32_t IpcAvGetClientSharedKey(const char *peerPk, const char *serviceId ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_PUB_KEY, (const uint8_t *)peerPk, HcStrlen(peerPk) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_PUB_KEY); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_SERVICE_ID, (const uint8_t *)serviceId, HcStrlen(serviceId) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_SERVICE_ID); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = DoBinderCall(callCtx, IPC_CALL_ID_AV_GET_CLIENT_SHARED_KEY, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } IpcDataInfo replyCache[IPC_DATA_CACHES_6] = { { 0 } }; @@ -1845,11 +1028,11 @@ static int32_t IpcAvGetClientSharedKey(const char *peerPk, const char *serviceId int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = GetSharedKeyAndRandom(replyCache, REPLAY_CACHE_NUM(replyCache), returnSharedKey, returnRandom); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } @@ -1879,13 +1062,16 @@ static int32_t GetSharedKey(const IpcDataInfo *replies, int32_t cacheNum, DataBu static int32_t IpcAvGetServerSharedKey(const char *peerPk, const char *serviceId, const DataBuff *random, DataBuff *returnSharedKey) { + LOGI("starting ..."); + int32_t ret; + uintptr_t callCtx = 0x0; + if ((peerPk == NULL) || (serviceId == NULL) || (random == NULL) || (random->data == NULL) || (returnSharedKey == NULL)) { LOGE("Invalid params."); return HC_ERR_INVALID_PARAMS; } - uintptr_t callCtx = 0x0; - int32_t ret = CreateCallCtx(&callCtx, NULL); + ret = CreateCallCtx(&callCtx); if (ret != HC_SUCCESS) { LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); return HC_ERR_IPC_INIT; @@ -1893,24 +1079,24 @@ static int32_t IpcAvGetServerSharedKey(const char *peerPk, const char *serviceId ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_PUB_KEY, (const uint8_t *)peerPk, HcStrlen(peerPk) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_PUB_KEY); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_SERVICE_ID, (const uint8_t *)serviceId, HcStrlen(serviceId) + 1); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_SERVICE_ID); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_RANDOM, (const uint8_t *)random->data, random->length); if (ret != HC_SUCCESS) { LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_RANDOM); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_BUILD_PARAM; } ret = DoBinderCall(callCtx, IPC_CALL_ID_AV_GET_SERVER_SHARED_KEY, true); if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return HC_ERR_IPC_PROC_FAILED; } IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } }; @@ -1919,11 +1105,11 @@ static int32_t IpcAvGetServerSharedKey(const char *peerPk, const char *serviceId int32_t inOutLen = sizeof(int32_t); GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); if (ret != HC_SUCCESS) { - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } ret = GetSharedKey(replyCache, REPLAY_CACHE_NUM(replyCache), returnSharedKey); - DestroyCallCtx(&callCtx, NULL); + DestroyCallCtx(&callCtx); return ret; } @@ -1936,200 +1122,104 @@ static void InitIpcAccountVerifierMethods(AccountVerifier *accountVerifier) DEVICE_AUTH_API_PUBLIC int32_t ProcessCredential(int32_t operationCode, const char *reqJsonStr, char **returnData) { - uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; + LOGI("starting ..."); int32_t ret; - IpcDataInfo replyCache = { 0 }; + uintptr_t callCtx = 0x0; + IpcDataInfo replyCache[IPC_RESULT_NUM_2] = { { 0 } }; + char *outInfo = NULL; - LOGI("starting ..."); - if (IsStrInvalid(reqJsonStr) || (returnData == NULL)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo( - callCtx, PARAM_TYPE_OPCODE, (const uint8_t *)&operationCode, sizeof(operationCode)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_OPCODE); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = - SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQ_JSON, (const uint8_t *)reqJsonStr, HcStrlen(reqJsonStr) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_REQ_JSON); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_PROCESS_CREDENTIAL, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = GetIpcReplyByTypeInner(&replyCache, REPLAY_CACHE_NUM(replyCache), returnData); - if (ret != HC_SUCCESS) { - LOGE("GetIpcReplyByType failed, ret %" LOG_PUB "d", ret); - } - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((IsStrInvalid(reqJsonStr) || (returnData == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_OPCODE, &operationCode, sizeof(operationCode)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQ_JSON, reqJsonStr, HcStrlen(reqJsonStr) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_PROCESS_CREDENTIAL, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + GET_IPC_REPLY_STR(replyCache, PARAM_TYPE_RETURN_DATA, outInfo); + *returnData = strdup(outInfo); + if (returnData == NULL) { + ret = HC_ERR_ALLOC_MEMORY; + } + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } DEVICE_AUTH_API_PUBLIC int32_t ProcessAuthDevice( int64_t requestId, const char *authParams, const DeviceAuthCallback *callback) { - uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(authParams) || (callback == NULL)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo( - callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, HcStrlen(authParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_AUTH_PARAMS); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_DEV_AUTH_CB); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_DIRECT_AUTH_ID); - ret = DoBinderCall(callCtx, IPC_CALL_ID_DA_PROC_DATA, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType( - &replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((IsStrInvalid(authParams) || (callback == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_AUTH_PARAMS, authParams, HcStrlen(authParams) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEV_AUTH_CB, callback, sizeof(*callback)); + SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_DIRECT_AUTH_ID); + DO_IPC_CALL(callCtx, IPC_CALL_ID_DA_PROC_DATA, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } DEVICE_AUTH_API_PUBLIC int32_t StartAuthDevice( int64_t authReqId, const char *authParams, const DeviceAuthCallback *callback) { - uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(authParams) || (callback == NULL)) { - LOGE("invalid params"); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_IPC_INIT; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo( - callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, HcStrlen(authParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_AUTH_PARAMS); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_DEV_AUTH_CB); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_BUILD_PARAM; - } - SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_DIRECT_AUTH_ID); - ret = DoBinderCall(callCtx, IPC_CALL_ID_DA_AUTH_DEVICE, true); - if (ret == HC_ERR_IPC_INTERNAL_FAILED) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType( - &replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((IsStrInvalid(authParams) || (callback == NULL))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_AUTH_PARAMS, authParams, HcStrlen(authParams) + 1); + SET_IPC_PARAM(callCtx, PARAM_TYPE_DEV_AUTH_CB, callback, sizeof(*callback)); + SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_DIRECT_AUTH_ID); + DO_IPC_CALL(callCtx, IPC_CALL_ID_DA_AUTH_DEVICE, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } DEVICE_AUTH_API_PUBLIC int32_t CancelAuthRequest(int64_t requestId, const char *authParams) { - uintptr_t callCtx = IPC_CALL_CONTEXT_INIT; + LOGI("starting ..."); int32_t ret; + uintptr_t callCtx = 0x0; int32_t inOutLen; IpcDataInfo replyCache = { 0 }; - LOGI("starting ..."); - if (IsStrInvalid(authParams)) { - LOGE("Invalid params."); - return HC_ERR_INVALID_PARAMS; - } - ret = CreateCallCtx(&callCtx, NULL); - if (ret != HC_SUCCESS) { - LOGE("CreateCallCtx failed, ret %" LOG_PUB "d", ret); - return HC_ERR_NULL_PTR; - } - ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId)); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, type %" LOG_PUB "d", ret, PARAM_TYPE_REQID); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_NULL_PTR; - } - ret = SetCallRequestParamInfo( - callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, HcStrlen(authParams) + 1); - if (ret != HC_SUCCESS) { - LOGE("set request param failed, ret %" LOG_PUB "d, param id %" LOG_PUB "d", ret, PARAM_TYPE_AUTH_PARAMS); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_NULL_PTR; - } - ret = DoBinderCall(callCtx, IPC_CALL_ID_DA_CANCEL_REQUEST, true); - if (ret != HC_SUCCESS) { - LOGE("ipc call failed"); - DestroyCallCtx(&callCtx, NULL); - return HC_ERR_IPC_PROC_FAILED; - } - DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); - ret = HC_ERR_IPC_UNKNOW_REPLY; - inOutLen = sizeof(int32_t); - GetIpcReplyByType( - &replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen); - LOGI("process done, ret %" LOG_PUB "d", ret); - DestroyCallCtx(&callCtx, NULL); + CHECK_IPC_PARAMS((IsStrInvalid(authParams))); + CREATE_IPC_CTX(callCtx); + do { + SET_IPC_PARAM(callCtx, PARAM_TYPE_REQID, &requestId, sizeof(requestId)); + SET_IPC_PARAM(callCtx, PARAM_TYPE_AUTH_PARAMS, authParams, HcStrlen(authParams) + 1); + DO_IPC_CALL(callCtx, IPC_CALL_ID_DA_CANCEL_REQUEST, true); + DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache)); + CHECK_IPC_RESULT(&replyCache, ret); + } while(0); + DESTROY_IPC_CTX(callCtx); + + LOGI("process done, ret: %" LOG_PUB "d", ret); return ret; } diff --git a/frameworks/src/ipc_service_common.c b/frameworks/src/ipc_service_common.c index 3f5e7e34..ded80fdc 100644 --- a/frameworks/src/ipc_service_common.c +++ b/frameworks/src/ipc_service_common.c @@ -520,8 +520,6 @@ int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32_t para } callRet = g_devGroupMgrMethod.getRegisterInfo(reqJsonStr, ®isterInfo); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t)); if (registerInfo != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_REG_INFO, (const uint8_t *)registerInfo, HcStrlen(registerInfo) + 1); @@ -590,8 +588,6 @@ int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum callRet = g_devGroupMgrMethod.getPkInfoList(osAccountId, appId, queryParams, &returnInfoList, &returnInfoNum); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t)); if (returnInfoList != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnInfoList, HcStrlen(returnInfoList) + 1); @@ -631,8 +627,6 @@ int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_t param callRet = g_devGroupMgrMethod.getGroupInfoById(osAccountId, appId, groupId, &groupInfo); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t)); if (groupInfo != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)groupInfo, HcStrlen(groupInfo) + 1); g_devGroupMgrMethod.destroyInfo(&groupInfo); @@ -671,8 +665,6 @@ int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t paramNum, callRet = g_devGroupMgrMethod.getGroupInfo(osAccountId, appId, queryParams, &outGroups, &groupNum); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t)); if (outGroups != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1); } else { @@ -714,8 +706,6 @@ int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t paramN callRet = g_devGroupMgrMethod.getJoinedGroups(osAccountId, appId, groupType, &outGroups, &groupNum); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t)); if (outGroups != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1); g_devGroupMgrMethod.destroyInfo(&outGroups); @@ -754,8 +744,6 @@ int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_t param callRet = g_devGroupMgrMethod.getRelatedGroups(osAccountId, appId, peerUdid, &outGroups, &groupNum); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t)); if (outGroups != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, HcStrlen(outGroups) + 1); } else { @@ -798,8 +786,6 @@ int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32_t para callRet = g_devGroupMgrMethod.getDeviceInfoById(osAccountId, appId, peerUdid, groupId, &outDevInfo); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t)); if (outDevInfo != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1); @@ -838,8 +824,6 @@ int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32_t para callRet = g_devGroupMgrMethod.getTrustedDevices(osAccountId, appId, groupId, &outDevInfo, &outDevNum); ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); - ret += IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT_NUM, - (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t)); if (outDevInfo != NULL) { ret += IpcEncodeCallReply(outCache, PARAM_TYPE_DEVICE_INFO, (const uint8_t *)outDevInfo, HcStrlen(outDevInfo) + 1); @@ -1123,6 +1107,7 @@ int32_t IpcServiceGaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) { + int32_t callRet; int32_t ret; int32_t osAccountId; const char *pseudonymId = NULL; @@ -1139,13 +1124,14 @@ int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, } char *realInfo = NULL; - ret = g_groupAuthMgrMethod.getRealInfo(osAccountId, pseudonymId, &realInfo); - if ((realInfo != NULL) && (ret == HC_SUCCESS)) { - ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)realInfo, + callRet = g_groupAuthMgrMethod.getRealInfo(osAccountId, pseudonymId, &realInfo); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); + if ((realInfo != NULL) && (callRet == HC_SUCCESS)) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)realInfo, HcStrlen(realInfo) + 1); HcFree(realInfo); } else { - ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0); } LOGI("process done, ipc ret %" LOG_PUB "d", ret); return ret; @@ -1153,6 +1139,7 @@ int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) { + int32_t callRet; int32_t ret; int32_t osAccountId; const char *indexKey = NULL; @@ -1169,13 +1156,14 @@ int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNu } char *pseudonymId = NULL; - ret = g_groupAuthMgrMethod.getPseudonymId(osAccountId, indexKey, &pseudonymId); - if ((pseudonymId != NULL) && (ret == HC_SUCCESS)) { - ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)pseudonymId, + callRet = g_groupAuthMgrMethod.getPseudonymId(osAccountId, indexKey, &pseudonymId); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); + if ((pseudonymId != NULL) && (callRet == HC_SUCCESS)) { + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)pseudonymId, HcStrlen(pseudonymId) + 1); HcFree(pseudonymId); } else { - ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0); } LOGI("process done, ipc ret %" LOG_PUB "d", ret); return ret; @@ -1183,6 +1171,7 @@ int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNu int32_t IpcServiceDaProcessCredential(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache) { + int32_t callRet; int32_t ret; int32_t operationCode = 0; const char *reqJsonStr = NULL; @@ -1198,16 +1187,14 @@ int32_t IpcServiceDaProcessCredential(const IpcDataInfo *ipcParams, int32_t para if (ret != HC_SUCCESS) { return ret; } - ret = ProcessCredential(operationCode, reqJsonStr, &returnData); - if (ret != HC_SUCCESS) { - LOGI("call ProcessCredential failed %" LOG_PUB "d", ret); - } - if (returnData != NULL) { - ret = IpcEncodeCallReply( + callRet = ProcessCredential(operationCode, reqJsonStr, &returnData); + ret = IpcEncodeCallReply(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t)); + if (returnData != NULL && callRet == HC_SUCCESS) { + ret += IpcEncodeCallReply( outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnData, HcStrlen(returnData) + 1); HcFree(returnData); } else { - ret = IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0); + ret += IpcEncodeCallReply(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0); } LOGI("process done, ipc ret %" LOG_PUB "d", ret); return ret; diff --git a/frameworks/src/lite/ipc_adapt.c b/frameworks/src/lite/ipc_adapt.c index 67c97e0c..476eaa15 100644 --- a/frameworks/src/lite/ipc_adapt.c +++ b/frameworks/src/lite/ipc_adapt.c @@ -1342,16 +1342,13 @@ void InitDevAuthListenerCbCtx(DataChangeListener *ctx) } /* ipc client process adapter */ -int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) +int32_t CreateCallCtx(uintptr_t *callCtx) { - ProxyDevAuthData *dataCache = NULL; - - (void)cbCtx; if (callCtx == NULL) { return HC_ERR_INVALID_PARAMS; } - dataCache = (ProxyDevAuthData *)HcMalloc(sizeof(ProxyDevAuthData), 0); + ProxyDevAuthData *dataCache = (ProxyDevAuthData *)HcMalloc(sizeof(ProxyDevAuthData), 0); if (dataCache == NULL) { LOGE("call context alloc failed"); return HC_ERR_ALLOC_MEMORY; @@ -1360,7 +1357,7 @@ int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) dataCache->tmpData = InitIpcDataCache(IPC_DATA_BUFF_MAX_SZ); dataCache->reply = InitIpcDataCache(IPC_DATA_BUFF_MAX_SZ); if ((dataCache->data == NULL) || (dataCache->tmpData == NULL) || (dataCache->reply == NULL)) { - DestroyCallCtx((uintptr_t *)(dataCache), NULL); + DestroyCallCtx((uintptr_t *)(dataCache)); return HC_ERROR; } /* linux lite, ipc io init with : token + SvcIdentity */ @@ -1369,11 +1366,9 @@ int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) return HC_SUCCESS; } -void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) +void DestroyCallCtx(uintptr_t *callCtx) { ProxyDevAuthData *dataCache = NULL; - - (void)cbCtx; if ((callCtx != NULL) && (*callCtx != 0)) { dataCache = (ProxyDevAuthData *)(*callCtx); if (dataCache->data != NULL) { diff --git a/frameworks/src/standard/ipc_adapt.cpp b/frameworks/src/standard/ipc_adapt.cpp index 434b2af9..be9e2941 100644 --- a/frameworks/src/standard/ipc_adapt.cpp +++ b/frameworks/src/standard/ipc_adapt.cpp @@ -1474,16 +1474,13 @@ void InitDevAuthCredListenerCbCtx(CredChangeListener *ctx) } /* ipc client process adapter */ -int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) +int32_t CreateCallCtx(uintptr_t *callCtx) { - ProxyDevAuthData *dataCache = nullptr; - - (void)cbCtx; if (callCtx == nullptr) { return HC_ERR_INVALID_PARAMS; } - dataCache = new(std::nothrow) ProxyDevAuthData(); + ProxyDevAuthData *dataCache = new(std::nothrow) ProxyDevAuthData(); if (dataCache == nullptr) { LOGE("call context alloc failed"); return HC_ERR_ALLOC_MEMORY; @@ -1492,11 +1489,9 @@ int32_t CreateCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) return HC_SUCCESS; } -void DestroyCallCtx(uintptr_t *callCtx, uintptr_t *cbCtx) +void DestroyCallCtx(uintptr_t *callCtx) { ProxyDevAuthData *dataCache = nullptr; - - (void)cbCtx; if ((callCtx != nullptr) && (*callCtx != 0)) { dataCache = reinterpret_cast(*callCtx); delete dataCache; diff --git a/services/frameworks/inc/common_defs.h b/services/frameworks/inc/common_defs.h index 07b7d2bf..fbb63a3a 100644 --- a/services/frameworks/inc/common_defs.h +++ b/services/frameworks/inc/common_defs.h @@ -122,7 +122,6 @@ #define FIELD_PEER_ID_FROM_REQUEST "peerIdFromRequest" #define FIELD_STEP "step" #define FIELD_DATA "data" -#define FIELD_EPK "epk" #define FIELD_AUTH_KEY_ALG_ENCODE "authKeyAlgEncode" #define FIELD_AUTH_PK_INFO "authPkInfo" #define FIELD_AUTH_PK_INFO_SIGN "authPkInfoSign" diff --git a/services/legacy/authenticators/src/account_unrelated/pake_task/pake_v1_task/pake_v1_protocol_task/pake_v1_client_protocol_task.c b/services/legacy/authenticators/src/account_unrelated/pake_task/pake_v1_task/pake_v1_protocol_task/pake_v1_client_protocol_task.c index f5046f35..d6a764a8 100644 --- a/services/legacy/authenticators/src/account_unrelated/pake_task/pake_v1_task/pake_v1_protocol_task/pake_v1_client_protocol_task.c +++ b/services/legacy/authenticators/src/account_unrelated/pake_task/pake_v1_task/pake_v1_protocol_task/pake_v1_client_protocol_task.c @@ -225,7 +225,7 @@ static int Process(struct AsyBaseCurTaskT *task, PakeParams *params, const CJson uint32_t step = ProtocolMessageIn(in); if (step == INVALID_MESSAGE) { res = PakeRequest(task, params, out, status); - step = 1; + step = STEP_ONE; goto OUT; } -- Gitee