1 /*
2 * Copyright (C) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ipc_sdk.h"
17
18 #include "common_defs.h"
19 #include "device_auth_defines.h"
20 #include "device_auth.h"
21 #include "hc_log.h"
22 #include "hc_mutex.h"
23
24 #include "ipc_adapt.h"
25 #include "securec.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define IPC_DATA_CACHES_1 1
32 #define IPC_DATA_CACHES_3 3
33 #define IPC_DATA_CACHES_4 4
34 #define REPLAY_CACHE_NUM(caches) (sizeof(caches) / sizeof(IpcDataInfo))
35 #define IPC_APPID_LEN 128
36
37 #define IS_COMM_DATA_VALID(dPtr, dLen) (((dPtr) != NULL) && ((dLen) > 0) && ((dLen) <= 4096))
38
39 static const int32_t IPC_RESULT_NUM_1 = 1;
40 static const int32_t IPC_RESULT_NUM_2 = 2;
41
42 typedef struct {
43 uintptr_t inst;
44 char appId[IPC_APPID_LEN];
45 } IpcProxyCbInfo;
46 static IpcProxyCbInfo g_ipcProxyCbList = { 0 };
47 static IpcProxyCbInfo g_ipcListenerCbList = { 0 };
48 static HcMutex g_ipcMutex;
49
IsStrInvalid(const char * str)50 static bool IsStrInvalid(const char *str)
51 {
52 return (str == NULL || str[0] == 0);
53 }
54
DelIpcCliCallbackCtx(const char * appId,IpcProxyCbInfo * cbCache)55 static void DelIpcCliCallbackCtx(const char *appId, IpcProxyCbInfo *cbCache)
56 {
57 int32_t ret;
58
59 if (cbCache->appId[0] == 0) {
60 return;
61 }
62 g_ipcMutex.lock(&g_ipcMutex);
63 ret = memcmp(appId, cbCache->appId, strlen(cbCache->appId) + 1);
64 if (ret == 0) {
65 cbCache->appId[0] = 0;
66 }
67 g_ipcMutex.unlock(&g_ipcMutex);
68 return;
69 }
70
AddIpcCliCallbackCtx(const char * appId,uintptr_t cbInst,IpcProxyCbInfo * cbCache)71 static void AddIpcCliCallbackCtx(const char *appId, uintptr_t cbInst, IpcProxyCbInfo *cbCache)
72 {
73 errno_t eno;
74
75 LOGI("starting ...");
76 g_ipcMutex.lock(&g_ipcMutex);
77 eno = memcpy_s(cbCache->appId, IPC_APPID_LEN, appId, strlen(appId) + 1);
78 if (eno != EOK) {
79 g_ipcMutex.unlock(&g_ipcMutex);
80 LOGE("memory copy failed");
81 return;
82 }
83 cbCache->inst = cbInst;
84 g_ipcMutex.unlock(&g_ipcMutex);
85 LOGI("success, appid: %s", appId);
86 return;
87 }
88
GetIpcReplyByType(const IpcDataInfo * ipcData,int32_t dataNum,int32_t type,uint8_t * outCache,int32_t * cacheLen)89 static void GetIpcReplyByType(const IpcDataInfo *ipcData,
90 int32_t dataNum, int32_t type, uint8_t *outCache, int32_t *cacheLen)
91 {
92 int32_t i;
93 int32_t ret = HC_ERR_IPC_BAD_MSG_TYPE;
94 errno_t eno;
95
96 LOGI("type %d", type);
97 for (i = 0; i < dataNum; i++) {
98 if (ipcData[i].type != type) {
99 continue;
100 }
101 ret = HC_SUCCESS;
102 switch (type) {
103 case PARAM_TYPE_REG_INFO:
104 case PARAM_TYPE_MGR_APPID:
105 case PARAM_TYPE_FRIEND_APPID:
106 case PARAM_TYPE_DEVICE_INFO:
107 case PARAM_TYPE_GROUP_INFO:
108 case PARAM_TYPE_RETURN_DATA:
109 *(uint8_t **)outCache = ipcData[i].val;
110 break;
111 case PARAM_TYPE_IPC_RESULT:
112 case PARAM_TYPE_IPC_RESULT_NUM:
113 case PARAM_TYPE_COMM_DATA:
114 case PARAM_TYPE_DATA_NUM:
115 eno = memcpy_s(outCache, *cacheLen, ipcData[i].val, ipcData[i].valSz);
116 if (eno != EOK) {
117 ret = HC_ERR_MEMORY_COPY;
118 break;
119 }
120 *cacheLen = ipcData[i].valSz;
121 break;
122 default:
123 ret = HC_ERR_IPC_BAD_MSG_TYPE;
124 LOGE("un-expectation type case");
125 break;
126 }
127 }
128 LOGI("process done, type %d, result %d", type, ret);
129 return;
130 }
131
IpcGmRegCallback(const char * appId,const DeviceAuthCallback * callback)132 static int32_t IpcGmRegCallback(const char *appId, const DeviceAuthCallback *callback)
133 {
134 uintptr_t callCtx = 0x0;
135 int32_t ret;
136
137 LOGI("starting ...");
138 if (IsStrInvalid(appId) || callback == NULL) {
139 LOGE("invalid params");
140 return HC_ERR_INVALID_PARAMS;
141 }
142 ret = CreateCallCtx(&callCtx, NULL);
143 if (ret != HC_SUCCESS) {
144 LOGE("CreateCallCtx failed, ret %d", ret);
145 return HC_ERR_IPC_INIT;
146 }
147
148 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
149 if (ret != HC_SUCCESS) {
150 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_APPID);
151 DestroyCallCtx(&callCtx, NULL);
152 return HC_ERR_IPC_BUILD_PARAM;
153 }
154 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback));
155 if (ret != HC_SUCCESS) {
156 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB);
157 DestroyCallCtx(&callCtx, NULL);
158 return HC_ERR_IPC_BUILD_PARAM;
159 }
160 SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID);
161 ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_CB, true);
162 if (ret == HC_SUCCESS) {
163 AddIpcCliCallbackCtx(appId, 0, &g_ipcProxyCbList);
164 }
165 DestroyCallCtx(&callCtx, NULL);
166 LOGI("process done, ret %d", ret);
167 return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED;
168 }
169
IpcGmUnRegCallback(const char * appId)170 static int32_t IpcGmUnRegCallback(const char *appId)
171 {
172 uintptr_t callCtx = 0x0;
173 int32_t ret;
174
175 LOGI("starting ...");
176 if (IsStrInvalid(appId)) {
177 LOGE("invalid params");
178 return HC_ERR_INVALID_PARAMS;
179 }
180 ret = CreateCallCtx(&callCtx, NULL);
181 if (ret != HC_SUCCESS) {
182 LOGE("CreateCallCtx failed, ret %d", ret);
183 return HC_ERR_IPC_INIT;
184 }
185
186 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
187 if (ret != HC_SUCCESS) {
188 LOGE("set request param failed, ret %d", ret);
189 DestroyCallCtx(&callCtx, NULL);
190 return HC_ERR_IPC_BUILD_PARAM;
191 }
192 ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_CB, true);
193 if (ret == HC_SUCCESS) {
194 DelIpcCliCallbackCtx(appId, &g_ipcProxyCbList);
195 }
196 DestroyCallCtx(&callCtx, NULL);
197 LOGI("process done, ret %d", HC_SUCCESS);
198 return HC_SUCCESS;
199 }
200
IpcGmRegDataChangeListener(const char * appId,const DataChangeListener * listener)201 static int32_t IpcGmRegDataChangeListener(const char *appId, const DataChangeListener *listener)
202 {
203 uintptr_t callCtx = 0x0;
204 int32_t ret;
205
206 LOGI("starting ...");
207 if (IsStrInvalid(appId) || (listener == NULL)) {
208 LOGE("invalid params");
209 return HC_ERR_INVALID_PARAMS;
210 }
211 ret = CreateCallCtx(&callCtx, NULL);
212 if (ret != HC_SUCCESS) {
213 LOGE("CreateCallCtx failed, ret %d", ret);
214 return HC_ERR_IPC_INIT;
215 }
216
217 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
218 if (ret != HC_SUCCESS) {
219 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_APPID);
220 DestroyCallCtx(&callCtx, NULL);
221 return HC_ERR_IPC_BUILD_PARAM;
222 }
223 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_LISTERNER, (const uint8_t *)listener, sizeof(*listener));
224 if (ret != HC_SUCCESS) {
225 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_LISTERNER);
226 DestroyCallCtx(&callCtx, NULL);
227 return HC_ERR_IPC_BUILD_PARAM;
228 }
229 SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_BIND_ID);
230 ret = DoBinderCall(callCtx, IPC_CALL_ID_REG_LISTENER, true);
231 if (ret == HC_SUCCESS) {
232 AddIpcCliCallbackCtx(appId, 0, &g_ipcListenerCbList);
233 }
234 DestroyCallCtx(&callCtx, NULL);
235 LOGI("process done, ret %d", ret);
236 return (ret == HC_SUCCESS) ? HC_SUCCESS : HC_ERR_IPC_PROC_FAILED;
237 }
238
IpcGmUnRegDataChangeListener(const char * appId)239 static int32_t IpcGmUnRegDataChangeListener(const char *appId)
240 {
241 uintptr_t callCtx = 0x0;
242 int32_t ret;
243
244 LOGI("starting ...");
245 if (IsStrInvalid(appId)) {
246 LOGE("invalid params");
247 return HC_ERR_INVALID_PARAMS;
248 }
249 ret = CreateCallCtx(&callCtx, NULL);
250 if (ret != HC_SUCCESS) {
251 LOGE("CreateCallCtx failed, ret %d", ret);
252 return HC_ERR_IPC_INIT;
253 }
254
255 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
256 if (ret != HC_SUCCESS) {
257 LOGE("set request param failed, ret %d", ret);
258 DestroyCallCtx(&callCtx, NULL);
259 return HC_ERR_IPC_BUILD_PARAM;
260 }
261 ret = DoBinderCall(callCtx, IPC_CALL_ID_UNREG_LISTENER, true);
262 if (ret == HC_SUCCESS) {
263 DelIpcCliCallbackCtx(appId, &g_ipcListenerCbList);
264 }
265 DestroyCallCtx(&callCtx, NULL);
266 LOGI("process done");
267 return HC_SUCCESS;
268 }
269
EncodeCreateGroupParams(uintptr_t callCtx,int32_t osAccountId,int64_t requestId,const char * appId,const char * createParams)270 static int32_t EncodeCreateGroupParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId,
271 const char *appId, const char *createParams)
272 {
273 int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
274 sizeof(osAccountId));
275 if (ret != HC_SUCCESS) {
276 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
277 return HC_ERR_IPC_BUILD_PARAM;
278 }
279 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
280 if (ret != HC_SUCCESS) {
281 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
282 return HC_ERR_IPC_BUILD_PARAM;
283 }
284 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
285 if (ret != HC_SUCCESS) {
286 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
287 return HC_ERR_IPC_BUILD_PARAM;
288 }
289 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_CREATE_PARAMS,
290 (const uint8_t *)createParams, strlen(createParams) + 1);
291 if (ret != HC_SUCCESS) {
292 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_CREATE_PARAMS);
293 return HC_ERR_IPC_BUILD_PARAM;
294 }
295 return HC_SUCCESS;
296 }
297
IpcGmCreateGroup(int32_t osAccountId,int64_t requestId,const char * appId,const char * createParams)298 static int32_t IpcGmCreateGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams)
299 {
300 uintptr_t callCtx = 0x0;
301 int32_t ret;
302 int32_t inOutLen;
303 IpcDataInfo replyCache = { 0 };
304
305 LOGI("starting ...");
306 if (IsStrInvalid(createParams) || IsStrInvalid(appId)) {
307 LOGE("invalid params");
308 return HC_ERR_INVALID_PARAMS;
309 }
310 ret = CreateCallCtx(&callCtx, NULL);
311 if (ret != HC_SUCCESS) {
312 LOGE("CreateCallCtx failed, ret %d", ret);
313 return HC_ERR_IPC_INIT;
314 }
315 ret = EncodeCreateGroupParams(callCtx, osAccountId, requestId, appId, createParams);
316 if (ret != HC_SUCCESS) {
317 DestroyCallCtx(&callCtx, NULL);
318 return ret;
319 }
320 ret = DoBinderCall(callCtx, IPC_CALL_ID_CREATE_GROUP, true);
321 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
322 LOGE("ipc call failed");
323 DestroyCallCtx(&callCtx, NULL);
324 return HC_ERR_IPC_PROC_FAILED;
325 }
326 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
327 ret = HC_ERR_IPC_UNKNOW_REPLY;
328 inOutLen = sizeof(int32_t);
329 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
330 DestroyCallCtx(&callCtx, NULL);
331 LOGI("process done, ret %d", ret);
332 return ret;
333 }
334
EncodeDeleteGroupParams(uintptr_t callCtx,int32_t osAccountId,int64_t requestId,const char * appId,const char * delParams)335 static int32_t EncodeDeleteGroupParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId,
336 const char *appId, const char *delParams)
337 {
338 int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
339 sizeof(osAccountId));
340 if (ret != HC_SUCCESS) {
341 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
342 return HC_ERR_IPC_BUILD_PARAM;
343 }
344 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
345 if (ret != HC_SUCCESS) {
346 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
347 return HC_ERR_IPC_BUILD_PARAM;
348 }
349 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, strlen(delParams) + 1);
350 if (ret != HC_SUCCESS) {
351 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS);
352 return HC_ERR_IPC_BUILD_PARAM;
353 }
354 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
355 if (ret != HC_SUCCESS) {
356 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
357 return HC_ERR_IPC_BUILD_PARAM;
358 }
359 return HC_SUCCESS;
360 }
361
IpcGmDeleteGroup(int32_t osAccountId,int64_t requestId,const char * appId,const char * delParams)362 static int32_t IpcGmDeleteGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams)
363 {
364 uintptr_t callCtx = 0x0;
365 int32_t ret;
366 int32_t inOutLen;
367 IpcDataInfo replyCache = { 0 };
368
369 LOGI("starting ...");
370 if (IsStrInvalid(delParams) || IsStrInvalid(appId)) {
371 LOGE("invalid params");
372 return HC_ERR_INVALID_PARAMS;
373 }
374 ret = CreateCallCtx(&callCtx, NULL);
375 if (ret != HC_SUCCESS) {
376 LOGE("CreateCallCtx failed, ret %d", ret);
377 return HC_ERR_IPC_INIT;
378 }
379 ret = EncodeDeleteGroupParams(callCtx, osAccountId, requestId, appId, delParams);
380 if (ret != HC_SUCCESS) {
381 DestroyCallCtx(&callCtx, NULL);
382 return ret;
383 }
384 ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP, true);
385 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
386 LOGE("ipc call failed");
387 DestroyCallCtx(&callCtx, NULL);
388 return HC_ERR_IPC_PROC_FAILED;
389 }
390 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
391 ret = HC_ERR_IPC_UNKNOW_REPLY;
392 inOutLen = sizeof(int32_t);
393 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
394 DestroyCallCtx(&callCtx, NULL);
395 LOGI("process done, ret %d", ret);
396 return ret;
397 }
398
EncodeAddMemberParams(uintptr_t callCtx,int32_t osAccountId,int64_t requestId,const char * appId,const char * addParams)399 static int32_t EncodeAddMemberParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId,
400 const char *appId, const char *addParams)
401 {
402 int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
403 sizeof(osAccountId));
404 if (ret != HC_SUCCESS) {
405 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
406 return HC_ERR_IPC_BUILD_PARAM;
407 }
408 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
409 if (ret != HC_SUCCESS) {
410 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
411 return HC_ERR_IPC_BUILD_PARAM;
412 }
413 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
414 if (ret != HC_SUCCESS) {
415 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
416 return HC_ERR_IPC_BUILD_PARAM;
417 }
418 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, strlen(addParams) + 1);
419 if (ret != HC_SUCCESS) {
420 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_ADD_PARAMS);
421 return HC_ERR_IPC_BUILD_PARAM;
422 }
423 return HC_SUCCESS;
424 }
425
IpcGmAddMemberToGroup(int32_t osAccountId,int64_t requestId,const char * appId,const char * addParams)426 static int32_t IpcGmAddMemberToGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *addParams)
427 {
428 uintptr_t callCtx = 0x0;
429 int32_t ret;
430 int32_t inOutLen;
431 IpcDataInfo replyCache = { 0 };
432
433 LOGI("starting ...");
434 if (IsStrInvalid(appId) || IsStrInvalid(addParams)) {
435 LOGE("invalid params");
436 return HC_ERR_INVALID_PARAMS;
437 }
438 ret = CreateCallCtx(&callCtx, NULL);
439 if (ret != HC_SUCCESS) {
440 LOGE("CreateCallCtx failed, ret %d", ret);
441 return HC_ERR_IPC_INIT;
442 }
443 ret = EncodeAddMemberParams(callCtx, osAccountId, requestId, appId, addParams);
444 if (ret != HC_SUCCESS) {
445 DestroyCallCtx(&callCtx, NULL);
446 return ret;
447 }
448 ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_GROUP_MEMBER, true);
449 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
450 LOGE("ipc call failed");
451 DestroyCallCtx(&callCtx, NULL);
452 return HC_ERR_IPC_PROC_FAILED;
453 }
454 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
455 ret = HC_ERR_IPC_UNKNOW_REPLY;
456 inOutLen = sizeof(int32_t);
457 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
458 DestroyCallCtx(&callCtx, NULL);
459 LOGI("process done, ret %d", ret);
460 return ret;
461 }
462
EncodeDeleteMemberParams(uintptr_t callCtx,int32_t osAccountId,int64_t requestId,const char * appId,const char * delParams)463 static int32_t EncodeDeleteMemberParams(uintptr_t callCtx, int32_t osAccountId, int64_t requestId,
464 const char *appId, const char *delParams)
465 {
466 int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
467 sizeof(osAccountId));
468 if (ret != HC_SUCCESS) {
469 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
470 return HC_ERR_IPC_BUILD_PARAM;
471 }
472 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
473 if (ret != HC_SUCCESS) {
474 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
475 return HC_ERR_IPC_BUILD_PARAM;
476 }
477 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
478 if (ret != HC_SUCCESS) {
479 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
480 return HC_ERR_IPC_BUILD_PARAM;
481 }
482 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, strlen(delParams) + 1);
483 if (ret != HC_SUCCESS) {
484 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS);
485 return HC_ERR_IPC_BUILD_PARAM;
486 }
487 return HC_SUCCESS;
488 }
489
IpcGmDelMemberFromGroup(int32_t osAccountId,int64_t requestId,const char * appId,const char * delParams)490 static int32_t IpcGmDelMemberFromGroup(int32_t osAccountId, int64_t requestId, const char *appId, const char *delParams)
491 {
492 uintptr_t callCtx = 0x0;
493 int32_t ret;
494 int32_t inOutLen;
495 IpcDataInfo replyCache = { 0 };
496
497 LOGI("starting ...");
498 if (IsStrInvalid(appId) || IsStrInvalid(delParams)) {
499 LOGE("invalid params");
500 return HC_ERR_INVALID_PARAMS;
501 }
502 ret = CreateCallCtx(&callCtx, NULL);
503 if (ret != HC_SUCCESS) {
504 LOGE("CreateCallCtx failed, ret %d", ret);
505 return HC_ERR_IPC_INIT;
506 }
507 ret = EncodeDeleteMemberParams(callCtx, osAccountId, requestId, appId, delParams);
508 if (ret != HC_SUCCESS) {
509 DestroyCallCtx(&callCtx, NULL);
510 return ret;
511 }
512 ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_GROUP_MEMBER, true);
513 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
514 LOGE("ipc call failed");
515 DestroyCallCtx(&callCtx, NULL);
516 return HC_ERR_IPC_PROC_FAILED;
517 }
518 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
519 ret = HC_ERR_IPC_UNKNOW_REPLY;
520 inOutLen = sizeof(int32_t);
521 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
522 DestroyCallCtx(&callCtx, NULL);
523 LOGI("process done, ret %d", ret);
524 return ret;
525 }
526
IpcGmAddMultiMembersToGroup(int32_t osAccountId,const char * appId,const char * addParams)527 static int32_t IpcGmAddMultiMembersToGroup(int32_t osAccountId, const char *appId, const char *addParams)
528 {
529 LOGI("starting ...");
530 if (IsStrInvalid(appId) || IsStrInvalid(addParams)) {
531 LOGE("Invalid params");
532 return HC_ERR_INVALID_PARAMS;
533 }
534 uintptr_t callCtx = 0x0;
535 int32_t ret = CreateCallCtx(&callCtx, NULL);
536 if (ret != HC_SUCCESS) {
537 LOGE("CreateCallCtx failed, ret %d", ret);
538 return HC_ERR_IPC_INIT;
539 }
540 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
541 sizeof(osAccountId));
542 if (ret != HC_SUCCESS) {
543 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
544 DestroyCallCtx(&callCtx, NULL);
545 return HC_ERR_IPC_BUILD_PARAM;
546 }
547 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
548 if (ret != HC_SUCCESS) {
549 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
550 DestroyCallCtx(&callCtx, NULL);
551 return HC_ERR_IPC_BUILD_PARAM;
552 }
553 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_ADD_PARAMS, (const uint8_t *)addParams, strlen(addParams) + 1);
554 if (ret != HC_SUCCESS) {
555 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_ADD_PARAMS);
556 DestroyCallCtx(&callCtx, NULL);
557 return HC_ERR_IPC_BUILD_PARAM;
558 }
559 ret = DoBinderCall(callCtx, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS, true);
560 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
561 LOGE("ipc call failed");
562 DestroyCallCtx(&callCtx, NULL);
563 return HC_ERR_IPC_PROC_FAILED;
564 }
565 IpcDataInfo replyCache = { 0 };
566 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
567 ret = HC_ERR_IPC_UNKNOW_REPLY;
568 int32_t inOutLen = sizeof(int32_t);
569 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
570 DestroyCallCtx(&callCtx, NULL);
571 LOGI("process done, ret %d", ret);
572 return ret;
573 }
574
IpcGmDelMultiMembersFromGroup(int32_t osAccountId,const char * appId,const char * delParams)575 static int32_t IpcGmDelMultiMembersFromGroup(int32_t osAccountId, const char *appId, const char *delParams)
576 {
577 LOGI("starting ...");
578 if (IsStrInvalid(appId) || IsStrInvalid(delParams)) {
579 LOGE("Invalid params");
580 return HC_ERR_INVALID_PARAMS;
581 }
582 uintptr_t callCtx = 0x0;
583 int32_t ret = CreateCallCtx(&callCtx, NULL);
584 if (ret != HC_SUCCESS) {
585 LOGE("CreateCallCtx failed, ret %d", ret);
586 return HC_ERR_IPC_INIT;
587 }
588 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
589 sizeof(osAccountId));
590 if (ret != HC_SUCCESS) {
591 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
592 DestroyCallCtx(&callCtx, NULL);
593 return HC_ERR_IPC_BUILD_PARAM;
594 }
595 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
596 if (ret != HC_SUCCESS) {
597 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
598 DestroyCallCtx(&callCtx, NULL);
599 return HC_ERR_IPC_BUILD_PARAM;
600 }
601 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEL_PARAMS, (const uint8_t *)delParams, strlen(delParams) + 1);
602 if (ret != HC_SUCCESS) {
603 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_DEL_PARAMS);
604 DestroyCallCtx(&callCtx, NULL);
605 return HC_ERR_IPC_BUILD_PARAM;
606 }
607 ret = DoBinderCall(callCtx, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS, true);
608 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
609 LOGE("ipc call failed");
610 DestroyCallCtx(&callCtx, NULL);
611 return HC_ERR_IPC_PROC_FAILED;
612 }
613 IpcDataInfo replyCache = { 0 };
614 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
615 ret = HC_ERR_IPC_UNKNOW_REPLY;
616 int32_t inOutLen = sizeof(int32_t);
617 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
618 DestroyCallCtx(&callCtx, NULL);
619 LOGI("process done, ret %d", ret);
620 return ret;
621 }
622
IpcGmProcessData(int64_t requestId,const uint8_t * data,uint32_t dataLen)623 static int32_t IpcGmProcessData(int64_t requestId, const uint8_t *data, uint32_t dataLen)
624 {
625 uintptr_t callCtx = 0x0;
626 int32_t ret;
627 int32_t inOutLen;
628 IpcDataInfo replyCache = { 0 };
629
630 LOGI("starting ...");
631 if (!IS_COMM_DATA_VALID(data, dataLen)) {
632 LOGE("invalid params");
633 return HC_ERR_INVALID_PARAMS;
634 }
635 ret = CreateCallCtx(&callCtx, NULL);
636 if (ret != HC_SUCCESS) {
637 LOGE("CreateCallCtx failed, ret %d", ret);
638 return HC_ERR_IPC_INIT;
639 }
640 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)&requestId, sizeof(requestId));
641 if (ret != HC_SUCCESS) {
642 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQID);
643 DestroyCallCtx(&callCtx, NULL);
644 return HC_ERR_IPC_BUILD_PARAM;
645 }
646 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, data, dataLen);
647 if (ret != HC_SUCCESS) {
648 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_COMM_DATA);
649 DestroyCallCtx(&callCtx, NULL);
650 return HC_ERR_IPC_BUILD_PARAM;
651 }
652 ret = DoBinderCall(callCtx, IPC_CALL_ID_GM_PROC_DATA, true);
653 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
654 LOGE("ipc call failed");
655 DestroyCallCtx(&callCtx, NULL);
656 return HC_ERR_IPC_PROC_FAILED;
657 }
658 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
659 ret = HC_ERR_IPC_UNKNOW_REPLY;
660 inOutLen = sizeof(int32_t);
661 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
662 DestroyCallCtx(&callCtx, NULL);
663 LOGI("process done, ret %d", ret);
664 return ret;
665 }
666
IpcGmGetRegisterInfo(const char * reqJsonStr,char ** registerInfo)667 static int32_t IpcGmGetRegisterInfo(const char *reqJsonStr, char **registerInfo)
668 {
669 uintptr_t callCtx = 0x0;
670 int32_t ret;
671 int32_t inOutLen;
672 IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } };
673 char *outInfo = NULL;
674
675 LOGI("starting ...");
676 if (IsStrInvalid(reqJsonStr) || (registerInfo == NULL)) {
677 LOGE("Invalid params.");
678 return HC_ERR_INVALID_PARAMS;
679 }
680 ret = CreateCallCtx(&callCtx, NULL);
681 if (ret != HC_SUCCESS) {
682 LOGE("CreateCallCtx failed, ret %d", ret);
683 return HC_ERR_IPC_INIT;
684 }
685 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQ_JSON, (const uint8_t *)reqJsonStr, strlen(reqJsonStr) + 1);
686 if (ret != HC_SUCCESS) {
687 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_REQ_JSON);
688 DestroyCallCtx(&callCtx, NULL);
689 return HC_ERR_IPC_BUILD_PARAM;
690 }
691 ret = DoBinderCall(callCtx, IPC_CALL_ID_APPLY_REG_INFO, true);
692 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
693 LOGE("ipc call failed");
694 DestroyCallCtx(&callCtx, NULL);
695 return HC_ERR_IPC_PROC_FAILED;
696 }
697 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
698 ret = HC_ERR_IPC_UNKNOW_REPLY;
699 inOutLen = sizeof(int32_t);
700 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
701 LOGI("process done, ret %d", ret);
702 if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
703 DestroyCallCtx(&callCtx, NULL);
704 return HC_ERR_IPC_BAD_PARAM;
705 }
706 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
707 if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) {
708 LOGE("done, ret %d", HC_ERR_IPC_OUT_DATA_NUM);
709 DestroyCallCtx(&callCtx, NULL);
710 return HC_ERR_IPC_OUT_DATA_NUM;
711 }
712 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_REG_INFO, (uint8_t *)&outInfo, NULL);
713 if ((outInfo == NULL) || (strlen(outInfo) == 0)) {
714 LOGE("done, ret %d", HC_ERR_IPC_OUT_DATA);
715 DestroyCallCtx(&callCtx, NULL);
716 return HC_ERR_IPC_OUT_DATA;
717 }
718 *registerInfo = strdup(outInfo);
719 DestroyCallCtx(&callCtx, NULL);
720 return (*registerInfo != NULL) ? HC_SUCCESS : HC_ERR_NULL_PTR;
721 }
722
IpcGmCheckAccessToGroup(int32_t osAccountId,const char * appId,const char * groupId)723 static int32_t IpcGmCheckAccessToGroup(int32_t osAccountId, const char *appId, const char *groupId)
724 {
725 uintptr_t callCtx = 0x0;
726 int32_t ret;
727 int32_t inOutLen;
728 IpcDataInfo replyCache = { 0 };
729
730 LOGI("starting ...");
731 if (IsStrInvalid(appId) || IsStrInvalid(groupId)) {
732 LOGE("Invalid params.");
733 return HC_ERR_INVALID_PARAMS;
734 }
735 ret = CreateCallCtx(&callCtx, NULL);
736 if (ret != HC_SUCCESS) {
737 LOGE("CreateCallCtx failed, ret %d", ret);
738 return HC_ERR_IPC_INIT;
739 }
740 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
741 sizeof(osAccountId));
742 if (ret != HC_SUCCESS) {
743 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
744 DestroyCallCtx(&callCtx, NULL);
745 return HC_ERR_IPC_BUILD_PARAM;
746 }
747 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
748 if (ret != HC_SUCCESS) {
749 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
750 DestroyCallCtx(&callCtx, NULL);
751 return HC_ERR_IPC_BUILD_PARAM;
752 }
753 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
754 if (ret != HC_SUCCESS) {
755 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
756 DestroyCallCtx(&callCtx, NULL);
757 return HC_ERR_IPC_BUILD_PARAM;
758 }
759 ret = DoBinderCall(callCtx, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP, true);
760 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
761 LOGE("ipc call failed");
762 DestroyCallCtx(&callCtx, NULL);
763 return HC_ERR_IPC_PROC_FAILED;
764 }
765 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
766 ret = HC_ERR_IPC_UNKNOW_REPLY;
767 inOutLen = sizeof(int32_t);
768 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
769 LOGI("process done, ret %d", ret);
770 DestroyCallCtx(&callCtx, NULL);
771 return ret;
772 }
773
ParseReturnResult(const IpcDataInfo * replies,int32_t cacheNum,char ** returnData,uint32_t * returnNum)774 static int32_t ParseReturnResult(const IpcDataInfo *replies, int32_t cacheNum, char **returnData, uint32_t *returnNum)
775 {
776 int32_t ret;
777 int32_t inOutLen;
778
779 inOutLen = sizeof(int32_t);
780 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
781 if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
782 return HC_ERR_IPC_OUT_DATA_NUM;
783 }
784 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)returnData, NULL);
785 if (*returnData == NULL) {
786 return HC_ERR_IPC_OUT_DATA;
787 }
788 *returnData = strdup(*returnData);
789 if (*returnData == NULL) {
790 return HC_ERR_ALLOC_MEMORY;
791 }
792 inOutLen = sizeof(int32_t);
793 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)returnNum, &inOutLen);
794 return HC_SUCCESS;
795 }
796
IpcGmGetPkInfoList(int32_t osAccountId,const char * appId,const char * queryParams,char ** returnInfoList,uint32_t * returnInfoNum)797 static int32_t IpcGmGetPkInfoList(int32_t osAccountId, const char *appId, const char *queryParams,
798 char **returnInfoList, uint32_t *returnInfoNum)
799 {
800 uintptr_t callCtx = 0x0;
801 int32_t ret;
802 int32_t inOutLen;
803 IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } };
804
805 LOGI("starting ...");
806 if (IsStrInvalid(appId) || IsStrInvalid(queryParams) ||
807 (returnInfoList == NULL) || (returnInfoNum == NULL)) {
808 LOGE("Invalid params.");
809 return HC_ERR_INVALID_PARAMS;
810 }
811 ret = CreateCallCtx(&callCtx, NULL);
812 if (ret != HC_SUCCESS) {
813 LOGE("CreateCallCtx failed, ret %d", ret);
814 return HC_ERR_IPC_INIT;
815 }
816 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
817 sizeof(osAccountId));
818 if (ret != HC_SUCCESS) {
819 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
820 DestroyCallCtx(&callCtx, NULL);
821 return HC_ERR_IPC_BUILD_PARAM;
822 }
823 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
824 if (ret != HC_SUCCESS) {
825 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
826 DestroyCallCtx(&callCtx, NULL);
827 return HC_ERR_IPC_BUILD_PARAM;
828 }
829 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS,
830 (const uint8_t *)queryParams, strlen(queryParams) + 1);
831 if (ret != HC_SUCCESS) {
832 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_QUERY_PARAMS);
833 DestroyCallCtx(&callCtx, NULL);
834 return HC_ERR_IPC_BUILD_PARAM;
835 }
836 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PK_INFO_LIST, true);
837 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
838 LOGE("ipc call failed");
839 DestroyCallCtx(&callCtx, NULL);
840 return HC_ERR_IPC_PROC_FAILED;
841 }
842 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
843 ret = HC_ERR_IPC_UNKNOW_REPLY;
844 inOutLen = sizeof(int32_t);
845 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
846 LOGI("process done, ret %d", ret);
847 if (ret != HC_SUCCESS) {
848 DestroyCallCtx(&callCtx, NULL);
849 return ret;
850 }
851 ret = ParseReturnResult(replyCache, REPLAY_CACHE_NUM(replyCache), returnInfoList, returnInfoNum);
852 LOGI("proc result done, ret %d", ret);
853 DestroyCallCtx(&callCtx, NULL);
854 return ret;
855 }
856
GroupInfoIpcResult(const IpcDataInfo * replies,int32_t cacheNum,char ** outGroupInfo)857 static int32_t GroupInfoIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outGroupInfo)
858 {
859 int32_t inOutLen;
860 int32_t ret;
861
862 inOutLen = sizeof(int32_t);
863 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
864 if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) {
865 return HC_ERR_IPC_OUT_DATA_NUM;
866 }
867 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupInfo, NULL);
868 if (*outGroupInfo == NULL) {
869 return HC_ERR_IPC_OUT_DATA;
870 }
871 *outGroupInfo = strdup(*outGroupInfo);
872 if (*outGroupInfo == NULL) {
873 return HC_ERR_ALLOC_MEMORY;
874 }
875 return HC_SUCCESS;
876 }
877
IpcGmGetGroupInfoById(int32_t osAccountId,const char * appId,const char * groupId,char ** outGroupInfo)878 static int32_t IpcGmGetGroupInfoById(int32_t osAccountId, const char *appId, const char *groupId, char **outGroupInfo)
879 {
880 uintptr_t callCtx = 0x0;
881 int32_t ret;
882 int32_t inOutLen;
883 IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } };
884
885 LOGI("starting ...");
886 if (IsStrInvalid(groupId) || IsStrInvalid(appId) || (outGroupInfo == NULL)) {
887 LOGE("Invalid params.");
888 return HC_ERR_INVALID_PARAMS;
889 }
890 ret = CreateCallCtx(&callCtx, NULL);
891 if (ret != HC_SUCCESS) {
892 LOGE("CreateCallCtx failed, ret %d", ret);
893 return HC_ERR_IPC_INIT;
894 }
895 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
896 sizeof(osAccountId));
897 if (ret != HC_SUCCESS) {
898 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
899 DestroyCallCtx(&callCtx, NULL);
900 return HC_ERR_IPC_BUILD_PARAM;
901 }
902 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
903 if (ret != HC_SUCCESS) {
904 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
905 DestroyCallCtx(&callCtx, NULL);
906 return HC_ERR_IPC_BUILD_PARAM;
907 }
908 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
909 if (ret != HC_SUCCESS) {
910 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
911 DestroyCallCtx(&callCtx, NULL);
912 return HC_ERR_IPC_BUILD_PARAM;
913 }
914 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_GROUP_INFO, true);
915 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
916 LOGE("ipc call failed");
917 DestroyCallCtx(&callCtx, NULL);
918 return HC_ERR_IPC_PROC_FAILED;
919 }
920 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
921 ret = HC_ERR_IPC_UNKNOW_REPLY;
922 inOutLen = sizeof(int32_t);
923 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
924 LOGI("process done, ret %d", ret);
925 if (ret != HC_SUCCESS) {
926 DestroyCallCtx(&callCtx, NULL);
927 return ret;
928 }
929 ret = GroupInfoIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupInfo);
930 DestroyCallCtx(&callCtx, NULL);
931 LOGI("proc result done, ret %d", ret);
932 return ret;
933 }
934
SearchGroupsIpcResult(const IpcDataInfo * replies,int32_t cacheNum,char ** outGroupVec,uint32_t * groupNum)935 static int32_t SearchGroupsIpcResult(const IpcDataInfo *replies,
936 int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
937 {
938 int32_t ret;
939 int32_t inOutLen;
940
941 inOutLen = sizeof(int32_t);
942 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
943 if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
944 return HC_ERR_IPC_OUT_DATA_NUM;
945 }
946 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL);
947 if (*outGroupVec == NULL) {
948 return HC_ERR_IPC_OUT_DATA;
949 }
950 *outGroupVec = strdup(*outGroupVec);
951 if (*outGroupVec == NULL) {
952 return HC_ERR_ALLOC_MEMORY;
953 }
954 inOutLen = sizeof(int32_t);
955 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen);
956 return HC_SUCCESS;
957 }
958
IpcGmGetGroupInfo(int32_t osAccountId,const char * appId,const char * queryParams,char ** outGroupVec,uint32_t * groupNum)959 static int32_t IpcGmGetGroupInfo(int32_t osAccountId, const char *appId, const char *queryParams,
960 char **outGroupVec, uint32_t *groupNum)
961 {
962 uintptr_t callCtx = 0x0;
963 int32_t ret;
964 int32_t inOutLen;
965 IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } };
966
967 LOGI("starting ...");
968 if (IsStrInvalid(queryParams) || IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL)) {
969 LOGE("Invalid params.");
970 return HC_ERR_INVALID_PARAMS;
971 }
972 ret = CreateCallCtx(&callCtx, NULL);
973 if (ret != HC_SUCCESS) {
974 LOGE("CreateCallCtx failed, ret %d", ret);
975 return HC_ERR_IPC_INIT;
976 }
977 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
978 sizeof(osAccountId));
979 if (ret != HC_SUCCESS) {
980 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
981 DestroyCallCtx(&callCtx, NULL);
982 return HC_ERR_IPC_BUILD_PARAM;
983 }
984 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
985 if (ret != HC_SUCCESS) {
986 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
987 DestroyCallCtx(&callCtx, NULL);
988 return HC_ERR_IPC_BUILD_PARAM;
989 }
990 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_QUERY_PARAMS,
991 (const uint8_t *)queryParams, strlen(queryParams) + 1);
992 if (ret != HC_SUCCESS) {
993 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_QUERY_PARAMS);
994 DestroyCallCtx(&callCtx, NULL);
995 return HC_ERR_IPC_BUILD_PARAM;
996 }
997 ret = DoBinderCall(callCtx, IPC_CALL_ID_SEARCH_GROUPS, true);
998 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
999 LOGE("ipc call failed");
1000 DestroyCallCtx(&callCtx, NULL);
1001 return HC_ERR_IPC_PROC_FAILED;
1002 }
1003 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1004 ret = HC_ERR_IPC_UNKNOW_REPLY;
1005 inOutLen = sizeof(int32_t);
1006 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1007 LOGI("process done, ret %d", ret);
1008 if (ret != HC_SUCCESS) {
1009 DestroyCallCtx(&callCtx, NULL);
1010 return ret;
1011 }
1012 ret = SearchGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum);
1013 LOGI("proc result done, ret %d", ret);
1014 DestroyCallCtx(&callCtx, NULL);
1015 return ret;
1016 }
1017
JoinedGroupsIpcResult(const IpcDataInfo * replies,int32_t cacheNum,char ** outGroupVec,uint32_t * groupNum)1018 static int32_t JoinedGroupsIpcResult(const IpcDataInfo *replies,
1019 int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
1020 {
1021 int32_t ret;
1022 int32_t inOutLen;
1023
1024 inOutLen = sizeof(int32_t);
1025 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
1026 if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
1027 return HC_ERR_IPC_OUT_DATA_NUM;
1028 }
1029 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL);
1030 if (*outGroupVec == NULL) {
1031 return HC_ERR_IPC_OUT_DATA;
1032 }
1033 *outGroupVec = strdup(*outGroupVec);
1034 if (*outGroupVec == NULL) {
1035 return HC_ERR_ALLOC_MEMORY;
1036 }
1037 inOutLen = sizeof(int32_t);
1038 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen);
1039 return HC_SUCCESS;
1040 }
1041
IpcGmGetJoinedGroups(int32_t osAccountId,const char * appId,int32_t groupType,char ** outGroupVec,uint32_t * groupNum)1042 static int32_t IpcGmGetJoinedGroups(int32_t osAccountId, const char *appId, int32_t groupType,
1043 char **outGroupVec, uint32_t *groupNum)
1044 {
1045 uintptr_t callCtx = 0x0;
1046 int32_t ret;
1047 int32_t inOutLen;
1048 IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } };
1049
1050 LOGI("starting ...");
1051 if (IsStrInvalid(appId) || (outGroupVec == NULL) || (groupNum == NULL)) {
1052 LOGE("Invalid params.");
1053 return HC_ERR_INVALID_PARAMS;
1054 }
1055 ret = CreateCallCtx(&callCtx, NULL);
1056 if (ret != HC_SUCCESS) {
1057 LOGE("CreateCallCtx failed, ret %d", ret);
1058 return HC_ERR_IPC_INIT;
1059 }
1060 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1061 sizeof(osAccountId));
1062 if (ret != HC_SUCCESS) {
1063 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1064 DestroyCallCtx(&callCtx, NULL);
1065 return HC_ERR_IPC_BUILD_PARAM;
1066 }
1067 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1068 if (ret != HC_SUCCESS) {
1069 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1070 DestroyCallCtx(&callCtx, NULL);
1071 return HC_ERR_IPC_BUILD_PARAM;
1072 }
1073 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUP_TYPE, (const uint8_t *)&groupType, sizeof(groupType));
1074 if (ret != HC_SUCCESS) {
1075 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUP_TYPE);
1076 DestroyCallCtx(&callCtx, NULL);
1077 return HC_ERR_IPC_BUILD_PARAM;
1078 }
1079 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_JOINED_GROUPS, true);
1080 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1081 LOGE("ipc call failed");
1082 DestroyCallCtx(&callCtx, NULL);
1083 return HC_ERR_IPC_PROC_FAILED;
1084 }
1085 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1086 ret = HC_ERR_IPC_UNKNOW_REPLY;
1087 inOutLen = sizeof(int32_t);
1088 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1089 LOGI("process done, ret %d", ret);
1090 if (ret != HC_SUCCESS) {
1091 DestroyCallCtx(&callCtx, NULL);
1092 return ret;
1093 }
1094 ret = JoinedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum);
1095 LOGI("proc result done, ret %d", ret);
1096 DestroyCallCtx(&callCtx, NULL);
1097 return ret;
1098 }
1099
RelatedGroupsIpcResult(const IpcDataInfo * replies,int32_t cacheNum,char ** outGroupVec,uint32_t * groupNum)1100 static int32_t RelatedGroupsIpcResult(const IpcDataInfo *replies,
1101 int32_t cacheNum, char **outGroupVec, uint32_t *groupNum)
1102 {
1103 int32_t ret;
1104 int32_t inOutLen;
1105
1106 inOutLen = sizeof(int32_t);
1107 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
1108 if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
1109 return HC_ERR_IPC_OUT_DATA_NUM;
1110 }
1111 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_GROUP_INFO, (uint8_t *)outGroupVec, NULL);
1112 if (*outGroupVec == NULL) {
1113 return HC_ERR_IPC_OUT_DATA;
1114 }
1115 *outGroupVec = strdup(*outGroupVec);
1116 if (*outGroupVec == NULL) {
1117 return HC_ERR_ALLOC_MEMORY;
1118 }
1119 inOutLen = sizeof(int32_t);
1120 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)groupNum, &inOutLen);
1121 return HC_SUCCESS;
1122 }
1123
IpcGmGetRelatedGroups(int32_t osAccountId,const char * appId,const char * peerUdid,char ** outGroupVec,uint32_t * groupNum)1124 static int32_t IpcGmGetRelatedGroups(int32_t osAccountId, const char *appId, const char *peerUdid,
1125 char **outGroupVec, uint32_t *groupNum)
1126 {
1127 uintptr_t callCtx = 0x0;
1128 int32_t ret;
1129 int32_t inOutLen;
1130 IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } };
1131
1132 LOGI("starting ...");
1133 if (IsStrInvalid(appId) || IsStrInvalid(peerUdid) || (outGroupVec == NULL) || (groupNum == NULL)) {
1134 LOGE("Invalid params.");
1135 return HC_ERR_INVALID_PARAMS;
1136 }
1137 ret = CreateCallCtx(&callCtx, NULL);
1138 if (ret != HC_SUCCESS) {
1139 LOGE("CreateCallCtx failed, ret %d", ret);
1140 return HC_ERR_IPC_INIT;
1141 }
1142 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1143 sizeof(osAccountId));
1144 if (ret != HC_SUCCESS) {
1145 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1146 DestroyCallCtx(&callCtx, NULL);
1147 return HC_ERR_IPC_BUILD_PARAM;
1148 }
1149 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1150 if (ret != HC_SUCCESS) {
1151 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1152 DestroyCallCtx(&callCtx, NULL);
1153 return HC_ERR_IPC_BUILD_PARAM;
1154 }
1155 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, strlen(peerUdid) + 1);
1156 if (ret != HC_SUCCESS) {
1157 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
1158 DestroyCallCtx(&callCtx, NULL);
1159 return HC_ERR_IPC_BUILD_PARAM;
1160 }
1161 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_RELATED_GROUPS, true);
1162 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1163 LOGE("ipc call failed");
1164 DestroyCallCtx(&callCtx, NULL);
1165 return HC_ERR_IPC_PROC_FAILED;
1166 }
1167 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1168 ret = HC_ERR_IPC_UNKNOW_REPLY;
1169 inOutLen = sizeof(int32_t);
1170 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1171 LOGI("process done, ret %d", ret);
1172 if (ret != HC_SUCCESS) {
1173 DestroyCallCtx(&callCtx, NULL);
1174 return ret;
1175 }
1176 ret = RelatedGroupsIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outGroupVec, groupNum);
1177 LOGI("proc result done, ret %d", ret);
1178 DestroyCallCtx(&callCtx, NULL);
1179 return ret;
1180 }
1181
DevInfoByIdIpcResult(const IpcDataInfo * replies,int32_t cacheNum,char ** outDevInfo)1182 static int32_t DevInfoByIdIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfo)
1183 {
1184 int32_t ret;
1185 int32_t inOutLen;
1186
1187 inOutLen = sizeof(int32_t);
1188 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
1189 if ((ret < IPC_RESULT_NUM_1) || (inOutLen != sizeof(int32_t))) {
1190 return HC_ERR_IPC_OUT_DATA_NUM;
1191 }
1192 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfo, NULL);
1193 if (*outDevInfo == NULL) {
1194 return HC_ERR_IPC_OUT_DATA;
1195 }
1196 *outDevInfo = strdup(*outDevInfo);
1197 if (*outDevInfo == NULL) {
1198 return HC_ERR_ALLOC_MEMORY;
1199 }
1200 return HC_SUCCESS;
1201 }
1202
FormParamsForGettingDeviceInfo(int32_t osAccountId,const char * appId,const char * peerUdid,const char * groupId,uintptr_t callCtx)1203 static int32_t FormParamsForGettingDeviceInfo(int32_t osAccountId, const char *appId,
1204 const char *peerUdid, const char *groupId, uintptr_t callCtx)
1205 {
1206 int32_t ret;
1207 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1208 sizeof(osAccountId));
1209 if (ret != HC_SUCCESS) {
1210 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1211 DestroyCallCtx(&callCtx, NULL);
1212 return HC_ERR_IPC_BUILD_PARAM;
1213 }
1214 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1215 if (ret != HC_SUCCESS) {
1216 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1217 return HC_ERR_IPC_BUILD_PARAM;
1218 }
1219 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)peerUdid, strlen(peerUdid) + 1);
1220 if (ret != HC_SUCCESS) {
1221 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
1222 return HC_ERR_IPC_BUILD_PARAM;
1223 }
1224 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
1225 if (ret != HC_SUCCESS) {
1226 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
1227 return HC_ERR_IPC_BUILD_PARAM;
1228 }
1229 return HC_SUCCESS;
1230 }
1231
IpcGmGetDeviceInfoById(int32_t osAccountId,const char * appId,const char * peerUdid,const char * groupId,char ** outDevInfo)1232 static int32_t IpcGmGetDeviceInfoById(int32_t osAccountId, const char *appId, const char *peerUdid, const char *groupId,
1233 char **outDevInfo)
1234 {
1235 uintptr_t callCtx = 0x0;
1236 int32_t ret;
1237 int32_t inOutLen;
1238 IpcDataInfo replyCache[IPC_DATA_CACHES_3] = { { 0 } };
1239
1240 LOGI("starting ...");
1241 if (IsStrInvalid(appId) || IsStrInvalid(peerUdid) || IsStrInvalid(groupId) || (outDevInfo == NULL)) {
1242 LOGE("Invalid params.");
1243 return HC_ERR_INVALID_PARAMS;
1244 }
1245 ret = CreateCallCtx(&callCtx, NULL);
1246 if (ret != HC_SUCCESS) {
1247 LOGE("CreateCallCtx failed, ret %d", ret);
1248 return HC_ERR_IPC_INIT;
1249 }
1250 ret = FormParamsForGettingDeviceInfo(osAccountId, appId, peerUdid, groupId, callCtx);
1251 if (ret != HC_SUCCESS) {
1252 DestroyCallCtx(&callCtx, NULL);
1253 return ret;
1254 }
1255 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_DEV_INFO_BY_ID, true);
1256 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1257 LOGE("ipc call failed");
1258 DestroyCallCtx(&callCtx, NULL);
1259 return HC_ERR_IPC_PROC_FAILED;
1260 }
1261 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1262 ret = HC_ERR_IPC_UNKNOW_REPLY;
1263 inOutLen = sizeof(int32_t);
1264 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1265 LOGI("process done, ret %d", ret);
1266 if (ret != HC_SUCCESS) {
1267 DestroyCallCtx(&callCtx, NULL);
1268 return ret;
1269 }
1270 ret = DevInfoByIdIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfo);
1271 LOGI("proc result done, ret %d", ret);
1272 DestroyCallCtx(&callCtx, NULL);
1273 return ret;
1274 }
1275
TrustedDevIpcResult(const IpcDataInfo * replies,int32_t cacheNum,char ** outDevInfoVec,uint32_t * devNum)1276 static int32_t TrustedDevIpcResult(const IpcDataInfo *replies, int32_t cacheNum, char **outDevInfoVec, uint32_t *devNum)
1277 {
1278 int32_t ret;
1279 int32_t inOutLen;
1280
1281 inOutLen = sizeof(int32_t);
1282 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_IPC_RESULT_NUM, (uint8_t *)&ret, &inOutLen);
1283 if ((ret < IPC_RESULT_NUM_2) || (inOutLen != sizeof(int32_t))) {
1284 return HC_ERR_IPC_OUT_DATA_NUM;
1285 }
1286 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DEVICE_INFO, (uint8_t *)outDevInfoVec, NULL);
1287 if (*outDevInfoVec == NULL) {
1288 return HC_ERR_IPC_OUT_DATA;
1289 }
1290 *outDevInfoVec = strdup(*outDevInfoVec);
1291 if (*outDevInfoVec == NULL) {
1292 return HC_ERR_ALLOC_MEMORY;
1293 }
1294 inOutLen = sizeof(int32_t);
1295 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_DATA_NUM, (uint8_t *)devNum, &inOutLen);
1296 return HC_SUCCESS;
1297 }
1298
IpcGmGetTrustedDevices(int32_t osAccountId,const char * appId,const char * groupId,char ** outDevInfoVec,uint32_t * deviceNum)1299 static int32_t IpcGmGetTrustedDevices(int32_t osAccountId, const char *appId,
1300 const char *groupId, char **outDevInfoVec, uint32_t *deviceNum)
1301 {
1302 uintptr_t callCtx = 0x0;
1303 int32_t ret;
1304 int32_t inOutLen;
1305 IpcDataInfo replyCache[IPC_DATA_CACHES_4] = { { 0 } };
1306
1307 LOGI("starting ...");
1308 if (IsStrInvalid(appId) || IsStrInvalid(groupId) ||
1309 (outDevInfoVec == NULL) || (deviceNum == NULL)) {
1310 LOGE("Invalid params.");
1311 return HC_ERR_INVALID_PARAMS;
1312 }
1313 ret = CreateCallCtx(&callCtx, NULL);
1314 if (ret != HC_SUCCESS) {
1315 LOGE("CreateCallCtx failed, ret %d", ret);
1316 return HC_ERR_IPC_INIT;
1317 }
1318 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1319 sizeof(osAccountId));
1320 if (ret != HC_SUCCESS) {
1321 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1322 DestroyCallCtx(&callCtx, NULL);
1323 return HC_ERR_IPC_BUILD_PARAM;
1324 }
1325 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1326 if (ret != HC_SUCCESS) {
1327 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1328 DestroyCallCtx(&callCtx, NULL);
1329 return HC_ERR_IPC_BUILD_PARAM;
1330 }
1331 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
1332 if (ret != HC_SUCCESS) {
1333 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
1334 DestroyCallCtx(&callCtx, NULL);
1335 return HC_ERR_IPC_BUILD_PARAM;
1336 }
1337 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_TRUST_DEVICES, true);
1338 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1339 LOGE("ipc call failed");
1340 DestroyCallCtx(&callCtx, NULL);
1341 return HC_ERR_IPC_PROC_FAILED;
1342 }
1343 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1344 ret = HC_ERR_IPC_UNKNOW_REPLY;
1345 inOutLen = sizeof(int32_t);
1346 GetIpcReplyByType(replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1347 LOGI("process done, ret %d", ret);
1348 if (ret != HC_SUCCESS) {
1349 DestroyCallCtx(&callCtx, NULL);
1350 return ret;
1351 }
1352 ret = TrustedDevIpcResult(replyCache, REPLAY_CACHE_NUM(replyCache), outDevInfoVec, deviceNum);
1353 LOGI("proc result done, ret %d", ret);
1354 DestroyCallCtx(&callCtx, NULL);
1355 return ret;
1356 }
1357
IpcGmIsDeviceInGroup(int32_t osAccountId,const char * appId,const char * groupId,const char * udid)1358 static bool IpcGmIsDeviceInGroup(int32_t osAccountId, const char *appId, const char *groupId, const char *udid)
1359 {
1360 uintptr_t callCtx = 0x0;
1361 int32_t ret;
1362 int32_t inOutLen;
1363 IpcDataInfo replyCache = { 0 };
1364
1365 LOGI("starting ...");
1366 if (IsStrInvalid(appId) || IsStrInvalid(groupId) || IsStrInvalid(udid)) {
1367 LOGE("Invalid params.");
1368 return false;
1369 }
1370 ret = CreateCallCtx(&callCtx, NULL);
1371 if (ret != HC_SUCCESS) {
1372 LOGE("CreateCallCtx failed, ret %d", ret);
1373 return false;
1374 }
1375 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1376 sizeof(osAccountId));
1377 if (ret != HC_SUCCESS) {
1378 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1379 DestroyCallCtx(&callCtx, NULL);
1380 return false;
1381 }
1382 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1383 if (ret != HC_SUCCESS) {
1384 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1385 DestroyCallCtx(&callCtx, NULL);
1386 return false;
1387 }
1388 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_GROUPID, (const uint8_t *)groupId, strlen(groupId) + 1);
1389 if (ret != HC_SUCCESS) {
1390 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_GROUPID);
1391 DestroyCallCtx(&callCtx, NULL);
1392 return false;
1393 }
1394 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_UDID, (const uint8_t *)udid, strlen(udid) + 1);
1395 if (ret != HC_SUCCESS) {
1396 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_UDID);
1397 DestroyCallCtx(&callCtx, NULL);
1398 return false;
1399 }
1400 ret = DoBinderCall(callCtx, IPC_CALL_ID_IS_DEV_IN_GROUP, true);
1401 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1402 LOGE("ipc call failed");
1403 DestroyCallCtx(&callCtx, NULL);
1404 return false;
1405 }
1406 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
1407 ret = HC_ERR_IPC_UNKNOW_REPLY;
1408 inOutLen = sizeof(int32_t);
1409 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1410 LOGI("process done, ret %d", ret);
1411 DestroyCallCtx(&callCtx, NULL);
1412 return (ret == HC_SUCCESS) ? true : false;
1413 }
1414
IpcGmDestroyInfo(char ** returnInfo)1415 static void IpcGmDestroyInfo(char **returnInfo)
1416 {
1417 if ((returnInfo == NULL) || (*returnInfo == NULL)) {
1418 return;
1419 }
1420 FreeJsonString(*returnInfo);
1421 *returnInfo = NULL;
1422 }
1423
IpcGmCancelRequest(int64_t requestId,const char * appId)1424 static void IpcGmCancelRequest(int64_t requestId, const char *appId)
1425 {
1426 uintptr_t callCtx = 0x0;
1427 int32_t ret;
1428
1429 LOGI("starting ...");
1430 if (IsStrInvalid(appId)) {
1431 LOGE("Invalid params.");
1432 return;
1433 }
1434 ret = CreateCallCtx(&callCtx, NULL);
1435 if (ret != HC_SUCCESS) {
1436 LOGE("CreateCallCtx failed, ret %d", ret);
1437 return;
1438 }
1439 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId));
1440 if (ret != HC_SUCCESS) {
1441 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);
1442 DestroyCallCtx(&callCtx, NULL);
1443 return;
1444 }
1445 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1446 if (ret != HC_SUCCESS) {
1447 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1448 DestroyCallCtx(&callCtx, NULL);
1449 return;
1450 }
1451 ret = DoBinderCall(callCtx, IPC_CALL_GM_CANCEL_REQUEST, true);
1452 DestroyCallCtx(&callCtx, NULL);
1453 if (ret != HC_SUCCESS) {
1454 LOGE("ipc call failed");
1455 } else {
1456 LOGI("process done, ret %d", ret);
1457 }
1458 }
1459
InitIpcGmMethods(DeviceGroupManager * gmMethodObj)1460 static void InitIpcGmMethods(DeviceGroupManager *gmMethodObj)
1461 {
1462 LOGI("starting ...");
1463 gmMethodObj->regCallback = IpcGmRegCallback;
1464 gmMethodObj->unRegCallback = IpcGmUnRegCallback;
1465 gmMethodObj->regDataChangeListener = IpcGmRegDataChangeListener;
1466 gmMethodObj->unRegDataChangeListener = IpcGmUnRegDataChangeListener;
1467 gmMethodObj->createGroup = IpcGmCreateGroup;
1468 gmMethodObj->deleteGroup = IpcGmDeleteGroup;
1469 gmMethodObj->addMemberToGroup = IpcGmAddMemberToGroup;
1470 gmMethodObj->deleteMemberFromGroup = IpcGmDelMemberFromGroup;
1471 gmMethodObj->addMultiMembersToGroup = IpcGmAddMultiMembersToGroup;
1472 gmMethodObj->delMultiMembersFromGroup = IpcGmDelMultiMembersFromGroup;
1473 gmMethodObj->processData = IpcGmProcessData;
1474 gmMethodObj->getRegisterInfo = IpcGmGetRegisterInfo;
1475 gmMethodObj->checkAccessToGroup = IpcGmCheckAccessToGroup;
1476 gmMethodObj->getPkInfoList = IpcGmGetPkInfoList;
1477 gmMethodObj->getGroupInfoById = IpcGmGetGroupInfoById;
1478 gmMethodObj->getGroupInfo = IpcGmGetGroupInfo;
1479 gmMethodObj->getJoinedGroups = IpcGmGetJoinedGroups;
1480 gmMethodObj->getRelatedGroups = IpcGmGetRelatedGroups;
1481 gmMethodObj->getDeviceInfoById = IpcGmGetDeviceInfoById;
1482 gmMethodObj->getTrustedDevices = IpcGmGetTrustedDevices;
1483 gmMethodObj->isDeviceInGroup = IpcGmIsDeviceInGroup;
1484 gmMethodObj->cancelRequest = IpcGmCancelRequest;
1485 gmMethodObj->destroyInfo = IpcGmDestroyInfo;
1486 LOGI("process done");
1487 return;
1488 }
1489
EncodeProcessDataParams(uintptr_t callCtx,int64_t authReqId,const uint8_t * data,uint32_t dataLen,const DeviceAuthCallback * callback)1490 static int32_t EncodeProcessDataParams(uintptr_t callCtx, int64_t authReqId,
1491 const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback)
1492 {
1493 int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId));
1494 if (ret != HC_SUCCESS) {
1495 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);
1496 return HC_ERR_IPC_BUILD_PARAM;
1497 }
1498 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_COMM_DATA, (const uint8_t *)data, dataLen);
1499 if (ret != HC_SUCCESS) {
1500 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_COMM_DATA);
1501 return HC_ERR_IPC_BUILD_PARAM;
1502 }
1503 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback));
1504 if (ret != HC_SUCCESS) {
1505 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB);
1506 return HC_ERR_IPC_BUILD_PARAM;
1507 }
1508 SetCbCtxToDataCtx(callCtx, 0x0);
1509 return HC_SUCCESS;
1510 }
1511
IpcGaProcessData(int64_t authReqId,const uint8_t * data,uint32_t dataLen,const DeviceAuthCallback * callback)1512 static int32_t IpcGaProcessData(int64_t authReqId,
1513 const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *callback)
1514 {
1515 uintptr_t callCtx = 0x0;
1516 int32_t ret;
1517 int32_t inOutLen;
1518 IpcDataInfo replyCache = { 0 };
1519
1520 LOGI("starting ...");
1521 if (!IS_COMM_DATA_VALID(data, dataLen) || (callback == NULL)) {
1522 LOGE("invalid params");
1523 return HC_ERR_INVALID_PARAMS;
1524 }
1525 ret = CreateCallCtx(&callCtx, NULL);
1526 if (ret != HC_SUCCESS) {
1527 LOGE("CreateCallCtx failed, ret %d", ret);
1528 return HC_ERR_IPC_INIT;
1529 }
1530 ret = EncodeProcessDataParams(callCtx, authReqId, data, dataLen, callback);
1531 if (ret != HC_SUCCESS) {
1532 DestroyCallCtx(&callCtx, NULL);
1533 return ret;
1534 }
1535 ret = DoBinderCall(callCtx, IPC_CALL_ID_GA_PROC_DATA, true);
1536 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1537 LOGE("ipc call failed");
1538 DestroyCallCtx(&callCtx, NULL);
1539 return HC_ERR_IPC_PROC_FAILED;
1540 }
1541 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
1542 ret = HC_ERR_IPC_UNKNOW_REPLY;
1543 inOutLen = sizeof(int32_t);
1544 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1545 LOGI("process done, ret %d", ret);
1546 DestroyCallCtx(&callCtx, NULL);
1547 return ret;
1548 }
1549
EncodeAuthDeviceParams(uintptr_t callCtx,int32_t osAccountId,int64_t authReqId,const char * authParams,const DeviceAuthCallback * callback)1550 static int32_t EncodeAuthDeviceParams(uintptr_t callCtx, int32_t osAccountId, int64_t authReqId,
1551 const char *authParams, const DeviceAuthCallback *callback)
1552 {
1553 int32_t ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1554 sizeof(osAccountId));
1555 if (ret != HC_SUCCESS) {
1556 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1557 return HC_ERR_IPC_BUILD_PARAM;
1558 }
1559 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&authReqId), sizeof(authReqId));
1560 if (ret != HC_SUCCESS) {
1561 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);
1562 return HC_ERR_IPC_BUILD_PARAM;
1563 }
1564 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_AUTH_PARAMS, (const uint8_t *)authParams, strlen(authParams) + 1);
1565 if (ret != HC_SUCCESS) {
1566 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_AUTH_PARAMS);
1567 return HC_ERR_IPC_BUILD_PARAM;
1568 }
1569 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_DEV_AUTH_CB, (const uint8_t *)callback, sizeof(*callback));
1570 if (ret != HC_SUCCESS) {
1571 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_DEV_AUTH_CB);
1572 return HC_ERR_IPC_BUILD_PARAM;
1573 }
1574 SetCbCtxToDataCtx(callCtx, IPC_CALL_BACK_STUB_AUTH_ID);
1575 return HC_SUCCESS;
1576 }
1577
IpcGaAuthDevice(int32_t osAccountId,int64_t authReqId,const char * authParams,const DeviceAuthCallback * callback)1578 static int32_t IpcGaAuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams,
1579 const DeviceAuthCallback *callback)
1580 {
1581 uintptr_t callCtx = 0x0;
1582 int32_t ret;
1583 int32_t inOutLen;
1584 IpcDataInfo replyCache = { 0 };
1585
1586 LOGI("starting ...");
1587 if (IsStrInvalid(authParams) || (callback == NULL)) {
1588 LOGE("invalid params");
1589 return HC_ERR_INVALID_PARAMS;
1590 }
1591 ret = CreateCallCtx(&callCtx, NULL);
1592 if (ret != HC_SUCCESS) {
1593 LOGE("CreateCallCtx failed, ret %d", ret);
1594 return HC_ERR_IPC_INIT;
1595 }
1596 ret = EncodeAuthDeviceParams(callCtx, osAccountId, authReqId, authParams, callback);
1597 if (ret != HC_SUCCESS) {
1598 DestroyCallCtx(&callCtx, NULL);
1599 return ret;
1600 }
1601 ret = DoBinderCall(callCtx, IPC_CALL_ID_AUTH_DEVICE, true);
1602 if (ret == HC_ERR_IPC_INTERNAL_FAILED) {
1603 LOGE("ipc call failed");
1604 DestroyCallCtx(&callCtx, NULL);
1605 return HC_ERR_IPC_PROC_FAILED;
1606 }
1607 DecodeCallReply(callCtx, &replyCache, REPLAY_CACHE_NUM(replyCache));
1608 ret = HC_ERR_IPC_UNKNOW_REPLY;
1609 inOutLen = sizeof(int32_t);
1610 GetIpcReplyByType(&replyCache, REPLAY_CACHE_NUM(replyCache), PARAM_TYPE_IPC_RESULT, (uint8_t *)&ret, &inOutLen);
1611 LOGI("process done, ret %d", ret);
1612 DestroyCallCtx(&callCtx, NULL);
1613 return ret;
1614 }
1615
IpcGaCancelRequest(int64_t requestId,const char * appId)1616 static void IpcGaCancelRequest(int64_t requestId, const char *appId)
1617 {
1618 uintptr_t callCtx = 0x0;
1619 int32_t ret;
1620
1621 LOGI("starting ...");
1622 if (IsStrInvalid(appId)) {
1623 LOGE("Invalid params.");
1624 return;
1625 }
1626 ret = CreateCallCtx(&callCtx, NULL);
1627 if (ret != HC_SUCCESS) {
1628 LOGE("CreateCallCtx failed, ret %d", ret);
1629 return;
1630 }
1631 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_REQID, (const uint8_t *)(&requestId), sizeof(requestId));
1632 if (ret != HC_SUCCESS) {
1633 LOGE("set request param failed, ret %d, type %d", ret, PARAM_TYPE_REQID);
1634 DestroyCallCtx(&callCtx, NULL);
1635 return;
1636 }
1637 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_APPID, (const uint8_t *)appId, strlen(appId) + 1);
1638 if (ret != HC_SUCCESS) {
1639 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_APPID);
1640 DestroyCallCtx(&callCtx, NULL);
1641 return;
1642 }
1643 ret = DoBinderCall(callCtx, IPC_CALL_GA_CANCEL_REQUEST, true);
1644 DestroyCallCtx(&callCtx, NULL);
1645 if (ret != HC_SUCCESS) {
1646 LOGE("ipc call failed");
1647 } else {
1648 LOGI("process done, ret %d", ret);
1649 }
1650 }
1651
GetIpcReplyByTypeInner(const IpcDataInfo * replies,int32_t cacheNum,char ** outInfo)1652 static int32_t GetIpcReplyByTypeInner(const IpcDataInfo *replies, int32_t cacheNum, char **outInfo)
1653 {
1654 GetIpcReplyByType(replies, cacheNum, PARAM_TYPE_RETURN_DATA, (uint8_t *)outInfo, NULL);
1655 if (*outInfo == NULL) {
1656 return HC_ERR_IPC_OUT_DATA;
1657 }
1658 *outInfo = strdup(*outInfo);
1659 if (*outInfo == NULL) {
1660 return HC_ERR_ALLOC_MEMORY;
1661 }
1662 return HC_SUCCESS;
1663 }
1664
IpcGaGetRealInfo(int32_t osAccountId,const char * pseudonymId,char ** realInfo)1665 static int32_t IpcGaGetRealInfo(int32_t osAccountId, const char *pseudonymId, char **realInfo)
1666 {
1667 uintptr_t callCtx = 0x0;
1668 int32_t ret;
1669 IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } };
1670
1671 LOGI("starting ...");
1672 if (IsStrInvalid(pseudonymId) || (realInfo == NULL)) {
1673 LOGE("Invalid params.");
1674 return HC_ERR_INVALID_PARAMS;
1675 }
1676 ret = CreateCallCtx(&callCtx, NULL);
1677 if (ret != HC_SUCCESS) {
1678 LOGE("CreateCallCtx failed, ret %d", ret);
1679 return HC_ERR_IPC_INIT;
1680 }
1681 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1682 sizeof(osAccountId));
1683 if (ret != HC_SUCCESS) {
1684 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1685 DestroyCallCtx(&callCtx, NULL);
1686 return HC_ERR_IPC_BUILD_PARAM;
1687 }
1688 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_PSEUDONYM_ID, (const uint8_t *)pseudonymId,
1689 strlen(pseudonymId) + 1);
1690 if (ret != HC_SUCCESS) {
1691 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_PSEUDONYM_ID);
1692 DestroyCallCtx(&callCtx, NULL);
1693 return HC_ERR_IPC_BUILD_PARAM;
1694 }
1695 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_REAL_INFO, true);
1696 if (ret != HC_SUCCESS) {
1697 LOGE("ipc call failed");
1698 DestroyCallCtx(&callCtx, NULL);
1699 return HC_ERR_IPC_PROC_FAILED;
1700 }
1701 LOGI("process done, ret %d", ret);
1702 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1703 ret = GetIpcReplyByTypeInner(replyCache, REPLAY_CACHE_NUM(replyCache), realInfo);
1704 if (ret != HC_SUCCESS) {
1705 LOGE("GetIpcReplyByType failed, ret %d", ret);
1706 }
1707 DestroyCallCtx(&callCtx, NULL);
1708 return ret;
1709 }
1710
IpcGaGetPseudonymId(int32_t osAccountId,const char * indexKey,char ** pseudonymId)1711 static int32_t IpcGaGetPseudonymId(int32_t osAccountId, const char *indexKey, char **pseudonymId)
1712 {
1713 uintptr_t callCtx = 0x0;
1714 int32_t ret;
1715 IpcDataInfo replyCache[IPC_DATA_CACHES_1] = { { 0 } };
1716
1717 LOGI("starting ...");
1718 if (IsStrInvalid(indexKey) || (pseudonymId == NULL)) {
1719 LOGE("Invalid params.");
1720 return HC_ERR_INVALID_PARAMS;
1721 }
1722 ret = CreateCallCtx(&callCtx, NULL);
1723 if (ret != HC_SUCCESS) {
1724 LOGE("CreateCallCtx failed, ret %d", ret);
1725 return HC_ERR_IPC_INIT;
1726 }
1727 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_OS_ACCOUNT_ID, (const uint8_t *)&osAccountId,
1728 sizeof(osAccountId));
1729 if (ret != HC_SUCCESS) {
1730 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_OS_ACCOUNT_ID);
1731 DestroyCallCtx(&callCtx, NULL);
1732 return HC_ERR_IPC_BUILD_PARAM;
1733 }
1734 ret = SetCallRequestParamInfo(callCtx, PARAM_TYPE_INDEX_KEY, (const uint8_t *)indexKey, strlen(indexKey) + 1);
1735 if (ret != HC_SUCCESS) {
1736 LOGE("set request param failed, ret %d, param id %d", ret, PARAM_TYPE_INDEX_KEY);
1737 DestroyCallCtx(&callCtx, NULL);
1738 return HC_ERR_IPC_BUILD_PARAM;
1739 }
1740 ret = DoBinderCall(callCtx, IPC_CALL_ID_GET_PSEUDONYM_ID, true);
1741 if (ret != HC_SUCCESS) {
1742 LOGE("ipc call failed");
1743 DestroyCallCtx(&callCtx, NULL);
1744 return HC_ERR_IPC_PROC_FAILED;
1745 }
1746 LOGI("process done, ret %d", ret);
1747 DecodeCallReply(callCtx, replyCache, REPLAY_CACHE_NUM(replyCache));
1748 ret = GetIpcReplyByTypeInner(replyCache, REPLAY_CACHE_NUM(replyCache), pseudonymId);
1749 if (ret != HC_SUCCESS) {
1750 LOGE("GetIpcReplyByType failed, ret %d", ret);
1751 }
1752 DestroyCallCtx(&callCtx, NULL);
1753 return ret;
1754 }
1755
InitIpcGaMethods(GroupAuthManager * gaMethodObj)1756 static void InitIpcGaMethods(GroupAuthManager *gaMethodObj)
1757 {
1758 LOGI("entering...");
1759 gaMethodObj->processData = IpcGaProcessData;
1760 gaMethodObj->authDevice = IpcGaAuthDevice;
1761 gaMethodObj->cancelRequest = IpcGaCancelRequest;
1762 gaMethodObj->getRealInfo = IpcGaGetRealInfo;
1763 gaMethodObj->getPseudonymId = IpcGaGetPseudonymId;
1764 LOGI("process done");
1765 return;
1766 }
1767
InitDeviceAuthService(void)1768 DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void)
1769 {
1770 InitHcMutex(&g_ipcMutex);
1771 return InitProxyAdapt();
1772 }
1773
DestroyDeviceAuthService(void)1774 DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void)
1775 {
1776 UnInitProxyAdapt();
1777 DestroyHcMutex(&g_ipcMutex);
1778 }
1779
GetGaInstance(void)1780 DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void)
1781 {
1782 static GroupAuthManager gaInstCtx = {NULL};
1783 static GroupAuthManager *gaInstPtr = NULL;
1784
1785 LOGI("Enter InitIpcMethods...");
1786 if (gaInstPtr == NULL) {
1787 InitIpcGaMethods(&gaInstCtx);
1788 gaInstPtr = &gaInstCtx;
1789 }
1790 LOGI("InitIpcMethods done");
1791 return (const GroupAuthManager *)(gaInstPtr);
1792 }
1793
GetGmInstance(void)1794 DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void)
1795 {
1796 static DeviceGroupManager gmInstCtx = {NULL};
1797 static DeviceGroupManager *gmInstPtr = NULL;
1798
1799 LOGI("Enter InitIpcMethods...");
1800 if (gmInstPtr == NULL) {
1801 InitIpcGmMethods(&gmInstCtx);
1802 gmInstPtr = &gmInstCtx;
1803 }
1804 LOGI("InitIpcMethods done");
1805 return (const DeviceGroupManager *)(gmInstPtr);
1806 }
1807
1808 #ifdef __cplusplus
1809 }
1810 #endif
1811