1 /*
2 * Copyright (C) 2022 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 "dbinder_ipc_adapter.h"
17
18 #include "rpc_errno.h"
19 #include "rpc_log.h"
20 #include "securec.h"
21
IsSameStub(DBinderServiceStub * stub,const char * serviceName,const char * deviceID,uintptr_t binderObject)22 bool IsSameStub(DBinderServiceStub *stub, const char *serviceName,
23 const char *deviceID, uintptr_t binderObject)
24 {
25 if (stub == NULL) {
26 return false;
27 }
28 return (strcmp(stub->serviceName, serviceName) == 0 && strcmp(stub->deviceID, deviceID) == 0
29 && stub->binderObject == binderObject);
30 }
31
RpcGetSystemAbility(int32_t systemAbility)32 ProxyObject *RpcGetSystemAbility(int32_t systemAbility)
33 {
34 IpcIo reply;
35 uint8_t replyAlloc[RPC_IPC_LENGTH];
36 IpcIoInit(&reply, replyAlloc, RPC_IPC_LENGTH, 0);
37 if (GetSystemAbilityById(systemAbility, &reply) != ERR_NONE) {
38 RPC_LOG_ERROR("GetSystemAbilityById failed");
39 return NULL;
40 }
41 SvcIdentity target;
42 ReadRemoteObject(&reply, &target);
43
44 ProxyObject *proxyObject = (ProxyObject *)calloc(1, sizeof(ProxyObject));
45 if (proxyObject == NULL) {
46 return NULL;
47 }
48 proxyObject->proxy = (SvcIdentity *)malloc(sizeof(SvcIdentity));
49 if (proxyObject->proxy == NULL) {
50 free(proxyObject);
51 return NULL;
52 }
53
54 if (memcpy_s(proxyObject->proxy, sizeof(SvcIdentity), &target, sizeof(SvcIdentity)) != EOK) {
55 free(proxyObject->proxy);
56 free(proxyObject);
57 return NULL;
58 }
59
60 return proxyObject;
61 }