1 /*
2 * Copyright (c) 2021 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/storage_daemon_proxy.h"
17 #include "storage_service_errno.h"
18 #include "storage_service_log.h"
19
20 namespace OHOS {
21 namespace StorageDaemon {
StorageDaemonProxy(const sptr<IRemoteObject> & impl)22 StorageDaemonProxy::StorageDaemonProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IStorageDaemon>(impl)
23 {}
24
Shutdown()25 int32_t StorageDaemonProxy::Shutdown()
26 {
27 MessageParcel data, reply;
28 MessageOption option(MessageOption::TF_SYNC);
29
30 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
31 return E_IPC_ERROR;
32 }
33
34 return Remote()->SendRequest(SHUTDOWN, data, reply, option);
35 }
36
Mount(std::string volId,uint32_t flags)37 int32_t StorageDaemonProxy::Mount(std::string volId, uint32_t flags)
38 {
39 MessageParcel data, reply;
40 MessageOption option(MessageOption::TF_SYNC);
41 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
42 return E_IPC_ERROR;
43 }
44
45 if (!data.WriteString(volId)) {
46 return E_IPC_ERROR;
47 }
48
49 if (!data.WriteUint32(flags)) {
50 return E_IPC_ERROR;
51 }
52
53 int err = Remote()->SendRequest(MOUNT, data, reply, option);
54 if (err != E_OK) {
55 return E_IPC_ERROR;
56 }
57
58 return reply.ReadInt32();
59 }
60
UMount(std::string volId)61 int32_t StorageDaemonProxy::UMount(std::string volId)
62 {
63 MessageParcel data, reply;
64 MessageOption option(MessageOption::TF_SYNC);
65 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
66 return E_IPC_ERROR;
67 }
68
69 if (!data.WriteString(volId)) {
70 return E_IPC_ERROR;
71 }
72
73 int err = Remote()->SendRequest(UMOUNT, data, reply, option);
74 if (err != E_OK) {
75 return E_IPC_ERROR;
76 }
77
78 return reply.ReadInt32();
79 }
80
Check(std::string volId)81 int32_t StorageDaemonProxy::Check(std::string volId)
82 {
83 MessageParcel data, reply;
84 MessageOption option(MessageOption::TF_SYNC);
85 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
86 return E_IPC_ERROR;
87 }
88
89 if (!data.WriteString(volId)) {
90 return E_IPC_ERROR;
91 }
92
93 int err = Remote()->SendRequest(CHECK, data, reply, option);
94 if (err != E_OK) {
95 return E_IPC_ERROR;
96 }
97
98 return reply.ReadInt32();
99 }
100
Format(std::string volId,std::string fsType)101 int32_t StorageDaemonProxy::Format(std::string volId, std::string fsType)
102 {
103 MessageParcel data, reply;
104 MessageOption option(MessageOption::TF_SYNC);
105 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
106 return E_IPC_ERROR;
107 }
108
109 if (!data.WriteString(volId)) {
110 return E_IPC_ERROR;
111 }
112
113 if (!data.WriteString(fsType)) {
114 return E_IPC_ERROR;
115 }
116
117 int err = Remote()->SendRequest(FORMAT, data, reply, option);
118 if (err != E_OK) {
119 return E_IPC_ERROR;
120 }
121
122 return reply.ReadInt32();
123 }
124
Partition(std::string diskId,int32_t type)125 int32_t StorageDaemonProxy::Partition(std::string diskId, int32_t type)
126 {
127 MessageParcel data, reply;
128 MessageOption option(MessageOption::TF_SYNC);
129 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
130 return E_IPC_ERROR;
131 }
132
133 if (!data.WriteString(diskId)) {
134 return E_IPC_ERROR;
135 }
136
137 if (!data.WriteInt32(type)) {
138 return E_IPC_ERROR;
139 }
140
141 int err = Remote()->SendRequest(PARTITION, data, reply, option);
142 if (err != E_OK) {
143 return E_IPC_ERROR;
144 }
145
146 return reply.ReadInt32();
147 }
148
PrepareUserDirs(int32_t userId,uint32_t flags)149 int32_t StorageDaemonProxy::PrepareUserDirs(int32_t userId, uint32_t flags)
150 {
151 MessageParcel data, reply;
152 MessageOption option(MessageOption::TF_SYNC);
153
154 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
155 return E_IPC_ERROR;
156 }
157
158 if (!data.WriteInt32(userId)) {
159 return E_IPC_ERROR;
160 }
161
162 if (!data.WriteUint32(flags)) {
163 return E_IPC_ERROR;
164 }
165
166 int err = Remote()->SendRequest(PREPARE_USER_DIRS, data, reply, option);
167 if (err != E_OK) {
168 return E_IPC_ERROR;
169 }
170
171 return reply.ReadInt32();
172 }
173
DestroyUserDirs(int32_t userId,uint32_t flags)174 int32_t StorageDaemonProxy::DestroyUserDirs(int32_t userId, uint32_t flags)
175 {
176 MessageParcel data, reply;
177 MessageOption option(MessageOption::TF_SYNC);
178
179 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
180 return E_IPC_ERROR;
181 }
182
183 if (!data.WriteInt32(userId)) {
184 return E_IPC_ERROR;
185 }
186
187 if (!data.WriteUint32(flags)) {
188 return E_IPC_ERROR;
189 }
190
191 int err = Remote()->SendRequest(DESTROY_USER_DIRS, data, reply, option);
192 if (err != E_OK) {
193 return E_IPC_ERROR;
194 }
195
196 return reply.ReadInt32();
197 }
198
StartUser(int32_t userId)199 int32_t StorageDaemonProxy::StartUser(int32_t userId)
200 {
201 MessageParcel data, reply;
202 MessageOption option(MessageOption::TF_SYNC);
203
204 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
205 return E_IPC_ERROR;
206 }
207
208 if (!data.WriteInt32(userId)) {
209 return E_IPC_ERROR;
210 }
211
212 int err = Remote()->SendRequest(START_USER, data, reply, option);
213 if (err != E_OK) {
214 return E_IPC_ERROR;
215 }
216
217 return reply.ReadInt32();
218 }
219
StopUser(int32_t userId)220 int32_t StorageDaemonProxy::StopUser(int32_t userId)
221 {
222 MessageParcel data, reply;
223 MessageOption option(MessageOption::TF_SYNC);
224
225 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
226 return E_IPC_ERROR;
227 }
228
229 if (!data.WriteInt32(userId)) {
230 return E_IPC_ERROR;
231 }
232
233 int err = Remote()->SendRequest(STOP_USER, data, reply, option);
234 if (err != E_OK) {
235 return E_IPC_ERROR;
236 }
237
238 return reply.ReadUint32();
239 }
240
InitGlobalKey(void)241 int32_t StorageDaemonProxy::InitGlobalKey(void)
242 {
243 MessageParcel data, reply;
244 MessageOption option(MessageOption::TF_SYNC);
245 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
246 return E_IPC_ERROR;
247 }
248
249 int err = Remote()->SendRequest(INIT_GLOBAL_KEY, data, reply, option);
250 if (err != E_OK) {
251 return E_IPC_ERROR;
252 }
253
254 return reply.ReadUint32();
255 }
256
InitGlobalUserKeys(void)257 int32_t StorageDaemonProxy::InitGlobalUserKeys(void)
258 {
259 MessageParcel data, reply;
260 MessageOption option(MessageOption::TF_SYNC);
261 LOGI("start");
262 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
263 return E_IPC_ERROR;
264 }
265
266 int err = Remote()->SendRequest(INIT_GLOBAL_USER_KEYS, data, reply, option);
267 if (err != E_OK) {
268 return E_IPC_ERROR;
269 }
270
271 return reply.ReadUint32();
272 }
273
GenerateUserKeys(uint32_t userId,uint32_t flags)274 int32_t StorageDaemonProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
275 {
276 MessageParcel data, reply;
277 MessageOption option(MessageOption::TF_SYNC);
278
279 LOGI("start");
280 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
281 return E_IPC_ERROR;
282 }
283
284 if (!data.WriteUint32(userId)) {
285 return E_IPC_ERROR;
286 }
287 if (!data.WriteUint32(flags)) {
288 return E_IPC_ERROR;
289 }
290
291 int err = Remote()->SendRequest(CREATE_USER_KEYS, data, reply, option);
292 if (err != E_OK) {
293 return E_IPC_ERROR;
294 }
295
296 return reply.ReadUint32();
297 }
298
DeleteUserKeys(uint32_t userId)299 int32_t StorageDaemonProxy::DeleteUserKeys(uint32_t userId)
300 {
301 MessageParcel data, reply;
302 MessageOption option(MessageOption::TF_SYNC);
303
304 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
305 return E_IPC_ERROR;
306 }
307
308 if (!data.WriteUint32(userId)) {
309 return E_IPC_ERROR;
310 }
311 int err = Remote()->SendRequest(DELETE_USER_KEYS, data, reply, option);
312 if (err != E_OK) {
313 return E_IPC_ERROR;
314 }
315
316 return reply.ReadInt32();
317 }
318
UpdateUserAuth(uint32_t userId,std::string auth,std::string compSecret)319 int32_t StorageDaemonProxy::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
320 {
321 MessageParcel data, reply;
322 MessageOption option(MessageOption::TF_SYNC);
323
324 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
325 return E_IPC_ERROR;
326 }
327
328 if (!data.WriteUint32(userId)) {
329 return E_IPC_ERROR;
330 }
331 int err = Remote()->SendRequest(UPDATE_USER_AUTH, data, reply, option);
332 if (err != E_OK) {
333 return E_IPC_ERROR;
334 }
335
336 return reply.ReadInt32();
337 }
338
ActiveUserKey(uint32_t userId,std::string auth,std::string compSecret)339 int32_t StorageDaemonProxy::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
340 {
341 MessageParcel data, reply;
342 MessageOption option(MessageOption::TF_SYNC);
343
344 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
345 return E_IPC_ERROR;
346 }
347
348 if (!data.WriteUint32(userId)) {
349 return E_IPC_ERROR;
350 }
351
352 int err = Remote()->SendRequest(ACTIVE_USER_KEY, data, reply, option);
353 if (err != E_OK) {
354 return E_IPC_ERROR;
355 }
356
357 return reply.ReadInt32();
358 }
359
InactiveUserKey(uint32_t userId)360 int32_t StorageDaemonProxy::InactiveUserKey(uint32_t userId)
361 {
362 MessageParcel data, reply;
363 MessageOption option(MessageOption::TF_SYNC);
364
365 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
366 return E_IPC_ERROR;
367 }
368
369 if (!data.WriteUint32(userId)) {
370 return E_IPC_ERROR;
371 }
372 int err = Remote()->SendRequest(INACTIVE_USER_KEY, data, reply, option);
373 if (err != E_OK) {
374 return E_IPC_ERROR;
375 }
376
377 return reply.ReadInt32();
378 }
379
UpdateKeyContext(uint32_t userId)380 int32_t StorageDaemonProxy::UpdateKeyContext(uint32_t userId)
381 {
382 MessageParcel data, reply;
383 MessageOption option(MessageOption::TF_SYNC);
384
385 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
386 return E_IPC_ERROR;
387 }
388
389 if (!data.WriteUint32(userId)) {
390 return E_IPC_ERROR;
391 }
392 int err = Remote()->SendRequest(UPDATE_KEY_CONTEXT, data, reply, option);
393 if (err != E_OK) {
394 return E_IPC_ERROR;
395 }
396
397 return reply.ReadInt32();
398 }
399 } // StorageDaemon
400 } // OHOS