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 "ipc/storage_daemon_ipc_interface_code.h"
18 #include "storage_service_errno.h"
19 #include "storage_service_log.h"
20
21 namespace OHOS {
22 namespace StorageDaemon {
StorageDaemonProxy(const sptr<IRemoteObject> & impl)23 StorageDaemonProxy::StorageDaemonProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IStorageDaemon>(impl)
24 {}
25
Shutdown()26 int32_t StorageDaemonProxy::Shutdown()
27 {
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option(MessageOption::TF_SYNC);
31
32 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
33 return E_WRITE_DESCRIPTOR_ERR;
34 }
35
36 return SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::SHUTDOWN), data, reply, option);
37 }
38
Mount(const std::string & volId,uint32_t flags)39 int32_t StorageDaemonProxy::Mount(const std::string &volId, uint32_t flags)
40 {
41 MessageParcel data;
42 MessageParcel reply;
43 MessageOption option(MessageOption::TF_SYNC);
44 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
45 return E_WRITE_DESCRIPTOR_ERR;
46 }
47
48 if (!data.WriteString(volId)) {
49 return E_WRITE_PARCEL_ERR;
50 }
51
52 if (!data.WriteUint32(flags)) {
53 return E_WRITE_PARCEL_ERR;
54 }
55
56 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::MOUNT), data, reply, option);
57 if (err != E_OK) {
58 return err;
59 }
60
61 return reply.ReadInt32();
62 }
63
UMount(const std::string & volId)64 int32_t StorageDaemonProxy::UMount(const std::string &volId)
65 {
66 MessageParcel data;
67 MessageParcel reply;
68 MessageOption option(MessageOption::TF_SYNC);
69 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
70 return E_WRITE_DESCRIPTOR_ERR;
71 }
72
73 if (!data.WriteString(volId)) {
74 return E_WRITE_PARCEL_ERR;
75 }
76
77 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UMOUNT), data, reply, option);
78 if (err != E_OK) {
79 return err;
80 }
81
82 return reply.ReadInt32();
83 }
84
Check(const std::string & volId)85 int32_t StorageDaemonProxy::Check(const std::string &volId)
86 {
87 MessageParcel data;
88 MessageParcel reply;
89 MessageOption option(MessageOption::TF_SYNC);
90 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
91 return E_WRITE_DESCRIPTOR_ERR;
92 }
93
94 if (!data.WriteString(volId)) {
95 return E_WRITE_PARCEL_ERR;
96 }
97
98 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::CHECK), data, reply, option);
99 if (err != E_OK) {
100 return err;
101 }
102
103 return reply.ReadInt32();
104 }
105
Format(const std::string & volId,const std::string & fsType)106 int32_t StorageDaemonProxy::Format(const std::string &volId, const std::string &fsType)
107 {
108 MessageParcel data;
109 MessageParcel reply;
110 MessageOption option(MessageOption::TF_SYNC);
111 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
112 return E_WRITE_DESCRIPTOR_ERR;
113 }
114
115 if (!data.WriteString(volId)) {
116 return E_WRITE_PARCEL_ERR;
117 }
118
119 if (!data.WriteString(fsType)) {
120 return E_WRITE_PARCEL_ERR;
121 }
122
123 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::FORMAT), data, reply, option);
124 if (err != E_OK) {
125 return err;
126 }
127
128 return reply.ReadInt32();
129 }
130
Partition(const std::string & diskId,int32_t type)131 int32_t StorageDaemonProxy::Partition(const std::string &diskId, int32_t type)
132 {
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option(MessageOption::TF_SYNC);
136 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
137 return E_WRITE_DESCRIPTOR_ERR;
138 }
139
140 if (!data.WriteString(diskId)) {
141 return E_WRITE_PARCEL_ERR;
142 }
143
144 if (!data.WriteInt32(type)) {
145 return E_WRITE_PARCEL_ERR;
146 }
147
148 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::PARTITION), data, reply, option);
149 if (err != E_OK) {
150 return err;
151 }
152
153 return reply.ReadInt32();
154 }
155
SetVolumeDescription(const std::string & volId,const std::string & description)156 int32_t StorageDaemonProxy::SetVolumeDescription(const std::string &volId, const std::string &description)
157 {
158 MessageParcel data;
159 MessageParcel reply;
160 MessageOption option(MessageOption::TF_SYNC);
161 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
162 return E_WRITE_DESCRIPTOR_ERR;
163 }
164
165 if (!data.WriteString(volId)) {
166 return E_WRITE_PARCEL_ERR;
167 }
168
169 if (!data.WriteString(description)) {
170 return E_WRITE_PARCEL_ERR;
171 }
172
173 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::SET_VOL_DESC), data, reply, option);
174 if (err != E_OK) {
175 return err;
176 }
177
178 return reply.ReadInt32();
179 }
180
PrepareUserDirs(int32_t userId,uint32_t flags)181 int32_t StorageDaemonProxy::PrepareUserDirs(int32_t userId, uint32_t flags)
182 {
183 MessageParcel data;
184 MessageParcel reply;
185 MessageOption option(MessageOption::TF_SYNC);
186
187 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
188 return E_WRITE_DESCRIPTOR_ERR;
189 }
190
191 if (!data.WriteInt32(userId)) {
192 return E_WRITE_PARCEL_ERR;
193 }
194
195 if (!data.WriteUint32(flags)) {
196 return E_WRITE_PARCEL_ERR;
197 }
198
199 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::PREPARE_USER_DIRS), data, reply, option);
200 if (err != E_OK) {
201 return err;
202 }
203
204 return reply.ReadInt32();
205 }
206
DestroyUserDirs(int32_t userId,uint32_t flags)207 int32_t StorageDaemonProxy::DestroyUserDirs(int32_t userId, uint32_t flags)
208 {
209 MessageParcel data;
210 MessageParcel reply;
211 MessageOption option(MessageOption::TF_SYNC);
212
213 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
214 return E_WRITE_DESCRIPTOR_ERR;
215 }
216
217 if (!data.WriteInt32(userId)) {
218 return E_WRITE_PARCEL_ERR;
219 }
220
221 if (!data.WriteUint32(flags)) {
222 return E_WRITE_PARCEL_ERR;
223 }
224
225 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::DESTROY_USER_DIRS), data, reply, option);
226 if (err != E_OK) {
227 return err;
228 }
229
230 return reply.ReadInt32();
231 }
232
StartUser(int32_t userId)233 int32_t StorageDaemonProxy::StartUser(int32_t userId)
234 {
235 MessageParcel data;
236 MessageParcel reply;
237 MessageOption option(MessageOption::TF_SYNC);
238
239 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
240 return E_WRITE_DESCRIPTOR_ERR;
241 }
242
243 if (!data.WriteInt32(userId)) {
244 return E_WRITE_PARCEL_ERR;
245 }
246
247 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::START_USER), data, reply, option);
248 if (err != E_OK) {
249 return err;
250 }
251
252 return reply.ReadInt32();
253 }
254
StopUser(int32_t userId)255 int32_t StorageDaemonProxy::StopUser(int32_t userId)
256 {
257 MessageParcel data;
258 MessageParcel reply;
259 MessageOption option(MessageOption::TF_SYNC);
260
261 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
262 return E_WRITE_DESCRIPTOR_ERR;
263 }
264
265 if (!data.WriteInt32(userId)) {
266 return E_WRITE_PARCEL_ERR;
267 }
268
269 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::STOP_USER), data, reply, option);
270 if (err != E_OK) {
271 return err;
272 }
273
274 return reply.ReadUint32();
275 }
276
CompleteAddUser(int32_t userId)277 int32_t StorageDaemonProxy::CompleteAddUser(int32_t userId)
278 {
279 MessageParcel data;
280 MessageParcel reply;
281 MessageOption option(MessageOption::TF_SYNC);
282
283 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
284 return E_WRITE_DESCRIPTOR_ERR;
285 }
286
287 if (!data.WriteInt32(userId)) {
288 return E_WRITE_PARCEL_ERR;
289 }
290
291 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER), data, reply, option);
292 if (err != E_OK) {
293 return err;
294 }
295
296 return reply.ReadUint32();
297 }
298
InitGlobalKey(void)299 int32_t StorageDaemonProxy::InitGlobalKey(void)
300 {
301 MessageParcel data;
302 MessageParcel reply;
303 MessageOption option(MessageOption::TF_SYNC);
304 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
305 return E_WRITE_DESCRIPTOR_ERR;
306 }
307
308 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY), data, reply, option);
309 if (err != E_OK) {
310 return err;
311 }
312
313 return reply.ReadUint32();
314 }
315
InitGlobalUserKeys(void)316 int32_t StorageDaemonProxy::InitGlobalUserKeys(void)
317 {
318 MessageParcel data;
319 MessageParcel reply;
320 MessageOption option(MessageOption::TF_SYNC);
321 LOGI("start");
322 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
323 return E_WRITE_DESCRIPTOR_ERR;
324 }
325
326 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS), data, reply,
327 option);
328 if (err != E_OK) {
329 return err;
330 }
331
332 return reply.ReadUint32();
333 }
334
GenerateUserKeys(uint32_t userId,uint32_t flags)335 int32_t StorageDaemonProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
336 {
337 MessageParcel data;
338 MessageParcel reply;
339 MessageOption option(MessageOption::TF_SYNC);
340
341 LOGI("start");
342 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
343 return E_WRITE_DESCRIPTOR_ERR;
344 }
345
346 if (!data.WriteUint32(userId)) {
347 return E_WRITE_PARCEL_ERR;
348 }
349 if (!data.WriteUint32(flags)) {
350 return E_WRITE_PARCEL_ERR;
351 }
352
353 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::CREATE_USER_KEYS), data, reply, option);
354 if (err != E_OK) {
355 return err;
356 }
357
358 return reply.ReadUint32();
359 }
360
DeleteUserKeys(uint32_t userId)361 int32_t StorageDaemonProxy::DeleteUserKeys(uint32_t userId)
362 {
363 MessageParcel data;
364 MessageParcel reply;
365 MessageOption option(MessageOption::TF_SYNC);
366
367 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
368 return E_WRITE_DESCRIPTOR_ERR;
369 }
370
371 if (!data.WriteUint32(userId)) {
372 return E_WRITE_PARCEL_ERR;
373 }
374 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::DELETE_USER_KEYS), data, reply, option);
375 if (err != E_OK) {
376 return err;
377 }
378
379 return reply.ReadInt32();
380 }
381
UpdateUserAuth(uint32_t userId,uint64_t secureUid,const std::vector<uint8_t> & token,const std::vector<uint8_t> & oldSecret,const std::vector<uint8_t> & newSecret)382 int32_t StorageDaemonProxy::UpdateUserAuth(uint32_t userId, uint64_t secureUid,
383 const std::vector<uint8_t> &token,
384 const std::vector<uint8_t> &oldSecret,
385 const std::vector<uint8_t> &newSecret)
386 {
387 MessageParcel data;
388 MessageParcel reply;
389 MessageOption option(MessageOption::TF_SYNC);
390
391 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
392 return E_WRITE_DESCRIPTOR_ERR;
393 }
394
395 if (!data.WriteUint32(userId)) {
396 return E_WRITE_PARCEL_ERR;
397 }
398 if (!data.WriteUint64(secureUid)) {
399 return E_WRITE_PARCEL_ERR;
400 }
401 if (!data.WriteUInt8Vector(token)) {
402 return E_WRITE_PARCEL_ERR;
403 }
404 if (!data.WriteUInt8Vector(oldSecret)) {
405 return E_WRITE_PARCEL_ERR;
406 }
407 if (!data.WriteUInt8Vector(newSecret)) {
408 return E_WRITE_PARCEL_ERR;
409 }
410
411 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UPDATE_USER_AUTH), data, reply, option);
412 if (err != E_OK) {
413 return err;
414 }
415
416 return reply.ReadInt32();
417 }
418
ActiveUserKey(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)419 int32_t StorageDaemonProxy::ActiveUserKey(uint32_t userId,
420 const std::vector<uint8_t> &token,
421 const std::vector<uint8_t> &secret)
422 {
423 MessageParcel data;
424 MessageParcel reply;
425 MessageOption option(MessageOption::TF_SYNC);
426
427 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
428 return E_WRITE_DESCRIPTOR_ERR;
429 }
430
431 if (!data.WriteUint32(userId)) {
432 return E_WRITE_PARCEL_ERR;
433 }
434 if (!data.WriteUInt8Vector(token)) {
435 return E_WRITE_PARCEL_ERR;
436 }
437 if (!data.WriteUInt8Vector(secret)) {
438 return E_WRITE_PARCEL_ERR;
439 }
440
441 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::ACTIVE_USER_KEY), data, reply, option);
442 if (err != E_OK) {
443 return err;
444 }
445
446 return reply.ReadInt32();
447 }
448
InactiveUserKey(uint32_t userId)449 int32_t StorageDaemonProxy::InactiveUserKey(uint32_t userId)
450 {
451 MessageParcel data;
452 MessageParcel reply;
453 MessageOption option(MessageOption::TF_SYNC);
454
455 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
456 return E_WRITE_DESCRIPTOR_ERR;
457 }
458
459 if (!data.WriteUint32(userId)) {
460 return E_WRITE_PARCEL_ERR;
461 }
462 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::INACTIVE_USER_KEY), data, reply, option);
463 if (err != E_OK) {
464 return err;
465 }
466
467 return reply.ReadInt32();
468 }
469
LockUserScreen(uint32_t userId)470 int32_t StorageDaemonProxy::LockUserScreen(uint32_t userId)
471 {
472 MessageParcel data;
473 MessageParcel reply;
474 MessageOption option(MessageOption::TF_SYNC);
475
476 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
477 return E_WRITE_DESCRIPTOR_ERR;
478 }
479
480 if (!data.WriteUint32(userId)) {
481 return E_WRITE_PARCEL_ERR;
482 }
483 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::LOCK_USER_SCREEN), data, reply, option);
484 if (err != E_OK) {
485 return err;
486 }
487
488 return reply.ReadInt32();
489 }
490
UnlockUserScreen(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)491 int32_t StorageDaemonProxy::UnlockUserScreen(uint32_t userId,
492 const std::vector<uint8_t> &token,
493 const std::vector<uint8_t> &secret)
494 {
495 MessageParcel data;
496 MessageParcel reply;
497 MessageOption option(MessageOption::TF_SYNC);
498
499 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
500 return E_WRITE_DESCRIPTOR_ERR;
501 }
502
503 if (!data.WriteUint32(userId)) {
504 return E_WRITE_PARCEL_ERR;
505 }
506 if (!data.WriteUInt8Vector(token)) {
507 return E_WRITE_PARCEL_ERR;
508 }
509 if (!data.WriteUInt8Vector(secret)) {
510 return E_WRITE_PARCEL_ERR;
511 }
512 int32_t err = SendRequest(
513 static_cast<int32_t>(StorageDaemonInterfaceCode::UNLOCK_USER_SCREEN), data, reply, option);
514 if (err != E_OK) {
515 return err;
516 }
517
518 return reply.ReadInt32();
519 }
520
GetLockScreenStatus(uint32_t userId,bool & lockScreenStatus)521 int32_t StorageDaemonProxy::GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus)
522 {
523 MessageParcel data;
524 MessageParcel reply;
525 MessageOption option(MessageOption::TF_SYNC);
526
527 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
528 return E_WRITE_DESCRIPTOR_ERR;
529 }
530
531 if (!data.WriteUint32(userId)) {
532 return E_WRITE_PARCEL_ERR;
533 }
534 int32_t err = SendRequest(
535 static_cast<int32_t>(StorageDaemonInterfaceCode::LOCK_SCREEN_STATUS), data, reply, option);
536 if (err != E_OK) {
537 return err;
538 }
539 lockScreenStatus = reply.ReadBool();
540 return reply.ReadInt32();
541 }
542
GenerateAppkey(uint32_t userId,uint32_t hashId,std::string & keyId)543 int32_t StorageDaemonProxy::GenerateAppkey(uint32_t userId, uint32_t hashId, std::string &keyId)
544 {
545 MessageParcel data;
546 MessageParcel reply;
547 MessageOption option(MessageOption::TF_SYNC);
548
549 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
550 return E_WRITE_DESCRIPTOR_ERR;
551 }
552
553 if (!data.WriteUint32(userId)) {
554 return E_WRITE_PARCEL_ERR;
555 }
556 if (!data.WriteUint32(hashId)) {
557 return E_WRITE_PARCEL_ERR;
558 }
559 int32_t err = SendRequest(
560 static_cast<int32_t>(StorageDaemonInterfaceCode::GENERATE_APP_KEY), data, reply, option);
561 if (err != E_OK) {
562 return err;
563 }
564 keyId = reply.ReadString();
565 return reply.ReadInt32();
566 }
567
DeleteAppkey(uint32_t userId,const std::string & keyId)568 int32_t StorageDaemonProxy::DeleteAppkey(uint32_t userId, const std::string &keyId)
569 {
570 MessageParcel data;
571 MessageParcel reply;
572 MessageOption option(MessageOption::TF_SYNC);
573
574 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
575 return E_WRITE_DESCRIPTOR_ERR;
576 }
577
578 if (!data.WriteUint32(userId)) {
579 return E_WRITE_PARCEL_ERR;
580 }
581 if (!data.WriteString(keyId)) {
582 return E_WRITE_PARCEL_ERR;
583 }
584 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::DELETE_APP_KEY), data, reply, option);
585 if (err != E_OK) {
586 return err;
587 }
588 return reply.ReadInt32();
589 }
590
UpdateKeyContext(uint32_t userId)591 int32_t StorageDaemonProxy::UpdateKeyContext(uint32_t userId)
592 {
593 MessageParcel data;
594 MessageParcel reply;
595 MessageOption option(MessageOption::TF_SYNC);
596
597 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
598 return E_WRITE_DESCRIPTOR_ERR;
599 }
600
601 if (!data.WriteUint32(userId)) {
602 return E_WRITE_PARCEL_ERR;
603 }
604 int32_t err = SendRequest(
605 static_cast<int32_t>(StorageDaemonInterfaceCode::UPDATE_KEY_CONTEXT), data, reply, option);
606 if (err != E_OK) {
607 return err;
608 }
609
610 return reply.ReadInt32();
611 }
612
MountCryptoPathAgain(uint32_t userId)613 int32_t StorageDaemonProxy::MountCryptoPathAgain(uint32_t userId)
614 {
615 MessageParcel data;
616 MessageParcel reply;
617 MessageOption option(MessageOption::TF_SYNC);
618
619 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
620 return E_WRITE_DESCRIPTOR_ERR;
621 }
622
623 if (!data.WriteUint32(userId)) {
624 return E_WRITE_PARCEL_ERR;
625 }
626 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::MOUNT_CRYPTO_PATH_AGAIN),
627 data, reply, option);
628 if (err != E_OK) {
629 return err;
630 }
631
632 return reply.ReadInt32();
633 }
634
CreateShareFile(const std::vector<std::string> & uriList,uint32_t tokenId,uint32_t flag)635 std::vector<int32_t> StorageDaemonProxy::CreateShareFile(const std::vector<std::string> &uriList,
636 uint32_t tokenId, uint32_t flag)
637 {
638 MessageParcel data;
639 MessageParcel reply;
640 MessageOption option(MessageOption::TF_SYNC);
641
642 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
643 return std::vector<int32_t>{E_WRITE_DESCRIPTOR_ERR};
644 }
645
646 if (!data.WriteStringVector(uriList)) {
647 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
648 }
649
650 if (!data.WriteUint32(tokenId)) {
651 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
652 }
653
654 if (!data.WriteUint32(flag)) {
655 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
656 }
657
658 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::CREATE_SHARE_FILE), data, reply, option);
659 if (err != E_OK) {
660 return std::vector<int32_t>{err};
661 }
662
663 std::vector<int32_t> retList;
664 if (!reply.ReadInt32Vector(&retList)) {
665 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
666 };
667 return retList;
668 }
669
DeleteShareFile(uint32_t tokenId,const std::vector<std::string> & uriList)670 int32_t StorageDaemonProxy::DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &uriList)
671 {
672 MessageParcel data;
673 MessageParcel reply;
674 MessageOption option(MessageOption::TF_ASYNC);
675
676 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
677 return E_WRITE_DESCRIPTOR_ERR;
678 }
679
680 if (!data.WriteUint32(tokenId)) {
681 return E_WRITE_PARCEL_ERR;
682 }
683
684 if (!data.WriteStringVector(uriList)) {
685 return E_WRITE_PARCEL_ERR;
686 }
687
688 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::DELETE_SHARE_FILE), data, reply, option);
689 if (err != E_OK) {
690 return err;
691 }
692
693 return reply.ReadInt32();
694 }
695
SetBundleQuota(const std::string & bundleName,int32_t uid,const std::string & bundleDataDirPath,int32_t limitSizeMb)696 int32_t StorageDaemonProxy::SetBundleQuota(const std::string &bundleName, int32_t uid,
697 const std::string &bundleDataDirPath, int32_t limitSizeMb)
698 {
699 MessageParcel data;
700 MessageParcel reply;
701 MessageOption option(MessageOption::TF_SYNC);
702 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
703 return E_WRITE_DESCRIPTOR_ERR;
704 }
705
706 if (!data.WriteString(bundleName)) {
707 return E_WRITE_PARCEL_ERR;
708 }
709
710 if (!data.WriteInt32(uid)) {
711 return E_WRITE_PARCEL_ERR;
712 }
713
714 if (!data.WriteString(bundleDataDirPath)) {
715 return E_WRITE_PARCEL_ERR;
716 }
717
718 if (!data.WriteInt32(limitSizeMb)) {
719 return E_WRITE_PARCEL_ERR;
720 }
721
722 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::SET_BUNDLE_QUOTA), data, reply, option);
723 if (err != E_OK) {
724 return err;
725 }
726
727 return reply.ReadInt32();
728 }
729
GetOccupiedSpace(int32_t idType,int32_t id,int64_t & size)730 int32_t StorageDaemonProxy::GetOccupiedSpace(int32_t idType, int32_t id, int64_t &size)
731 {
732 MessageParcel data;
733 MessageParcel reply;
734 MessageOption option(MessageOption::TF_SYNC);
735 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
736 return E_WRITE_DESCRIPTOR_ERR;
737 }
738
739 if (!data.WriteInt32(idType)) {
740 return E_WRITE_PARCEL_ERR;
741 }
742
743 if (!data.WriteInt32(id)) {
744 return E_WRITE_PARCEL_ERR;
745 }
746
747 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::GET_SPACE), data, reply, option);
748 if (err != E_OK) {
749 return err;
750 }
751
752 err = reply.ReadInt32();
753 if (err != E_OK) {
754 return err;
755 }
756 size = reply.ReadInt64();
757 return E_OK;
758 }
759
GetBundleStatsForIncrease(uint32_t userId,const std::vector<std::string> & bundleNames,const std::vector<int64_t> & incrementalBackTimes,std::vector<int64_t> & pkgFileSizes,std::vector<int64_t> & incPkgFileSizes)760 int32_t StorageDaemonProxy::GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames,
761 const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes,
762 std::vector<int64_t> &incPkgFileSizes)
763 {
764 MessageParcel data;
765 MessageParcel reply;
766 MessageOption option(MessageOption::TF_SYNC);
767 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
768 return E_WRITE_DESCRIPTOR_ERR;
769 }
770
771 if (!data.WriteInt32(userId)) {
772 return E_WRITE_PARCEL_ERR;
773 }
774
775 if (!data.WriteStringVector(bundleNames)) {
776 return E_WRITE_PARCEL_ERR;
777 }
778
779 if (!data.WriteInt64Vector(incrementalBackTimes)) {
780 return E_WRITE_PARCEL_ERR;
781 }
782
783 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::GET_BUNDLE_STATS_INCREASE), data, reply,
784 option);
785 if (err != E_OK) {
786 LOGE("StorageDaemonProxy::SendRequest call err = %{public}d", err);
787 return err;
788 }
789 err = reply.ReadInt32();
790 if (err != E_OK) {
791 LOGE("StorageDaemonProxy::SendRequest reply.ReadInt32() call err = %{public}d", err);
792 return err;
793 }
794 if (!reply.ReadInt64Vector(&pkgFileSizes)) {
795 LOGE("StorageDaemonProxy::SendRequest read pkgFileSizes");
796 return E_WRITE_REPLY_ERR;
797 }
798 if (!reply.ReadInt64Vector(&incPkgFileSizes)) {
799 LOGE("StorageDaemonProxy::SendRequest read incPkgFileSizes");
800 return E_WRITE_REPLY_ERR;
801 }
802
803 return E_OK;
804 }
805
MountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)806 int32_t StorageDaemonProxy::MountDfsDocs(int32_t userId, const std::string &relativePath,
807 const std::string &networkId, const std::string &deviceId)
808 {
809 MessageParcel data;
810 MessageParcel reply;
811 MessageOption option(MessageOption::TF_SYNC);
812 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
813 return E_WRITE_DESCRIPTOR_ERR;
814 }
815 if (!data.WriteInt32(userId) || !data.WriteString(relativePath) ||
816 !data.WriteString(networkId) || !data.WriteString(deviceId)) {
817 return E_WRITE_PARCEL_ERR;
818 }
819
820 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::MOUNT_DFS_DOCS), data, reply, option);
821 if (err != E_OK) {
822 return err;
823 }
824
825 return reply.ReadInt32();
826 }
827
UMountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)828 int32_t StorageDaemonProxy::UMountDfsDocs(int32_t userId, const std::string &relativePath,
829 const std::string &networkId, const std::string &deviceId)
830 {
831 MessageParcel data;
832 MessageParcel reply;
833 MessageOption option(MessageOption::TF_SYNC);
834 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
835 return E_WRITE_DESCRIPTOR_ERR;
836 }
837 if (!data.WriteInt32(userId) || !data.WriteString(relativePath) ||
838 !data.WriteString(networkId) || !data.WriteString(deviceId)) {
839 return E_WRITE_PARCEL_ERR;
840 }
841
842 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UMOUNT_DFS_DOCS), data, reply, option);
843 if (err != E_OK) {
844 return err;
845 }
846
847 return reply.ReadInt32();
848 }
849
UpdateMemoryPara(int32_t size,int32_t & oldSize)850 int32_t StorageDaemonProxy::UpdateMemoryPara(int32_t size, int32_t &oldSize)
851 {
852 MessageParcel data;
853 MessageParcel reply;
854 MessageOption option(MessageOption::TF_SYNC);
855
856 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
857 return E_WRITE_DESCRIPTOR_ERR;
858 }
859
860 if (!data.WriteInt32(size)) {
861 return E_WRITE_PARCEL_ERR;
862 }
863
864 int32_t err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UPDATE_MEM_PARA), data, reply, option);
865 if (err != E_OK) {
866 return err;
867 }
868 err = reply.ReadInt32();
869 if (err != E_OK) {
870 return err;
871 }
872 oldSize = reply.ReadInt32();
873 return E_OK;
874 }
875
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)876 int32_t StorageDaemonProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
877 {
878 sptr<IRemoteObject> remote = Remote();
879 if (remote == nullptr) {
880 LOGE("remote is nullptr, code = %{public}d", code);
881 return E_REMOTE_IS_NULLPTR;
882 }
883
884 int32_t result = remote->SendRequest(code, data, reply, option);
885 if (result != E_OK) {
886 LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
887 return result;
888 }
889
890 return E_OK;
891 }
892
GetFileEncryptStatus(uint32_t userId,bool & isEncrypted,bool needCheckDirMount)893 int32_t StorageDaemonProxy::GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount)
894 {
895 MessageParcel data;
896 MessageParcel reply;
897 MessageOption option(MessageOption::TF_SYNC);
898
899 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
900 return E_WRITE_DESCRIPTOR_ERR;
901 }
902
903 if (!data.WriteUint32(userId)) {
904 return E_WRITE_PARCEL_ERR;
905 }
906 if (!data.WriteBool(needCheckDirMount)) {
907 return E_WRITE_PARCEL_ERR;
908 }
909 int32_t err =
910 SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::GET_FILE_ENCRYPT_STATUS), data, reply, option);
911 if (err != E_OK) {
912 return err;
913 }
914 isEncrypted = reply.ReadBool();
915 return reply.ReadInt32();
916 }
917 } // StorageDaemon
918 } // OHOS
919