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(std::string volId,uint32_t flags)39 int32_t StorageDaemonProxy::Mount(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 int 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(std::string volId)64 int32_t StorageDaemonProxy::UMount(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 int 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(std::string volId)85 int32_t StorageDaemonProxy::Check(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 int 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(std::string volId,std::string fsType)106 int32_t StorageDaemonProxy::Format(std::string volId, 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 int 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(std::string diskId,int32_t type)131 int32_t StorageDaemonProxy::Partition(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 int 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(std::string volId,std::string description)156 int32_t StorageDaemonProxy::SetVolumeDescription(std::string volId, 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 int 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 int 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 int 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 int 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 int 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
InitGlobalKey(void)277 int32_t StorageDaemonProxy::InitGlobalKey(void)
278 {
279 MessageParcel data;
280 MessageParcel reply;
281 MessageOption option(MessageOption::TF_SYNC);
282 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
283 return E_WRITE_DESCRIPTOR_ERR;
284 }
285
286 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY), data, reply, option);
287 if (err != E_OK) {
288 return err;
289 }
290
291 return reply.ReadUint32();
292 }
293
InitGlobalUserKeys(void)294 int32_t StorageDaemonProxy::InitGlobalUserKeys(void)
295 {
296 MessageParcel data;
297 MessageParcel reply;
298 MessageOption option(MessageOption::TF_SYNC);
299 LOGI("start");
300 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
301 return E_WRITE_DESCRIPTOR_ERR;
302 }
303
304 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS), data, reply,
305 option);
306 if (err != E_OK) {
307 return err;
308 }
309
310 return reply.ReadUint32();
311 }
312
GenerateUserKeys(uint32_t userId,uint32_t flags)313 int32_t StorageDaemonProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
314 {
315 MessageParcel data;
316 MessageParcel reply;
317 MessageOption option(MessageOption::TF_SYNC);
318
319 LOGI("start");
320 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
321 return E_WRITE_DESCRIPTOR_ERR;
322 }
323
324 if (!data.WriteUint32(userId)) {
325 return E_WRITE_PARCEL_ERR;
326 }
327 if (!data.WriteUint32(flags)) {
328 return E_WRITE_PARCEL_ERR;
329 }
330
331 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::CREATE_USER_KEYS), data, reply, option);
332 if (err != E_OK) {
333 return err;
334 }
335
336 return reply.ReadUint32();
337 }
338
DeleteUserKeys(uint32_t userId)339 int32_t StorageDaemonProxy::DeleteUserKeys(uint32_t userId)
340 {
341 MessageParcel data;
342 MessageParcel reply;
343 MessageOption option(MessageOption::TF_SYNC);
344
345 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
346 return E_WRITE_DESCRIPTOR_ERR;
347 }
348
349 if (!data.WriteUint32(userId)) {
350 return E_WRITE_PARCEL_ERR;
351 }
352 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::DELETE_USER_KEYS), data, reply, option);
353 if (err != E_OK) {
354 return err;
355 }
356
357 return reply.ReadInt32();
358 }
359
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)360 int32_t StorageDaemonProxy::UpdateUserAuth(uint32_t userId, uint64_t secureUid,
361 const std::vector<uint8_t> &token,
362 const std::vector<uint8_t> &oldSecret,
363 const std::vector<uint8_t> &newSecret)
364 {
365 MessageParcel data;
366 MessageParcel reply;
367 MessageOption option(MessageOption::TF_SYNC);
368
369 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
370 return E_WRITE_DESCRIPTOR_ERR;
371 }
372
373 if (!data.WriteUint32(userId)) {
374 return E_WRITE_PARCEL_ERR;
375 }
376 if (!data.WriteUint64(secureUid)) {
377 return E_WRITE_PARCEL_ERR;
378 }
379 if (!data.WriteUInt8Vector(token)) {
380 return E_WRITE_PARCEL_ERR;
381 }
382 if (!data.WriteUInt8Vector(oldSecret)) {
383 return E_WRITE_PARCEL_ERR;
384 }
385 if (!data.WriteUInt8Vector(newSecret)) {
386 return E_WRITE_PARCEL_ERR;
387 }
388
389 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UPDATE_USER_AUTH), data, reply, option);
390 if (err != E_OK) {
391 return err;
392 }
393
394 return reply.ReadInt32();
395 }
396
ActiveUserKey(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)397 int32_t StorageDaemonProxy::ActiveUserKey(uint32_t userId,
398 const std::vector<uint8_t> &token,
399 const std::vector<uint8_t> &secret)
400 {
401 MessageParcel data;
402 MessageParcel reply;
403 MessageOption option(MessageOption::TF_SYNC);
404
405 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
406 return E_WRITE_DESCRIPTOR_ERR;
407 }
408
409 if (!data.WriteUint32(userId)) {
410 return E_WRITE_PARCEL_ERR;
411 }
412 if (!data.WriteUInt8Vector(token)) {
413 return E_WRITE_PARCEL_ERR;
414 }
415 if (!data.WriteUInt8Vector(secret)) {
416 return E_WRITE_PARCEL_ERR;
417 }
418
419 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::ACTIVE_USER_KEY), data, reply, option);
420 if (err != E_OK) {
421 return err;
422 }
423
424 return reply.ReadInt32();
425 }
426
InactiveUserKey(uint32_t userId)427 int32_t StorageDaemonProxy::InactiveUserKey(uint32_t userId)
428 {
429 MessageParcel data;
430 MessageParcel reply;
431 MessageOption option(MessageOption::TF_SYNC);
432
433 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
434 return E_WRITE_DESCRIPTOR_ERR;
435 }
436
437 if (!data.WriteUint32(userId)) {
438 return E_WRITE_PARCEL_ERR;
439 }
440 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::INACTIVE_USER_KEY), data, reply, option);
441 if (err != E_OK) {
442 return err;
443 }
444
445 return reply.ReadInt32();
446 }
447
LockUserScreen(uint32_t userId)448 int32_t StorageDaemonProxy::LockUserScreen(uint32_t userId)
449 {
450 MessageParcel data;
451 MessageParcel reply;
452 MessageOption option(MessageOption::TF_SYNC);
453
454 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
455 return E_WRITE_DESCRIPTOR_ERR;
456 }
457
458 if (!data.WriteUint32(userId)) {
459 return E_WRITE_PARCEL_ERR;
460 }
461 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::LOCK_USER_SCREEN), data, reply, option);
462 if (err != E_OK) {
463 return err;
464 }
465
466 return reply.ReadInt32();
467 }
468
UnlockUserScreen(uint32_t userId)469 int32_t StorageDaemonProxy::UnlockUserScreen(uint32_t userId)
470 {
471 MessageParcel data;
472 MessageParcel reply;
473 MessageOption option(MessageOption::TF_SYNC);
474
475 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
476 return E_WRITE_DESCRIPTOR_ERR;
477 }
478
479 if (!data.WriteUint32(userId)) {
480 return E_WRITE_PARCEL_ERR;
481 }
482 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UNLOCK_USER_SCREEN), data, reply, option);
483 if (err != E_OK) {
484 return err;
485 }
486
487 return reply.ReadInt32();
488 }
489
GetLockScreenStatus(uint32_t userId,bool & lockScreenStatus)490 int32_t StorageDaemonProxy::GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus)
491 {
492 MessageParcel data;
493 MessageParcel reply;
494 MessageOption option(MessageOption::TF_SYNC);
495
496 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
497 return E_WRITE_DESCRIPTOR_ERR;
498 }
499
500 if (!data.WriteUint32(userId)) {
501 return E_WRITE_PARCEL_ERR;
502 }
503 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::LOCK_SCREEN_STATUS), data, reply, option);
504 if (err != E_OK) {
505 return err;
506 }
507 lockScreenStatus = reply.ReadBool();
508 return reply.ReadInt32();
509 }
510
UpdateKeyContext(uint32_t userId)511 int32_t StorageDaemonProxy::UpdateKeyContext(uint32_t userId)
512 {
513 MessageParcel data;
514 MessageParcel reply;
515 MessageOption option(MessageOption::TF_SYNC);
516
517 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
518 return E_WRITE_DESCRIPTOR_ERR;
519 }
520
521 if (!data.WriteUint32(userId)) {
522 return E_WRITE_PARCEL_ERR;
523 }
524 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UPDATE_KEY_CONTEXT), data, reply, option);
525 if (err != E_OK) {
526 return err;
527 }
528
529 return reply.ReadInt32();
530 }
531
MountCryptoPathAgain(uint32_t userId)532 int32_t StorageDaemonProxy::MountCryptoPathAgain(uint32_t userId)
533 {
534 MessageParcel data;
535 MessageParcel reply;
536 MessageOption option(MessageOption::TF_SYNC);
537
538 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
539 return E_WRITE_DESCRIPTOR_ERR;
540 }
541
542 if (!data.WriteUint32(userId)) {
543 return E_WRITE_PARCEL_ERR;
544 }
545 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::MOUNT_CRYPTO_PATH_AGAIN),
546 data, reply, option);
547 if (err != E_OK) {
548 return err;
549 }
550
551 return reply.ReadInt32();
552 }
553
CreateShareFile(const std::vector<std::string> & uriList,uint32_t tokenId,uint32_t flag)554 std::vector<int32_t> StorageDaemonProxy::CreateShareFile(const std::vector<std::string> &uriList,
555 uint32_t tokenId, uint32_t flag)
556 {
557 MessageParcel data;
558 MessageParcel reply;
559 MessageOption option(MessageOption::TF_SYNC);
560
561 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
562 return std::vector<int32_t>{E_WRITE_DESCRIPTOR_ERR};
563 }
564
565 if (!data.WriteStringVector(uriList)) {
566 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
567 }
568
569 if (!data.WriteUint32(tokenId)) {
570 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
571 }
572
573 if (!data.WriteUint32(flag)) {
574 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
575 }
576
577 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::CREATE_SHARE_FILE), data, reply, option);
578 if (err != E_OK) {
579 return std::vector<int32_t>{err};
580 }
581
582 std::vector<int32_t> retList;
583 if (!reply.ReadInt32Vector(&retList)) {
584 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
585 };
586 return retList;
587 }
588
DeleteShareFile(uint32_t tokenId,const std::vector<std::string> & uriList)589 int32_t StorageDaemonProxy::DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &uriList)
590 {
591 MessageParcel data;
592 MessageParcel reply;
593 MessageOption option(MessageOption::TF_ASYNC);
594
595 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
596 return E_WRITE_DESCRIPTOR_ERR;
597 }
598
599 if (!data.WriteUint32(tokenId)) {
600 return E_WRITE_PARCEL_ERR;
601 }
602
603 if (!data.WriteStringVector(uriList)) {
604 return E_WRITE_PARCEL_ERR;
605 }
606
607 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::DELETE_SHARE_FILE), data, reply, option);
608 if (err != E_OK) {
609 return err;
610 }
611
612 return reply.ReadInt32();
613 }
614
SetBundleQuota(const std::string & bundleName,int32_t uid,const std::string & bundleDataDirPath,int32_t limitSizeMb)615 int32_t StorageDaemonProxy::SetBundleQuota(const std::string &bundleName, int32_t uid,
616 const std::string &bundleDataDirPath, int32_t limitSizeMb)
617 {
618 MessageParcel data;
619 MessageParcel reply;
620 MessageOption option(MessageOption::TF_SYNC);
621 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
622 return E_WRITE_DESCRIPTOR_ERR;
623 }
624
625 if (!data.WriteString(bundleName)) {
626 return E_WRITE_PARCEL_ERR;
627 }
628
629 if (!data.WriteInt32(uid)) {
630 return E_WRITE_PARCEL_ERR;
631 }
632
633 if (!data.WriteString(bundleDataDirPath)) {
634 return E_WRITE_PARCEL_ERR;
635 }
636
637 if (!data.WriteInt32(limitSizeMb)) {
638 return E_WRITE_PARCEL_ERR;
639 }
640
641 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::SET_BUNDLE_QUOTA), data, reply, option);
642 if (err != E_OK) {
643 return err;
644 }
645
646 return reply.ReadInt32();
647 }
648
GetOccupiedSpace(int32_t idType,int32_t id,int64_t & size)649 int32_t StorageDaemonProxy::GetOccupiedSpace(int32_t idType, int32_t id, int64_t &size)
650 {
651 MessageParcel data;
652 MessageParcel reply;
653 MessageOption option(MessageOption::TF_SYNC);
654 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
655 return E_WRITE_DESCRIPTOR_ERR;
656 }
657
658 if (!data.WriteInt32(idType)) {
659 return E_WRITE_PARCEL_ERR;
660 }
661
662 if (!data.WriteInt32(id)) {
663 return E_WRITE_PARCEL_ERR;
664 }
665
666 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::GET_SPACE), data, reply, option);
667 if (err != E_OK) {
668 return err;
669 }
670
671 err = reply.ReadInt32();
672 if (err != E_OK) {
673 return err;
674 }
675 size = reply.ReadInt64();
676 return E_OK;
677 }
678
UpdateMemoryPara(int32_t size,int32_t & oldSize)679 int32_t StorageDaemonProxy::UpdateMemoryPara(int32_t size, int32_t &oldSize)
680 {
681 MessageParcel data;
682 MessageParcel reply;
683 MessageOption option(MessageOption::TF_SYNC);
684
685 if (!data.WriteInterfaceToken(StorageDaemonProxy::GetDescriptor())) {
686 return E_WRITE_DESCRIPTOR_ERR;
687 }
688
689 if (!data.WriteInt32(size)) {
690 return E_WRITE_PARCEL_ERR;
691 }
692
693 int err = SendRequest(static_cast<int32_t>(StorageDaemonInterfaceCode::UPDATE_MEM_PARA), data, reply, option);
694 if (err != E_OK) {
695 return err;
696 }
697 err = reply.ReadInt32();
698 if (err != E_OK) {
699 return err;
700 }
701 oldSize = reply.ReadInt32();
702 return E_OK;
703 }
704
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)705 int32_t StorageDaemonProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
706 {
707 sptr<IRemoteObject> remote = Remote();
708 if (remote == nullptr) {
709 LOGE("remote is nullptr, code = %{public}d", code);
710 return E_REMOTE_IS_NULLPTR;
711 }
712
713 int32_t result = remote->SendRequest(code, data, reply, option);
714 if (result != E_OK) {
715 LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
716 return result;
717 }
718
719 return E_OK;
720 }
721 } // StorageDaemon
722 } // OHOS
723