• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_service.h"
17 
18 #include "common_defs.h"
19 #include "device_auth_defines.h"
20 #include "device_auth.h"
21 #include "hc_condition.h"
22 #include "hc_log.h"
23 #include "hc_thread.h"
24 #include "ipc_adapt.h"
25 #include "ipc_sdk.h"
26 #include "securec.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 static const int32_t IPC_RESULT_NUM_1 = 1;
33 static const int32_t IPC_RESULT_NUM_2 = 2;
34 static const char *g_serviceAppId = "deviceauth_service";
35 static DeviceGroupManager g_devGroupMgrMethod = {NULL};
36 static GroupAuthManager g_groupAuthMgrMethod = {NULL};
37 static DeviceAuthCallback g_bindCbAdt = {NULL};
38 static DeviceAuthCallback g_authCbAdt = {NULL};
39 static DataChangeListener g_listenCbAdt = {NULL};
40 
BindRequestIdWithAppId(const char * data)41 static int32_t BindRequestIdWithAppId(const char *data)
42 {
43     const char *appId = NULL;
44     int32_t ret;
45     int64_t requestId = -1;
46     CJson *dataJson = CreateJsonFromString(data);
47     if (dataJson == NULL) {
48         LOGE("failed to create json from string!");
49         return HC_ERROR;
50     }
51 
52     appId = GetStringFromJson(dataJson, FIELD_APP_ID);
53     if (appId == NULL) {
54         LOGE("failed to get appId from json object!");
55         FreeJson(dataJson);
56         return HC_ERROR;
57     }
58     (void)GetInt64FromJson(dataJson, FIELD_REQUEST_ID, &requestId);
59     ret = AddReqIdByAppId(appId, requestId);
60     FreeJson(dataJson);
61     return ret;
62 }
63 
IpcServiceGmRegCallback(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)64 static int32_t IpcServiceGmRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
65 {
66     int32_t callRet;
67     int32_t ret;
68     const char *appId = NULL;
69     const DeviceAuthCallback *callback = NULL;
70     int32_t cbObjIdx = -1;
71     int32_t idxLen;
72 
73     LOGI("starting ...");
74     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
75     if (ret != HC_SUCCESS) {
76         LOGE("get param error, type %d", PARAM_TYPE_APPID);
77         return ret;
78     }
79 
80     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&callback, NULL);
81     if (ret != HC_SUCCESS) {
82         LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
83         return ret;
84     }
85     ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DeviceAuthCallback), CB_TYPE_DEV_AUTH);
86     if (ret != HC_SUCCESS) {
87         LOGE("add ipc callback failed");
88         return HC_ERROR;
89     }
90 
91     idxLen = sizeof(cbObjIdx);
92     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &idxLen);
93     if (ret != HC_SUCCESS) {
94         LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
95         DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
96         return ret;
97     }
98     AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_DEV_AUTH);
99     InitDeviceAuthCbCtx(&g_bindCbAdt, CB_TYPE_DEV_AUTH);
100     callRet = g_devGroupMgrMethod.regCallback(appId, &g_bindCbAdt);
101     if (callRet != HC_SUCCESS) {
102         DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
103     }
104     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
105     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
106     return ret;
107 }
108 
IpcServiceGmUnRegCallback(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)109 static int32_t IpcServiceGmUnRegCallback(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
110 {
111     int32_t callRet = HC_SUCCESS;
112     int32_t ret;
113     const char *appId = NULL;
114 
115     LOGI("starting ...");
116     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
117     if (ret != HC_SUCCESS) {
118         LOGE("get param error, type %d", PARAM_TYPE_APPID);
119         return ret;
120     }
121 
122     DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
123     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
124     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
125     return ret;
126 }
127 
IpcServiceGmRegDataChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)128 static int32_t IpcServiceGmRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
129 {
130     int32_t callRet;
131     int32_t ret;
132     const char *appId = NULL;
133     const DataChangeListener *callback = NULL;
134     static int32_t registered = 0;
135     int32_t cbObjIdx = -1;
136     int32_t idxLen;
137 
138     LOGI("starting ...");
139     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
140     if (ret != HC_SUCCESS) {
141         LOGE("get param error, type %d", PARAM_TYPE_APPID);
142         return ret;
143     }
144 
145     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_LISTERNER, (uint8_t *)&callback, NULL);
146     if (ret != HC_SUCCESS) {
147         LOGE("get param error, type %d", PARAM_TYPE_LISTERNER);
148         return ret;
149     }
150 
151     ret = AddIpcCallBackByAppId(appId, (const uint8_t *)callback, sizeof(DataChangeListener), CB_TYPE_LISTENER);
152     if (ret != HC_SUCCESS) {
153         LOGE("add ipc callback failed");
154         return HC_ERROR;
155     }
156 
157     idxLen = sizeof(cbObjIdx);
158     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &idxLen);
159     if (ret != HC_SUCCESS) {
160         LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
161         DelIpcCallBackByAppId(appId, CB_TYPE_DEV_AUTH);
162         return ret;
163     }
164     AddIpcCbObjByAppId(appId, cbObjIdx, CB_TYPE_LISTENER);
165 
166     callRet = HC_SUCCESS;
167     if (registered == 0) {
168         InitDevAuthListenerCbCtx(&g_listenCbAdt);
169         callRet = g_devGroupMgrMethod.regDataChangeListener(g_serviceAppId, &g_listenCbAdt);
170         if (callRet == HC_SUCCESS) {
171             registered = 1;
172         } else {
173             DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
174         }
175     }
176     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
177     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
178     return ret;
179 }
180 
IpcServiceGmUnRegDataChangeListener(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)181 static int32_t IpcServiceGmUnRegDataChangeListener(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
182 {
183     int32_t callRet = HC_SUCCESS;
184     int32_t ret;
185     const char *appId = NULL;
186 
187     LOGI("starting ...");
188     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
189     if (ret != HC_SUCCESS) {
190         LOGE("get param error, type %d", PARAM_TYPE_APPID);
191         return ret;
192     }
193     DelIpcCallBackByAppId(appId, CB_TYPE_LISTENER);
194     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
195     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
196     return ret;
197 }
198 
IpcServiceGmCreateGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)199 static int32_t IpcServiceGmCreateGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
200 {
201     int32_t callRet;
202     int32_t ret;
203     int32_t osAccountId;
204     int64_t requestId = 0;
205     int32_t inOutLen;
206     const char *createParams = NULL;
207     const char *appId = NULL;
208 
209     LOGI("starting ...");
210     inOutLen = sizeof(int32_t);
211     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
212     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
213         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
214         return HC_ERR_IPC_BAD_PARAM;
215     }
216     inOutLen = sizeof(int64_t);
217     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
218     if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
219         LOGE("get param error, type %d", PARAM_TYPE_REQID);
220         return HC_ERR_IPC_BAD_PARAM;
221     }
222     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
223     if (ret != HC_SUCCESS) {
224         LOGE("get param error, type %d", PARAM_TYPE_APPID);
225         return ret;
226     }
227     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CREATE_PARAMS, (uint8_t *)&createParams, NULL);
228     if (ret != HC_SUCCESS) {
229         LOGE("get param error, type %d", PARAM_TYPE_CREATE_PARAMS);
230         return ret;
231     }
232     ret = AddReqIdByAppId(appId, requestId);
233     if (ret != 0) {
234         LOGE("bind request id by app id failed");
235         return ret;
236     }
237     callRet = g_devGroupMgrMethod.createGroup(osAccountId, requestId, appId, createParams);
238     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
239     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
240     return ret;
241 }
242 
IpcServiceGmDelGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)243 static int32_t IpcServiceGmDelGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
244 {
245     int32_t callRet;
246     int32_t ret;
247     int32_t osAccountId;
248     int64_t requestId = 0;
249     int32_t inOutLen;
250     const char *appId = NULL;
251     const char *delParams = NULL;
252 
253     LOGI("starting ...");
254     inOutLen = sizeof(int32_t);
255     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
256     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
257         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
258         return HC_ERR_IPC_BAD_PARAM;
259     }
260     inOutLen = sizeof(int64_t);
261     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
262     if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
263         LOGE("get param error, type %d", PARAM_TYPE_REQID);
264         return HC_ERR_IPC_BAD_PARAM;
265     }
266     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
267     if (ret != HC_SUCCESS) {
268         LOGE("get param error, type %d", PARAM_TYPE_APPID);
269         return ret;
270     }
271     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
272     if (ret != HC_SUCCESS) {
273         LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
274         return ret;
275     }
276     ret = AddReqIdByAppId(appId, requestId);
277     if (ret != 0) {
278         LOGE("bind request id by app id failed");
279         return ret;
280     }
281     callRet = g_devGroupMgrMethod.deleteGroup(osAccountId, requestId, appId, delParams);
282     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
283     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
284     return ret;
285 }
286 
IpcServiceGmAddMemberToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)287 static int32_t IpcServiceGmAddMemberToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
288 {
289     int32_t callRet;
290     int32_t ret;
291     int32_t inOutLen;
292     int32_t osAccountId;
293     int64_t requestId = 0;
294     const char *addParams = NULL;
295     const char *appId = NULL;
296 
297     LOGI("starting ...");
298     inOutLen = sizeof(int32_t);
299     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
300     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
301         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
302         return HC_ERR_IPC_BAD_PARAM;
303     }
304     inOutLen = sizeof(int64_t);
305     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
306     if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
307         LOGE("get param error, type %d", PARAM_TYPE_REQID);
308         return HC_ERR_IPC_BAD_PARAM;
309     }
310     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
311     if (ret != HC_SUCCESS) {
312         LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS);
313         return ret;
314     }
315     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
316     if (ret != HC_SUCCESS) {
317         LOGE("get param error, type %d", PARAM_TYPE_APPID);
318         return ret;
319     }
320     ret = AddReqIdByAppId(appId, requestId);
321     if (ret != HC_SUCCESS) {
322         return ret;
323     }
324     callRet = g_devGroupMgrMethod.addMemberToGroup(osAccountId, requestId, appId, addParams);
325     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
326     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
327     return ret;
328 }
329 
IpcServiceGmDelMemberFromGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)330 static int32_t IpcServiceGmDelMemberFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
331 {
332     int32_t callRet;
333     int32_t ret;
334     int32_t inOutLen;
335     int32_t osAccountId;
336     int64_t requestId = 0;
337     const char *delParams = NULL;
338     const char *appId = NULL;
339 
340     LOGI("starting ...");
341     inOutLen = sizeof(int32_t);
342     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
343     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
344         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
345         return HC_ERR_IPC_BAD_PARAM;
346     }
347     inOutLen = sizeof(int64_t);
348     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
349     if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
350         LOGE("get param error, type %d", PARAM_TYPE_REQID);
351         return HC_ERR_IPC_BAD_PARAM;
352     }
353     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
354     if (ret != HC_SUCCESS) {
355         LOGE("get param error, type %d", PARAM_TYPE_APPID);
356         return ret;
357     }
358     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
359     if (ret != HC_SUCCESS) {
360         LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
361         return ret;
362     }
363     ret = AddReqIdByAppId(appId, requestId);
364     if (ret != 0) {
365         LOGE("bind request id by app id failed");
366         return ret;
367     }
368     callRet = g_devGroupMgrMethod.deleteMemberFromGroup(osAccountId, requestId, appId, delParams);
369     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
370     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
371     return ret;
372 }
373 
IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)374 static int32_t IpcServiceGmAddMultiMembersToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
375 {
376     int32_t callRet;
377     int32_t ret;
378     int32_t inOutLen;
379     int32_t osAccountId;
380     const char *addParams = NULL;
381     const char *appId = NULL;
382 
383     LOGI("starting ...");
384     inOutLen = sizeof(int32_t);
385     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
386     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
387         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
388         return HC_ERR_IPC_BAD_PARAM;
389     }
390     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_ADD_PARAMS, (uint8_t *)&addParams, NULL);
391     if (ret != HC_SUCCESS) {
392         LOGE("get param error, type %d", PARAM_TYPE_ADD_PARAMS);
393         return ret;
394     }
395     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
396     if (ret != HC_SUCCESS) {
397         LOGE("get param error, type %d", PARAM_TYPE_APPID);
398         return ret;
399     }
400     callRet = g_devGroupMgrMethod.addMultiMembersToGroup(osAccountId, appId, addParams);
401     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
402     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
403     return ret;
404 }
405 
IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)406 static int32_t IpcServiceGmDelMultiMembersFromGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
407 {
408     int32_t callRet;
409     int32_t ret;
410     int32_t inOutLen;
411     int32_t osAccountId;
412     const char *delParams = NULL;
413     const char *appId = NULL;
414 
415     LOGI("starting ...");
416     inOutLen = sizeof(int32_t);
417     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
418     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
419         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
420         return HC_ERR_IPC_BAD_PARAM;
421     }
422     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
423     if (ret != HC_SUCCESS) {
424         LOGE("get param error, type %d", PARAM_TYPE_APPID);
425         return ret;
426     }
427     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEL_PARAMS, (uint8_t *)&delParams, NULL);
428     if (ret != HC_SUCCESS) {
429         LOGE("get param error, type %d", PARAM_TYPE_DEL_PARAMS);
430         return ret;
431     }
432     callRet = g_devGroupMgrMethod.delMultiMembersFromGroup(osAccountId, appId, delParams);
433     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
434     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
435     return ret;
436 }
437 
IpcServiceGmProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)438 static int32_t IpcServiceGmProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
439 {
440     int32_t callRet;
441     int32_t ret;
442     int32_t dataLen;
443     int32_t inOutLen;
444     int64_t requestId = 0;
445     const uint8_t *data = NULL;
446 
447     LOGI("starting ...");
448     inOutLen = sizeof(int64_t);
449     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
450     if ((inOutLen != sizeof(int64_t)) || (ret != HC_SUCCESS)) {
451         LOGE("get param error, type %d", PARAM_TYPE_REQID);
452         return HC_ERR_IPC_BAD_PARAM;
453     }
454 
455     dataLen = 0;
456     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, &dataLen);
457     if ((dataLen <= 0) || (ret != HC_SUCCESS)) {
458         LOGE("get param error, type %d, data length %d", PARAM_TYPE_COMM_DATA, dataLen);
459         return HC_ERR_IPC_BAD_PARAM;
460     }
461     ret = BindRequestIdWithAppId((const char *)data);
462     if (ret != HC_SUCCESS) {
463         return ret;
464     }
465     callRet = g_devGroupMgrMethod.processData(requestId, data, dataLen);
466     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
467     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
468     return ret;
469 }
470 
IpcServiceGmApplyRegisterInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)471 static int32_t IpcServiceGmApplyRegisterInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
472 {
473     int32_t callRet;
474     int32_t ret;
475     const char *reqJsonStr = NULL;
476     char *registerInfo = NULL;
477 
478     LOGI("starting ...");
479     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQ_JSON, (uint8_t *)&reqJsonStr, NULL);
480     if ((reqJsonStr == NULL) || (ret != HC_SUCCESS)) {
481         LOGE("get param error, type %d", PARAM_TYPE_REQ_JSON);
482         return HC_ERR_IPC_BAD_PARAM;
483     }
484     callRet = g_devGroupMgrMethod.getRegisterInfo(reqJsonStr, &registerInfo);
485     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
486     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
487                                (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
488     if (registerInfo != NULL) {
489         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_REG_INFO,
490             (const uint8_t *)registerInfo, strlen(registerInfo) + 1);
491         g_devGroupMgrMethod.destroyInfo(&registerInfo);
492     } else {
493         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_REG_INFO, NULL, 0);
494     }
495     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
496     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
497 }
498 
IpcServiceGmCheckAccessToGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)499 static int32_t IpcServiceGmCheckAccessToGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
500 {
501     int32_t callRet;
502     int32_t ret;
503     int32_t inOutLen;
504     int32_t osAccountId;
505     const char *appId = NULL;
506     const char *groupId = NULL;
507 
508     LOGI("starting ...");
509     inOutLen = sizeof(int32_t);
510     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
511     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
512         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
513         return HC_ERR_IPC_BAD_PARAM;
514     }
515     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
516     if ((appId == NULL) || (ret != HC_SUCCESS)) {
517         LOGE("get param error, type %d", PARAM_TYPE_APPID);
518         return HC_ERR_IPC_BAD_PARAM;
519     }
520     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
521     if ((groupId == NULL) || (ret != HC_SUCCESS)) {
522         LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
523         return HC_ERR_IPC_BAD_PARAM;
524     }
525 
526     callRet = g_devGroupMgrMethod.checkAccessToGroup(osAccountId, appId, groupId);
527     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
528     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
529     return ret;
530 }
531 
IpcServiceGmGetPkInfoList(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)532 static int32_t IpcServiceGmGetPkInfoList(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
533 {
534     int32_t callRet;
535     int32_t ret;
536     int32_t inOutLen;
537     int32_t osAccountId;
538     const char *appId = NULL;
539     const char *queryParams = NULL;
540     char *returnInfoList = NULL;
541     uint32_t returnInfoNum = 0;
542 
543     LOGI("starting ...");
544     inOutLen = sizeof(int32_t);
545     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
546     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
547         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
548         return HC_ERR_IPC_BAD_PARAM;
549     }
550     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
551     if ((appId == NULL) || (ret != HC_SUCCESS)) {
552         LOGE("get param error, type %d", PARAM_TYPE_APPID);
553         return HC_ERR_IPC_BAD_PARAM;
554     }
555     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
556     if ((queryParams == NULL) || (ret != HC_SUCCESS)) {
557         LOGE("get param error, type %d", PARAM_TYPE_QUERY_PARAMS);
558         return HC_ERR_IPC_BAD_PARAM;
559     }
560 
561     callRet = g_devGroupMgrMethod.getPkInfoList(osAccountId, appId, queryParams, &returnInfoList, &returnInfoNum);
562     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
563     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
564                                (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
565     if (returnInfoList != NULL) {
566         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)returnInfoList,
567                                    strlen(returnInfoList) + 1);
568     } else {
569         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
570     }
571     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&returnInfoNum, sizeof(int32_t));
572     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
573     g_devGroupMgrMethod.destroyInfo(&returnInfoList);
574     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
575 }
576 
IpcServiceGmGetGroupInfoById(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)577 static int32_t IpcServiceGmGetGroupInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
578 {
579     int32_t callRet;
580     int32_t ret;
581     int32_t inOutLen;
582     int32_t osAccountId;
583     const char *appId = NULL;
584     const char *groupId = NULL;
585     char *groupInfo = NULL;
586 
587     LOGI("starting ...");
588     inOutLen = sizeof(int32_t);
589     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
590     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
591         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
592         return HC_ERR_IPC_BAD_PARAM;
593     }
594     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
595     if ((appId == NULL) || (ret != HC_SUCCESS)) {
596         LOGE("get param error, type %d", PARAM_TYPE_APPID);
597         return HC_ERR_IPC_BAD_PARAM;
598     }
599     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
600     if ((groupId == NULL) || (ret != HC_SUCCESS)) {
601         LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
602         return HC_ERR_IPC_BAD_PARAM;
603     }
604 
605     callRet = g_devGroupMgrMethod.getGroupInfoById(osAccountId, appId, groupId, &groupInfo);
606     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
607     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
608                                (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
609     if (groupInfo != NULL) {
610         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)groupInfo, strlen(groupInfo) + 1);
611         g_devGroupMgrMethod.destroyInfo(&groupInfo);
612     } else {
613         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
614     }
615     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
616     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
617 }
618 
IpcServiceGmGetGroupInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)619 static int32_t IpcServiceGmGetGroupInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
620 {
621     int32_t callRet;
622     int32_t ret;
623     int32_t inOutLen;
624     int32_t osAccountId;
625     const char *appId = NULL;
626     const char *queryParams = NULL;
627     char *outGroups = NULL;
628     uint32_t groupNum = 0;
629 
630     LOGI("starting ...");
631     inOutLen = sizeof(int32_t);
632     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
633     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
634         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
635         return HC_ERR_IPC_BAD_PARAM;
636     }
637     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
638     if ((appId == NULL) || (ret != HC_SUCCESS)) {
639         LOGE("get param error, type %d", PARAM_TYPE_APPID);
640         return HC_ERR_IPC_BAD_PARAM;
641     }
642     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_QUERY_PARAMS, (uint8_t *)&queryParams, NULL);
643     if ((queryParams == NULL) || (ret != HC_SUCCESS)) {
644         LOGE("get param error, type %d", PARAM_TYPE_QUERY_PARAMS);
645         return HC_ERR_IPC_BAD_PARAM;
646     }
647 
648     callRet = g_devGroupMgrMethod.getGroupInfo(osAccountId, appId, queryParams, &outGroups, &groupNum);
649     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
650     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
651                                (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
652     if (outGroups != NULL) {
653         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, strlen(outGroups) + 1);
654     } else {
655         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
656     }
657     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
658     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
659     g_devGroupMgrMethod.destroyInfo(&outGroups);
660     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
661 }
662 
IpcServiceGmGetJoinedGroups(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)663 static int32_t IpcServiceGmGetJoinedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
664 {
665     int32_t callRet;
666     int32_t ret;
667     int32_t groupType = 0;
668     int32_t inOutLen;
669     int32_t osAccountId;
670     const char *appId = NULL;
671     char *outGroups = NULL;
672     uint32_t groupNum = 0;
673 
674     LOGI("starting ...");
675     inOutLen = sizeof(int32_t);
676     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
677     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
678         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
679         return HC_ERR_IPC_BAD_PARAM;
680     }
681     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
682     if ((appId == NULL) || (ret != HC_SUCCESS)) {
683         LOGE("get param error, type %d", PARAM_TYPE_APPID);
684         return HC_ERR_IPC_BAD_PARAM;
685     }
686     inOutLen = sizeof(groupType);
687     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUP_TYPE, (uint8_t *)&groupType, &inOutLen);
688     if ((inOutLen != sizeof(groupType)) || (ret != HC_SUCCESS)) {
689         LOGE("get param error, type %d", PARAM_TYPE_GROUP_TYPE);
690         return HC_ERR_IPC_BAD_PARAM;
691     }
692 
693     callRet = g_devGroupMgrMethod.getJoinedGroups(osAccountId, appId, groupType, &outGroups, &groupNum);
694     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
695     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
696                                (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
697     if (outGroups != NULL) {
698         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, strlen(outGroups) + 1);
699         g_devGroupMgrMethod.destroyInfo(&outGroups);
700     } else {
701         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
702     }
703     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
704     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
705     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
706 }
707 
IpcServiceGmGetRelatedGroups(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)708 static int32_t IpcServiceGmGetRelatedGroups(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
709 {
710     int32_t callRet;
711     int32_t ret;
712     int32_t inOutLen;
713     int32_t osAccountId;
714     const char *appId = NULL;
715     const char *peerUdid = NULL;
716     char *outGroups = NULL;
717     uint32_t groupNum = 0;
718 
719     LOGI("starting ...");
720     inOutLen = sizeof(int32_t);
721     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
722     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
723         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
724         return HC_ERR_IPC_BAD_PARAM;
725     }
726     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
727     if ((appId == NULL) || (ret != HC_SUCCESS)) {
728         LOGE("get param error, type %d", PARAM_TYPE_APPID);
729         return HC_ERR_IPC_BAD_PARAM;
730     }
731     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
732     if ((peerUdid == NULL) || (ret != HC_SUCCESS)) {
733         LOGE("get param error, type %d", PARAM_TYPE_UDID);
734         return HC_ERR_IPC_BAD_PARAM;
735     }
736 
737     callRet = g_devGroupMgrMethod.getRelatedGroups(osAccountId, appId, peerUdid, &outGroups, &groupNum);
738     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
739     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
740                                (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
741     if (outGroups != NULL) {
742         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, (const uint8_t *)outGroups, strlen(outGroups) + 1);
743     } else {
744         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_GROUP_INFO, NULL, 0);
745     }
746     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&groupNum, sizeof(int32_t));
747     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
748     g_devGroupMgrMethod.destroyInfo(&outGroups);
749     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
750 }
751 
IpcServiceGmGetDeviceInfoById(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)752 static int32_t IpcServiceGmGetDeviceInfoById(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
753 {
754     int32_t callRet;
755     int32_t ret;
756     int32_t inOutLen;
757     int32_t osAccountId;
758     const char *appId = NULL;
759     const char *peerUdid = NULL;
760     const char *groupId = NULL;
761     char *outDevInfo = NULL;
762 
763     LOGI("starting ...");
764     inOutLen = sizeof(int32_t);
765     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
766     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
767         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
768         return HC_ERR_IPC_BAD_PARAM;
769     }
770     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
771     if ((appId == NULL) || (ret != HC_SUCCESS)) {
772         LOGE("get param error, type %d", PARAM_TYPE_APPID);
773         return HC_ERR_IPC_BAD_PARAM;
774     }
775     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&peerUdid, NULL);
776     if ((peerUdid == NULL) || (ret != HC_SUCCESS)) {
777         LOGE("get param error, type %d", PARAM_TYPE_UDID);
778         return HC_ERR_IPC_BAD_PARAM;
779     }
780     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
781     if ((groupId == NULL) || (ret != HC_SUCCESS)) {
782         LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
783         return HC_ERR_IPC_BAD_PARAM;
784     }
785 
786     callRet = g_devGroupMgrMethod.getDeviceInfoById(osAccountId, appId, peerUdid, groupId, &outDevInfo);
787     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
788     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
789                                (const uint8_t *)&IPC_RESULT_NUM_1, sizeof(int32_t));
790     if (outDevInfo != NULL) {
791         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO,
792             (const uint8_t *)outDevInfo, strlen(outDevInfo) + 1);
793         g_devGroupMgrMethod.destroyInfo(&outDevInfo);
794     } else {
795         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
796     }
797     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
798     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
799 }
800 
IpcServiceGmGetTrustedDevices(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)801 static int32_t IpcServiceGmGetTrustedDevices(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
802 {
803     int32_t callRet;
804     int32_t ret;
805     int32_t inOutLen;
806     int32_t osAccountId;
807     const char *appId = NULL;
808     const char *groupId = NULL;
809     char *outDevInfo = NULL;
810     uint32_t outDevNum = 0;
811 
812     LOGI("starting ...");
813     inOutLen = sizeof(int32_t);
814     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
815     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
816         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
817         return HC_ERR_IPC_BAD_PARAM;
818     }
819     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
820     if ((appId == NULL) || (ret != HC_SUCCESS)) {
821         LOGE("get param error, type %d", PARAM_TYPE_APPID);
822         return HC_ERR_IPC_BAD_PARAM;
823     }
824     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
825     if ((groupId == NULL) || (ret != HC_SUCCESS)) {
826         LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
827         return HC_ERR_IPC_BAD_PARAM;
828     }
829 
830     callRet = g_devGroupMgrMethod.getTrustedDevices(osAccountId, appId, groupId, &outDevInfo, &outDevNum);
831     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
832     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT_NUM,
833                                (const uint8_t *)&IPC_RESULT_NUM_2, sizeof(int32_t));
834     if (outDevInfo != NULL) {
835         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO,
836             (const uint8_t *)outDevInfo, strlen(outDevInfo) + 1);
837     } else {
838         ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DEVICE_INFO, NULL, 0);
839     }
840     ret += IpcEncodeCallReplay(outCache, PARAM_TYPE_DATA_NUM, (const uint8_t *)&outDevNum, sizeof(int32_t));
841     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
842     g_devGroupMgrMethod.destroyInfo(&outDevInfo);
843     return (ret == HC_SUCCESS) ? ret : HC_ERROR;
844 }
845 
IpcServiceGmIsDeviceInGroup(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)846 static int32_t IpcServiceGmIsDeviceInGroup(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
847 {
848     int32_t callRet;
849     int32_t ret;
850     int32_t inOutLen;
851     int32_t osAccountId;
852     bool bRet = false;
853     const char *appId = NULL;
854     const char *udid = NULL;
855     const char *groupId = NULL;
856 
857     LOGI("starting ...");
858     inOutLen = sizeof(int32_t);
859     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
860     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
861         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
862         return HC_ERR_IPC_BAD_PARAM;
863     }
864     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
865     if ((appId == NULL) || (ret != HC_SUCCESS)) {
866         LOGE("get param error, type %d", PARAM_TYPE_APPID);
867         return HC_ERR_IPC_BAD_PARAM;
868     }
869     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_UDID, (uint8_t *)&udid, NULL);
870     if ((udid == NULL) || (ret != HC_SUCCESS)) {
871         LOGE("get param error, type %d", PARAM_TYPE_UDID);
872         return HC_ERR_IPC_BAD_PARAM;
873     }
874     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_GROUPID, (uint8_t *)&groupId, NULL);
875     if ((groupId == NULL) || (ret != HC_SUCCESS)) {
876         LOGE("get param error, type %d", PARAM_TYPE_GROUPID);
877         return HC_ERR_IPC_BAD_PARAM;
878     }
879 
880     bRet = g_devGroupMgrMethod.isDeviceInGroup(osAccountId, appId, groupId, udid);
881     callRet = ((bRet == true) ? HC_SUCCESS : HC_ERROR);
882     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
883     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
884     return ret;
885 }
886 
IpcServiceGmCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)887 static int32_t IpcServiceGmCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
888 {
889     int32_t ret;
890     int64_t requestId = 0;
891     const char *appId = NULL;
892 
893     LOGI("starting ...");
894     int32_t inOutLen = sizeof(int64_t);
895     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
896     if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
897         LOGE("get param error, type %d", PARAM_TYPE_REQID);
898         return HC_ERR_IPC_BAD_PARAM;
899     }
900     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
901     if ((appId == NULL) || (ret != HC_SUCCESS)) {
902         LOGE("get param error, type %d", PARAM_TYPE_APPID);
903         return HC_ERR_IPC_BAD_PARAM;
904     }
905 
906     g_devGroupMgrMethod.cancelRequest(requestId, appId);
907     LOGI("process done, ipc ret %d", ret);
908     return ret;
909 }
910 
IpcServiceGaProcessData(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)911 static int32_t IpcServiceGaProcessData(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
912 {
913     int32_t callRet;
914     int32_t ret;
915     const DeviceAuthCallback *gaCallback = NULL;
916     int64_t authReqId = 0;
917     uint8_t *data = NULL;
918     uint32_t dataLen = 0;
919     int32_t inOutLen;
920     int32_t cbObjIdx = -1;
921 
922     LOGI("starting ...");
923     inOutLen = sizeof(authReqId);
924     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
925     if ((inOutLen != sizeof(authReqId)) || (ret != HC_SUCCESS)) {
926         LOGE("get param error, type %d", PARAM_TYPE_REQID);
927         return HC_ERR_IPC_BAD_PARAM;
928     }
929     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_COMM_DATA, (uint8_t *)&data, (int32_t *)&dataLen);
930     if ((data == NULL) || (dataLen == 0) || (ret != HC_SUCCESS)) {
931         LOGE("get param error, type %d", PARAM_TYPE_COMM_DATA);
932         return HC_ERR_IPC_BAD_PARAM;
933     }
934     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, NULL);
935     if (ret != HC_SUCCESS) {
936         LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
937         return ret;
938     }
939     /* add call back */
940     ret = AddIpcCallBackByReqId(authReqId, (const uint8_t *)gaCallback,
941         sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
942     if (ret != HC_SUCCESS) {
943         LOGE("add ipc callback failed");
944         return HC_ERROR;
945     }
946     inOutLen = sizeof(cbObjIdx);
947     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
948     if (ret != HC_SUCCESS) {
949         LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
950         DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
951         return ret;
952     }
953     AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
954     InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
955     callRet = g_groupAuthMgrMethod.processData(authReqId, data, dataLen, &g_authCbAdt);
956     if (callRet != HC_SUCCESS) {
957         DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
958     }
959     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
960     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
961     return ret;
962 }
963 
IpcServiceGaAuthDevice(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)964 static int32_t IpcServiceGaAuthDevice(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
965 {
966     int32_t callRet;
967     int32_t ret;
968     DeviceAuthCallback *gaCallback = NULL;
969     int32_t osAccountId;
970     int64_t authReqId = 0;
971     const char *authParams = NULL;
972     int32_t inOutLen;
973     int32_t cbObjIdx = -1;
974 
975     LOGI("starting ...");
976     inOutLen = sizeof(int32_t);
977     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
978     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
979         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
980         return HC_ERR_IPC_BAD_PARAM;
981     }
982     inOutLen = sizeof(authReqId);
983     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&authReqId, &inOutLen);
984     if ((inOutLen != sizeof(authReqId)) || (ret != HC_SUCCESS)) {
985         LOGE("get param error, type %d", PARAM_TYPE_REQID);
986         return HC_ERR_IPC_BAD_PARAM;
987     }
988     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_AUTH_PARAMS, (uint8_t *)&authParams, NULL);
989     if ((authParams == NULL) || (ret != HC_SUCCESS)) {
990         LOGE("get param error, type %d", PARAM_TYPE_AUTH_PARAMS);
991         return HC_ERR_IPC_BAD_PARAM;
992     }
993     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_DEV_AUTH_CB, (uint8_t *)&gaCallback, NULL);
994     if (ret != HC_SUCCESS) {
995         LOGE("get param error, type %d", PARAM_TYPE_DEV_AUTH_CB);
996         return ret;
997     }
998 
999     /* add call back */
1000     ret = AddIpcCallBackByReqId(authReqId, (const uint8_t *)gaCallback,
1001         sizeof(DeviceAuthCallback), CB_TYPE_TMP_DEV_AUTH);
1002     if (ret != HC_SUCCESS) {
1003         LOGE("add ipc callback failed");
1004         return HC_ERROR;
1005     }
1006     inOutLen = sizeof(cbObjIdx);
1007     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_CB_OBJECT, (uint8_t *)&cbObjIdx, &inOutLen);
1008     if (ret != HC_SUCCESS) {
1009         LOGE("get param error, type %d", PARAM_TYPE_CB_OBJECT);
1010         DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1011         return ret;
1012     }
1013     AddIpcCbObjByReqId(authReqId, cbObjIdx, CB_TYPE_TMP_DEV_AUTH);
1014     InitDeviceAuthCbCtx(&g_authCbAdt, CB_TYPE_TMP_DEV_AUTH);
1015     callRet = g_groupAuthMgrMethod.authDevice(osAccountId, authReqId, authParams, &g_authCbAdt);
1016     if (callRet != HC_SUCCESS) {
1017         DelIpcCallBackByReqId(authReqId, CB_TYPE_TMP_DEV_AUTH, true);
1018     }
1019     ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_IPC_RESULT, (const uint8_t *)&callRet, sizeof(int32_t));
1020     LOGI("process done, call ret %d, ipc ret %d", callRet, ret);
1021     return ret;
1022 }
1023 
IpcServiceGaCancelRequest(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1024 static int32_t IpcServiceGaCancelRequest(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1025 {
1026     int32_t ret;
1027     int64_t requestId = 0;
1028     const char *appId = NULL;
1029 
1030     LOGI("starting ...");
1031     int32_t inOutLen = sizeof(int64_t);
1032     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_REQID, (uint8_t *)&requestId, &inOutLen);
1033     if ((inOutLen != sizeof(requestId)) || (ret != HC_SUCCESS)) {
1034         LOGE("get param error, type %d", PARAM_TYPE_REQID);
1035         return HC_ERR_IPC_BAD_PARAM;
1036     }
1037     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_APPID, (uint8_t *)&appId, NULL);
1038     if ((appId == NULL) || (ret != HC_SUCCESS)) {
1039         LOGE("get param error, type %d", PARAM_TYPE_APPID);
1040         return HC_ERR_IPC_BAD_PARAM;
1041     }
1042 
1043     g_groupAuthMgrMethod.cancelRequest(requestId, appId);
1044     LOGI("process done, ipc ret %d", ret);
1045     return ret;
1046 }
1047 
IpcServiceGaGetRealInfo(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1048 static int32_t IpcServiceGaGetRealInfo(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1049 {
1050     int32_t ret;
1051     int32_t osAccountId;
1052     const char *pseudonymId = NULL;
1053 
1054     LOGI("starting ...");
1055     int32_t inOutLen = sizeof(int64_t);
1056     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1057     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
1058         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
1059         return HC_ERR_IPC_BAD_PARAM;
1060     }
1061     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_PSEUDONYM_ID, (uint8_t *)&pseudonymId, NULL);
1062     if ((pseudonymId == NULL) || (ret != HC_SUCCESS)) {
1063         LOGE("get param error, type %d", PARAM_TYPE_PSEUDONYM_ID);
1064         return HC_ERR_IPC_BAD_PARAM;
1065     }
1066 
1067     char *realInfo = NULL;
1068     ret = g_groupAuthMgrMethod.getRealInfo(osAccountId, pseudonymId, &realInfo);
1069     if ((realInfo != NULL) && (ret == HC_SUCCESS)) {
1070         ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)realInfo,
1071             strlen(realInfo) + 1);
1072         HcFree(realInfo);
1073     } else {
1074         ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1075     }
1076     LOGI("process done, ipc ret %d", ret);
1077     return ret;
1078 }
1079 
IpcServiceGaGetPseudonymId(const IpcDataInfo * ipcParams,int32_t paramNum,uintptr_t outCache)1080 static int32_t IpcServiceGaGetPseudonymId(const IpcDataInfo *ipcParams, int32_t paramNum, uintptr_t outCache)
1081 {
1082     int32_t ret;
1083     int32_t osAccountId;
1084     const char *indexKey = NULL;
1085 
1086     LOGI("starting ...");
1087     int32_t inOutLen = sizeof(int64_t);
1088     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_OS_ACCOUNT_ID, (uint8_t *)&osAccountId, &inOutLen);
1089     if ((inOutLen != sizeof(int32_t)) || (ret != HC_SUCCESS)) {
1090         LOGE("get param error, type %d", PARAM_TYPE_OS_ACCOUNT_ID);
1091         return HC_ERR_IPC_BAD_PARAM;
1092     }
1093     ret = GetIpcRequestParamByType(ipcParams, paramNum, PARAM_TYPE_INDEX_KEY, (uint8_t *)&indexKey, NULL);
1094     if ((indexKey == NULL) || (ret != HC_SUCCESS)) {
1095         LOGE("get param error, type %d", PARAM_TYPE_INDEX_KEY);
1096         return HC_ERR_IPC_BAD_PARAM;
1097     }
1098 
1099     char *pseudonymId = NULL;
1100     ret = g_groupAuthMgrMethod.getPseudonymId(osAccountId, indexKey, &pseudonymId);
1101     if ((pseudonymId != NULL) && (ret == HC_SUCCESS)) {
1102         ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, (const uint8_t *)pseudonymId,
1103             strlen(pseudonymId) + 1);
1104         HcFree(pseudonymId);
1105     } else {
1106         ret = IpcEncodeCallReplay(outCache, PARAM_TYPE_RETURN_DATA, NULL, 0);
1107     }
1108     LOGI("process done, ipc ret %d", ret);
1109     return ret;
1110 }
1111 
AddMethodMap(uintptr_t ipcInstance)1112 int32_t AddMethodMap(uintptr_t ipcInstance)
1113 {
1114     uint32_t ret;
1115 
1116     // Group Manager Interfaces
1117     ret = SetIpcCallMap(ipcInstance, IpcServiceGmRegCallback, IPC_CALL_ID_REG_CB);
1118     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnRegCallback, IPC_CALL_ID_UNREG_CB);
1119     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmRegDataChangeListener, IPC_CALL_ID_REG_LISTENER);
1120     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmUnRegDataChangeListener, IPC_CALL_ID_UNREG_LISTENER);
1121     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCreateGroup, IPC_CALL_ID_CREATE_GROUP);
1122     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelGroup, IPC_CALL_ID_DEL_GROUP);
1123     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddMemberToGroup, IPC_CALL_ID_ADD_GROUP_MEMBER);
1124     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelMemberFromGroup, IPC_CALL_ID_DEL_GROUP_MEMBER);
1125     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmAddMultiMembersToGroup, IPC_CALL_ID_ADD_MULTI_GROUP_MEMBERS);
1126     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmDelMultiMembersFromGroup, IPC_CALL_ID_DEL_MULTI_GROUP_MEMBERS);
1127     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmProcessData, IPC_CALL_ID_GM_PROC_DATA);
1128     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmApplyRegisterInfo, IPC_CALL_ID_APPLY_REG_INFO);
1129     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCheckAccessToGroup, IPC_CALL_ID_CHECK_ACCESS_TO_GROUP);
1130     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetPkInfoList, IPC_CALL_ID_GET_PK_INFO_LIST);
1131     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupInfoById, IPC_CALL_ID_GET_GROUP_INFO);
1132     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetGroupInfo, IPC_CALL_ID_SEARCH_GROUPS);
1133     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetJoinedGroups, IPC_CALL_ID_GET_JOINED_GROUPS);
1134     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetRelatedGroups, IPC_CALL_ID_GET_RELATED_GROUPS);
1135     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetDeviceInfoById, IPC_CALL_ID_GET_DEV_INFO_BY_ID);
1136     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmGetTrustedDevices, IPC_CALL_ID_GET_TRUST_DEVICES);
1137     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmIsDeviceInGroup, IPC_CALL_ID_IS_DEV_IN_GROUP);
1138     ret &= SetIpcCallMap(ipcInstance, IpcServiceGmCancelRequest, IPC_CALL_GM_CANCEL_REQUEST);
1139 
1140     // Group Auth Interfaces
1141     ret &= SetIpcCallMap(ipcInstance, IpcServiceGaProcessData, IPC_CALL_ID_GA_PROC_DATA);
1142     ret &= SetIpcCallMap(ipcInstance, IpcServiceGaAuthDevice, IPC_CALL_ID_AUTH_DEVICE);
1143     ret &= SetIpcCallMap(ipcInstance, IpcServiceGaCancelRequest, IPC_CALL_GA_CANCEL_REQUEST);
1144     ret &= SetIpcCallMap(ipcInstance, IpcServiceGaGetRealInfo, IPC_CALL_ID_GET_REAL_INFO);
1145     ret &= SetIpcCallMap(ipcInstance, IpcServiceGaGetPseudonymId, IPC_CALL_ID_GET_PSEUDONYM_ID);
1146     LOGI("process done, ret %u", ret);
1147     return ret;
1148 }
1149 
DeMainRescInit(uintptr_t * serviceCtx)1150 void DeMainRescInit(uintptr_t *serviceCtx)
1151 {
1152     if (g_devGroupMgrMethod.unRegDataChangeListener != NULL) {
1153         (void)g_devGroupMgrMethod.unRegDataChangeListener(g_serviceAppId);
1154     }
1155     DeInitIpcCallBackList();
1156     DestroyServiceInstance(serviceCtx);
1157     return;
1158 }
1159 
MainRescInit(void)1160 int32_t MainRescInit(void)
1161 {
1162     int32_t ret;
1163     const DeviceGroupManager *gmInst = NULL;
1164     const GroupAuthManager *gaInst = NULL;
1165 
1166     LOGI("starting ...");
1167     ret = InitIpcCallBackList();
1168     if (ret != HC_SUCCESS) {
1169         return ret;
1170     }
1171     gmInst = GetGmInstance();
1172     gaInst = GetGaInstance();
1173     if ((gmInst == NULL) || (gaInst == NULL)) {
1174         DeInitIpcCallBackList();
1175         LOGE("MainInit, GetGmInstance failed");
1176         return HC_ERROR;
1177     }
1178     g_devGroupMgrMethod = (DeviceGroupManager)(*gmInst);
1179     g_groupAuthMgrMethod = (GroupAuthManager)(*gaInst);
1180     InitDevAuthListenerCbCtx(&g_listenCbAdt);
1181     ret = gmInst->regDataChangeListener(g_serviceAppId, &g_listenCbAdt);
1182     if (ret != HC_SUCCESS) {
1183         DeInitIpcCallBackList();
1184         LOGE("MainInit, register ipc listener failed, ret %d", ret);
1185         return HC_ERROR;
1186     }
1187 
1188     LOGI("process done");
1189     return HC_SUCCESS;
1190 }
1191 
1192 #ifndef DEV_AUTH_FUZZ_TEST
main(int32_t argc,char const * argv[])1193 int32_t main(int32_t argc, char const *argv[])
1194 {
1195     uintptr_t serviceCtx = 0x0;
1196     int32_t ret;
1197     HcCondition cond;
1198 
1199     (void)argc;
1200     (void)argv;
1201     LOGI("device authentication service starting ...");
1202     ret = InitDeviceAuthService();
1203     if (ret != HC_SUCCESS) {
1204         LOGE("device auth service main, InitDeviceAuthService failed, ret %d", ret);
1205         return 1;
1206     }
1207 
1208     ret = MainRescInit();
1209     if (ret != HC_SUCCESS) {
1210         DestroyDeviceAuthService();
1211         LOGE("device auth service main, init work failed");
1212         return 1;
1213     }
1214 
1215     ret = AddDevAuthServiceToManager(&serviceCtx);
1216     if (ret != HC_SUCCESS) {
1217         DeMainRescInit(&serviceCtx);
1218         DestroyDeviceAuthService();
1219         serviceCtx = 0x0;
1220         LOGE("device auth service main, AddDevAuthServiceToManager failed, ret %d", ret);
1221         return 1;
1222     }
1223     (void)AddMethodMap(serviceCtx);
1224     LOGI("device authentication service register to IPC manager done, service running...");
1225     (void)memset_s(&cond, sizeof(cond), 0, sizeof(cond));
1226     InitHcCond(&cond, NULL);
1227     cond.wait(&cond);
1228     DestroyHcCond(&cond);
1229     return 0;
1230 }
1231 #endif
1232 
1233 #ifdef __cplusplus
1234 }
1235 #endif
1236