1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
From 31f1a71fee10a1248de00ea1f36eeaf80e683673 Mon Sep 17 00:00:00 2001
From: "beiling.xie" <xiekunxun@huawei.com>
Date: Fri, 16 Sep 2022 01:11:40 +0800
Subject: [PATCH] adapter deviceauth ipc service
Signed-off-by: beiling.xie <xiekunxun@huawei.com>
---
frameworks/inc/ipc_service.h | 2 ++
frameworks/src/ipc_service.c | 16 +-----------
frameworks/src/standard/ipc_adapt.cpp | 18 +++++++------
.../src/standard/ipc_dev_auth_proxy.cpp | 25 ++++---------------
frameworks/src/standard/ipc_dev_auth_stub.cpp | 7 +-----
services/BUILD.gn | 15 ++++++++++-
services/device_auth.c | 6 +++++
7 files changed, 39 insertions(+), 50 deletions(-)
diff --git a/frameworks/inc/ipc_service.h b/frameworks/inc/ipc_service.h
index e3eb11b..ed73555 100755
--- a/frameworks/inc/ipc_service.h
+++ b/frameworks/inc/ipc_service.h
@@ -20,6 +20,8 @@
extern "C" {
#endif
+int DeviceAuthIpcInit();
+
#ifdef __cplusplus
}
#endif
diff --git a/frameworks/src/ipc_service.c b/frameworks/src/ipc_service.c
index afc21fc..3db6bb5 100644
--- a/frameworks/src/ipc_service.c
+++ b/frameworks/src/ipc_service.c
@@ -1038,20 +1038,10 @@ int32_t MainRescInit(void)
return HC_SUCCESS;
}
-int32_t main(int32_t argc, char const *argv[])
+int DeviceAuthIpcInit()
{
uintptr_t serviceCtx = 0x0;
int32_t ret;
- HcCondition cond;
-
- (void)argc;
- (void)argv;
- LOGI("device authentication service starting ...");
- ret = InitDeviceAuthService();
- if (ret != HC_SUCCESS) {
- LOGE("device auth service main, InitDeviceAuthService failed, ret %d", ret);
- return 1;
- }
ret = MainRescInit();
if (ret != HC_SUCCESS) {
@@ -1070,10 +1060,6 @@ int32_t main(int32_t argc, char const *argv[])
}
(void)AddMethodMap(serviceCtx);
LOGI("device authentication service register to IPC manager done, service running...");
- (void)memset_s(&cond, sizeof(cond), 0, sizeof(cond));
- InitHcCond(&cond, NULL);
- cond.wait(&cond);
- DestroyHcCond(&cond);
return 0;
}
diff --git a/frameworks/src/standard/ipc_adapt.cpp b/frameworks/src/standard/ipc_adapt.cpp
index 3dd4ec8..3910726 100644
--- a/frameworks/src/standard/ipc_adapt.cpp
+++ b/frameworks/src/standard/ipc_adapt.cpp
@@ -23,12 +23,14 @@
#include "ipc_dev_auth_stub.h"
#include "ipc_sdk.h"
#include "ipc_service.h"
-#include "iservice_registry.h"
#include "securec.h"
#include "system_ability_definition.h"
+#include "ipc_center.h"
+
using namespace std;
using namespace OHOS;
+static IpcCenter *g_deviceIpc = nullptr;
namespace {
static const int32_t BUFF_MAX_SZ = 128;
static const int32_t IPC_CALL_BACK_MAX_NODES = 64;
@@ -1335,19 +1337,19 @@ void DestroyServiceInstance(uintptr_t *ipcInstance)
int32_t AddDevAuthServiceToManager(uintptr_t *serviceCtx)
{
- int32_t ret = ERR_OK;
+ int32_t ret = HC_SUCCESS;
ServiceDevAuth *sPtr = nullptr;
- sptr<ISystemAbilityManager> sysMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
- if (sysMgr == nullptr) {
- return HC_ERR_IPC_GET_SERVICE;
- }
sPtr = new(std::nothrow) ServiceDevAuth();
if (sPtr == nullptr) {
return HC_ERR_ALLOC_MEMORY;
}
- ret = sysMgr->AddSystemAbility(DEVICE_AUTH_SERVICE_ID, sPtr);
- if (ret != ERR_OK) {
+ sPtr->isDSoftBusObj = false;
+ if (!g_deviceIpc->Init(true, static_cast<IPCObjectStub*>(sPtr))) {
+ LOGE("deviceIpc init failed");
+ }
+ ret = IPCSkeleton::SetDeviceAuthObj(sPtr);
+ if (ret != true) {
LOGE("add service failed");
delete sPtr;
return HC_ERROR;
diff --git a/frameworks/src/standard/ipc_dev_auth_proxy.cpp b/frameworks/src/standard/ipc_dev_auth_proxy.cpp
index bc3abeb..c493f7a 100644
--- a/frameworks/src/standard/ipc_dev_auth_proxy.cpp
+++ b/frameworks/src/standard/ipc_dev_auth_proxy.cpp
@@ -19,9 +19,9 @@
#include "hc_log.h"
#include "ipc_adapt.h"
#include "ipc_sdk.h"
-#include "iservice_registry.h"
#include "system_ability_definition.h"
+
namespace OHOS {
ProxyDevAuth::ProxyDevAuth(const sptr<IRemoteObject> &impl) : IRemoteProxy<IMethodsIpcCall>(impl)
{}
@@ -33,7 +33,7 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re
{
int32_t ret;
sptr<IRemoteObject> remote = nullptr;
- MessageOption option = { MessageOption::TF_SYNC };
+ MessageOption option;
LOGI("ProxyDevAuth, SendRequest...");
remote = Remote();
@@ -42,9 +42,6 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re
return HC_ERR_IPC_INTERNAL_FAILED;
}
- if (withSync == false) {
- option = { MessageOption::TF_ASYNC };
- }
ret = remote->SendRequest(DEV_AUTH_CALL_REQUEST, dataParcel, replyParcel, option);
LOGI("SendRequest done, ret %d", ret);
(ret == ERR_NONE) ? replyParcel.ReadInt32(ret) : (ret = HC_ERR_IPC_INTERNAL_FAILED);
@@ -53,15 +50,8 @@ int32_t ProxyDevAuth::DoCallRequest(MessageParcel &dataParcel, MessageParcel &re
bool ProxyDevAuth::ServiceRunning(void)
{
- auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
- if (saMgr == nullptr) {
- return false;
- }
- auto daSa = saMgr->GetSystemAbility(DEVICE_AUTH_SERVICE_ID);
- if (daSa == nullptr) {
- return false;
- }
- return true;
+ auto daSa = IPCSkeleton::GetDeviceAuthObj();
+ return daSa != nullptr;
}
int32_t ProxyDevAuthData::EncodeCallRequest(int32_t type, const uint8_t *param, int32_t paramSz)
@@ -117,12 +107,7 @@ int32_t ProxyDevAuthData::FinalCallRequest(int32_t methodId)
sptr<ProxyDevAuth> ProxyDevAuthData::GetProxy() const
{
- auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
- if (saMgr == nullptr) {
- LOGE("GetSystemAbilityManager failed");
- return nullptr;
- }
- auto daSa = saMgr->GetSystemAbility(DEVICE_AUTH_SERVICE_ID);
+ auto daSa = IPCSkeleton::GetDeviceAuthObj();
if (daSa == nullptr) {
LOGE("GetSystemAbility failed");
return nullptr;
diff --git a/frameworks/src/standard/ipc_dev_auth_stub.cpp b/frameworks/src/standard/ipc_dev_auth_stub.cpp
index e33b770..648bc3b 100644
--- a/frameworks/src/standard/ipc_dev_auth_stub.cpp
+++ b/frameworks/src/standard/ipc_dev_auth_stub.cpp
@@ -286,12 +286,7 @@ void ServiceDevAuth::ActCallback(int32_t objIdx, int32_t callbackId, bool sync,
LOGW("nothing to do, callback id %d, remote object id %d", callbackId, objIdx);
return;
}
- MessageOption option(MessageOption::TF_SYNC);
- option.SetWaitTime(DEV_AUTH_CALL_WAIT_TIME);
- if (!sync) {
- option.SetFlags(MessageOption::TF_ASYNC);
- option.SetWaitTime(0);
- }
+ MessageOption option;
std::lock_guard<std::mutex> autoLock(g_cBMutex);
sptr<ICommIpcCallback> proxy = iface_cast<ICommIpcCallback>(g_cbStub[objIdx].cbStub);
proxy->DoCallBack(callbackId, cbHook, dataParcel, reply, option);
diff --git a/services/BUILD.gn b/services/BUILD.gn
index b2cdb17..ce6e24b 100644
--- a/services/BUILD.gn
+++ b/services/BUILD.gn
@@ -142,9 +142,14 @@ if (defined(ohos_lite)) {
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
"//third_party/json/include",
+ "${frameworks_path}/inc",
+ "${dev_frameworks_path}/inc/permission_adapter",
]
sources = deviceauth_files
+ sources += deviceauth_ipc_files
+ sources += permission_adapter_files
+ sources += [ "${frameworks_path}/src/ipc_service.c" ]
cflags = [ "-DHILOG_ENABLE" ]
defines = deviceauth_defines
cflags += build_flags
@@ -164,6 +169,7 @@ if (defined(ohos_lite)) {
external_deps = [
"hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
]
if (support_jsapi) {
external_deps += [ "os_account_standard:os_account_innerkits" ]
@@ -238,6 +244,12 @@ if (defined(ohos_lite)) {
sources = deviceauth_ipc_files
sources += permission_adapter_files
sources += [ "${frameworks_path}/src/ipc_sdk.c" ]
+ sources += [ "${os_adapter_path}/impl/src/hc_log.c" ]
+ sources += [ "${os_adapter_path}/impl/src/linux/hc_types.c" ]
+ sources += [ "${os_adapter_path}/impl/src/hc_mutex.c" ]
+ sources += [ "${common_lib_path}/impl/src/json_utils.c" ]
+ sources += [ "${common_lib_path}/impl/src/string_util.c" ]
+ sources += [ "${common_lib_path}/impl/src/clib_types.c" ]
defines = [
"__LINUX__",
@@ -250,9 +262,10 @@ if (defined(ohos_lite)) {
}
deps = [
- "${deps_adapter_path}:${hal_module_name}",
"//third_party/cJSON:cjson_static",
"//utils/native/base:utils",
+ "//third_party/bounds_checking_function:libsec_shared",
+ "//third_party/cJSON:cjson_static",
]
external_deps = [
diff --git a/services/device_auth.c b/services/device_auth.c
index e09dce4..16f6200 100644
--- a/services/device_auth.c
+++ b/services/device_auth.c
@@ -14,6 +14,7 @@
*/
#include "device_auth.h"
+#include "ipc_service.h"
#include "alg_loader.h"
#include "callback_manager.h"
@@ -241,6 +242,11 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void)
DestroyGmAndGa();
return res;
}
+ res = DeviceAuthIpcInit();
+ if (res != HC_SUCCESS) {
+ DestroyGmAndGa();
+ return res;
+ }
SetInitStatus();
LOGI("[End]: [Service]: Init device auth service successfully!");
return HC_SUCCESS;
--
2.25.1
|