• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 "storage_manager_proxy.h"
17 #include "hitrace_meter.h"
18 #include "storage_manager_ipc_interface_code.h"
19 #include "storage_service_errno.h"
20 #include "storage_service_log.h"
21 
22 namespace OHOS {
23 namespace StorageManager {
PrepareAddUser(int32_t userId,uint32_t flags)24 int32_t StorageManagerProxy::PrepareAddUser(int32_t userId, uint32_t flags)
25 {
26     LOGI("StorageManagerProxy::PrepareAddUser, userId:%{public}d", userId);
27     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option(MessageOption::TF_SYNC);
31     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
32         LOGE("StorageManagerProxy::PrepareAddUser, WriteInterfaceToken failed");
33         return E_WRITE_DESCRIPTOR_ERR;
34     }
35     if (!data.WriteInt32(userId)) {
36         LOGE("StorageManagerProxy::PrepareAddUser, WriteInt32 failed");
37         return E_WRITE_PARCEL_ERR;
38     }
39     if (!data.WriteUint32(flags)) {
40         LOGE("StorageManagerProxy::PrepareAddUser, WriteUint32 failed");
41         return E_WRITE_PARCEL_ERR;
42     }
43     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::PREPARE_ADD_USER), data, reply, option);
44     if (err != E_OK) {
45         return err;
46     }
47     return reply.ReadUint32();
48 }
49 
RemoveUser(int32_t userId,uint32_t flags)50 int32_t StorageManagerProxy::RemoveUser(int32_t userId, uint32_t flags)
51 {
52     LOGI("StorageManagerProxy::RemoveUser, userId:%{public}d", userId);
53     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
54     MessageParcel data;
55     MessageParcel reply;
56     MessageOption option(MessageOption::TF_SYNC);
57     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
58         LOGE("StorageManagerProxy::RemoveUser, WriteInterfaceToken failed");
59         return E_WRITE_DESCRIPTOR_ERR;
60     }
61     if (!data.WriteInt32(userId)) {
62         LOGE("StorageManagerProxy::RemoveUser, WriteInt32 failed");
63         return E_WRITE_PARCEL_ERR;
64     }
65     if (!data.WriteUint32(flags)) {
66         LOGE("StorageManagerProxy::RemoveUser, WriteUint32 failed");
67         return E_WRITE_PARCEL_ERR;
68     }
69     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::REMOVE_USER), data, reply, option);
70     if (err != E_OK) {
71         return err;
72     }
73     return reply.ReadUint32();
74 }
75 
PrepareStartUser(int32_t userId)76 int32_t StorageManagerProxy::PrepareStartUser(int32_t userId)
77 {
78     LOGI("StorageManagerProxy::PrepareStartUser, userId:%{public}d", userId);
79     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
80     MessageParcel data;
81     MessageParcel reply;
82     MessageOption option(MessageOption::TF_SYNC);
83     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
84         LOGE("StorageManagerProxy::PrepareStartUser, WriteInterfaceToken failed");
85         return E_WRITE_DESCRIPTOR_ERR;
86     }
87     if (!data.WriteInt32(userId)) {
88         LOGE("StorageManagerProxy::PrepareStartUser, WriteInt32 failed");
89         return E_WRITE_PARCEL_ERR;
90     }
91     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::PREPARE_START_USER), data, reply, option);
92     if (err != E_OK) {
93         return err;
94     }
95     return reply.ReadUint32();
96 }
97 
StopUser(int32_t userId)98 int32_t StorageManagerProxy::StopUser(int32_t userId)
99 {
100     LOGI("StorageManagerProxy::StopUser, userId:%{public}d", userId);
101     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
102     MessageParcel data;
103     MessageParcel reply;
104     MessageOption option(MessageOption::TF_SYNC);
105     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
106         LOGE("StorageManagerProxy::StopUser, WriteInterfaceToken failed");
107         return E_WRITE_DESCRIPTOR_ERR;
108     }
109     if (!data.WriteInt32(userId)) {
110         LOGE("StorageManagerProxy::StopUser, WriteInt32 failed");
111         return E_WRITE_PARCEL_ERR;
112     }
113     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::STOP_USER), data, reply, option);
114     if (err != E_OK) {
115         return err;
116     }
117     return reply.ReadUint32();
118 }
119 
GenerateUserKeys(uint32_t userId,uint32_t flags)120 int32_t StorageManagerProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
121 {
122     LOGI("user ID: %{public}u, flags: %{public}u", userId, flags);
123     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
124     MessageParcel data;
125     MessageParcel reply;
126     MessageOption option(MessageOption::TF_SYNC);
127     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
128         LOGE("WriteInterfaceToken failed");
129         return E_WRITE_DESCRIPTOR_ERR;
130     }
131     if (!data.WriteUint32(userId)) {
132         LOGE("Write user ID failed");
133         return E_WRITE_PARCEL_ERR;
134     }
135     if (!data.WriteUint32(flags)) {
136         LOGE("Write key flags failed");
137         return E_WRITE_PARCEL_ERR;
138     }
139     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_USER_KEYS), data, reply, option);
140     if (err != E_OK) {
141         return err;
142     }
143 
144     return reply.ReadInt32();
145 }
146 
DeleteUserKeys(uint32_t userId)147 int32_t StorageManagerProxy::DeleteUserKeys(uint32_t userId)
148 {
149     LOGI("user ID: %{public}u", userId);
150     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
151     MessageParcel data;
152     MessageParcel reply;
153     MessageOption option(MessageOption::TF_SYNC);
154     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
155         LOGE("WriteInterfaceToken failed");
156         return E_WRITE_DESCRIPTOR_ERR;
157     }
158     if (!data.WriteUint32(userId)) {
159         LOGE("Write user ID failed");
160         return E_WRITE_PARCEL_ERR;
161     }
162     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_USER_KEYS), data, reply, option);
163     if (err != E_OK) {
164         return err;
165     }
166 
167     return reply.ReadInt32();
168 }
169 
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)170 int32_t StorageManagerProxy::UpdateUserAuth(uint32_t userId, uint64_t secureUid,
171                                             const std::vector<uint8_t> &token,
172                                             const std::vector<uint8_t> &oldSecret,
173                                             const std::vector<uint8_t> &newSecret)
174 {
175     LOGI("user ID: %{public}u", userId);
176     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
177     MessageParcel data;
178     MessageParcel reply;
179     MessageOption option(MessageOption::TF_SYNC);
180     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
181         LOGE("WriteInterfaceToken failed");
182         return E_WRITE_DESCRIPTOR_ERR;
183     }
184     if (!data.WriteUint32(userId)) {
185         LOGE("Write user ID failed");
186         return E_WRITE_PARCEL_ERR;
187     }
188     if (!data.WriteUint64(secureUid)) {
189         LOGE("Write user ID failed");
190         return E_WRITE_PARCEL_ERR;
191     }
192     if (!data.WriteUInt8Vector(token)) {
193         LOGE("Write token failed");
194         return E_WRITE_PARCEL_ERR;
195     }
196     if (!data.WriteUInt8Vector(oldSecret)) {
197         LOGE("Write oldSecret failed");
198         return E_WRITE_PARCEL_ERR;
199     }
200     if (!data.WriteUInt8Vector(newSecret)) {
201         LOGE("Write newSecret failed");
202         return E_WRITE_PARCEL_ERR;
203     }
204 
205     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_USER_AUTH), data, reply, option);
206     if (err != E_OK) {
207         return err;
208     }
209 
210     return reply.ReadInt32();
211 }
212 
ActiveUserKey(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)213 int32_t StorageManagerProxy::ActiveUserKey(uint32_t userId,
214                                            const std::vector<uint8_t> &token,
215                                            const std::vector<uint8_t> &secret)
216 {
217     LOGI("user ID: %{public}u", userId);
218     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
219     MessageParcel data;
220     MessageParcel reply;
221     MessageOption option(MessageOption::TF_SYNC);
222     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
223         LOGE("WriteInterfaceToken failed");
224         return E_WRITE_DESCRIPTOR_ERR;
225     }
226     if (!data.WriteUint32(userId)) {
227         LOGE("Write user ID failed");
228         return E_WRITE_PARCEL_ERR;
229     }
230     if (!data.WriteUInt8Vector(token)) {
231         LOGE("Write token failed");
232         return E_WRITE_PARCEL_ERR;
233     }
234     if (!data.WriteUInt8Vector(secret)) {
235         LOGE("Write secret failed");
236         return E_WRITE_PARCEL_ERR;
237     }
238 
239     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::ACTIVE_USER_KEY), data, reply, option);
240     if (err != E_OK) {
241         return err;
242     }
243 
244     return reply.ReadInt32();
245 }
246 
InactiveUserKey(uint32_t userId)247 int32_t StorageManagerProxy::InactiveUserKey(uint32_t userId)
248 {
249     LOGI("user ID: %{public}u", userId);
250     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
251     MessageParcel data;
252     MessageParcel reply;
253     MessageOption option(MessageOption::TF_SYNC);
254     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
255         LOGE("WriteInterfaceToken failed");
256         return E_WRITE_DESCRIPTOR_ERR;
257     }
258     if (!data.WriteUint32(userId)) {
259         LOGE("Write user ID failed");
260         return E_WRITE_PARCEL_ERR;
261     }
262     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::INACTIVE_USER_KEY), data, reply, option);
263     if (err != E_OK) {
264         return err;
265     }
266 
267     return reply.ReadInt32();
268 }
269 
LockUserScreen(uint32_t userId)270 int32_t StorageManagerProxy::LockUserScreen(uint32_t userId)
271 {
272     LOGI("user ID: %{public}u", userId);
273     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
274     MessageParcel data;
275     MessageParcel reply;
276     MessageOption option(MessageOption::TF_SYNC);
277     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
278         LOGE("WriteInterfaceToken failed");
279         return E_WRITE_DESCRIPTOR_ERR;
280     }
281     if (!data.WriteUint32(userId)) {
282         LOGE("Write user ID failed");
283         return E_WRITE_PARCEL_ERR;
284     }
285     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::LOCK_USER_SCREEN), data, reply, option);
286     if (err != E_OK) {
287         return err;
288     }
289 
290     return reply.ReadInt32();
291 }
292 
UnlockUserScreen(uint32_t userId)293 int32_t StorageManagerProxy::UnlockUserScreen(uint32_t userId)
294 {
295     LOGI("user ID: %{public}u", userId);
296     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
297     MessageParcel data;
298     MessageParcel reply;
299     MessageOption option(MessageOption::TF_SYNC);
300     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
301         LOGE("WriteInterfaceToken failed");
302         return E_WRITE_DESCRIPTOR_ERR;
303     }
304     if (!data.WriteUint32(userId)) {
305         LOGE("Write user ID failed");
306         return E_WRITE_PARCEL_ERR;
307     }
308     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UNLOCK_USER_SCREEN), data, reply, option);
309     if (err != E_OK) {
310         return err;
311     }
312 
313     return reply.ReadInt32();
314 }
315 
GetLockScreenStatus(uint32_t userId,bool & lockScreenStatus)316 int32_t StorageManagerProxy::GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus)
317 {
318     LOGI("user ID: %{public}u", userId);
319     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
320     MessageParcel data;
321     MessageParcel reply;
322     MessageOption option(MessageOption::TF_SYNC);
323     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
324         LOGE("WriteInterfaceToken failed");
325         return E_WRITE_DESCRIPTOR_ERR;
326     }
327     if (!data.WriteUint32(userId)) {
328         LOGE("Write user ID failed");
329         return E_WRITE_PARCEL_ERR;
330     }
331     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::LOCK_SCREEN_STATUS), data, reply, option);
332     if (err != E_OK) {
333         return err;
334     }
335     lockScreenStatus = reply.ReadBool();
336     return reply.ReadInt32();
337 }
338 
UpdateKeyContext(uint32_t userId)339 int32_t StorageManagerProxy::UpdateKeyContext(uint32_t userId)
340 {
341     LOGI("user ID: %{public}u", userId);
342     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
343     MessageParcel data;
344     MessageParcel reply;
345     MessageOption option(MessageOption::TF_SYNC);
346     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
347         LOGE("WriteInterfaceToken failed");
348         return E_WRITE_DESCRIPTOR_ERR;
349     }
350     if (!data.WriteUint32(userId)) {
351         LOGE("Write user ID failed");
352         return E_WRITE_PARCEL_ERR;
353     }
354     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_KEY_CONTEXT), data, reply, option);
355     if (err != E_OK) {
356         return err;
357     }
358 
359     return reply.ReadInt32();
360 }
361 
GetFreeSizeOfVolume(std::string volumeUuid,int64_t & freeSize)362 int32_t StorageManagerProxy::GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize)
363 {
364     LOGI("StorageManagerProxy::GetFreeSizeOfVolume, volumeUuid:%{public}s", volumeUuid.c_str());
365     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
366     MessageParcel data;
367     MessageParcel reply;
368     MessageOption option(MessageOption::TF_SYNC);
369     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
370         LOGE("StorageManagerProxy::GetFreeSizeOfVolume, WriteInterfaceToken failed");
371         return E_WRITE_DESCRIPTOR_ERR;
372     }
373 
374     if (!data.WriteString(volumeUuid)) {
375         LOGE("StorageManagerProxy::GetFreeSizeOfVolume, WriteString failed");
376         return E_WRITE_PARCEL_ERR;
377     }
378     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_FREE), data, reply, option);
379     if (err != E_OK) {
380         return err;
381     }
382     err = reply.ReadInt32();
383     if (err != E_OK) {
384         return err;
385     }
386     freeSize = reply.ReadInt64();
387     return E_OK;
388 }
389 
GetTotalSizeOfVolume(std::string volumeUuid,int64_t & totalSize)390 int32_t StorageManagerProxy::GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize)
391 {
392     LOGI("StorageManagerProxy::GetTotalSizeOfVolume, volumeUuid:%{public}s", volumeUuid.c_str());
393     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
394     MessageParcel data;
395     MessageParcel reply;
396     MessageOption option(MessageOption::TF_SYNC);
397     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
398         LOGE("StorageManagerProxy::GetTotalSizeOfVolume, WriteInterfaceToken failed");
399         return E_WRITE_DESCRIPTOR_ERR;
400     }
401 
402     if (!data.WriteString(volumeUuid)) {
403         LOGE("StorageManagerProxy::GetTotalSizeOfVolume, WriteString failed");
404         return E_WRITE_PARCEL_ERR;
405     }
406     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_TOTAL), data, reply, option);
407     if (err != E_OK) {
408         return err;
409     }
410     err = reply.ReadInt32();
411     if (err != E_OK) {
412         return err;
413     }
414     totalSize = reply.ReadInt64();
415     return E_OK;
416 }
417 
GetBundleStats(std::string pkgName,BundleStats & bundleStats)418 int32_t StorageManagerProxy::GetBundleStats(std::string pkgName, BundleStats &bundleStats)
419 {
420     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
421     MessageParcel data;
422     MessageParcel reply;
423     MessageOption option(MessageOption::TF_SYNC);
424     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
425         return E_WRITE_DESCRIPTOR_ERR;
426     }
427 
428     if (!data.WriteString(pkgName)) {
429         return E_WRITE_PARCEL_ERR;
430     }
431     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_BUNDLE_STATUS), data, reply, option);
432     if (err != E_OK) {
433         return err;
434     }
435     err = reply.ReadInt32();
436     if (err != E_OK) {
437         return err;
438     }
439     bundleStats = *BundleStats::Unmarshalling(reply);
440     return E_OK;
441 }
442 
NotifyVolumeCreated(VolumeCore vc)443 int32_t StorageManagerProxy::NotifyVolumeCreated(VolumeCore vc)
444 {
445     LOGI("StorageManagerProxy::NotifyVolumeCreated, volumeUuid:%{public}s", vc.GetId().c_str());
446     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
447     MessageParcel data;
448     MessageParcel reply;
449     MessageOption option(MessageOption::TF_SYNC);
450     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
451         LOGE("StorageManagerProxy::NotifyVolumeCreated, WriteInterfaceToken failed");
452         return E_WRITE_DESCRIPTOR_ERR;
453     }
454 
455     if (!vc.Marshalling(data)) {
456         LOGE("StorageManagerProxy::NotifyVolumeCreated, WriteVolumeInfo failed");
457         return E_WRITE_PARCEL_ERR;
458     }
459 
460     return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_CREATED), data, reply, option);
461 }
462 
NotifyVolumeMounted(std::string volumeId,int32_t fsType,std::string fsUuid,std::string path,std::string description)463 int32_t StorageManagerProxy::NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
464     std::string path, std::string description)
465 {
466     LOGI("StorageManagerProxy::NotifyVolumeMounted, volumeUuid:%{public}s", volumeId.c_str());
467     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
468     MessageParcel data;
469     MessageParcel reply;
470     MessageOption option(MessageOption::TF_SYNC);
471     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
472         LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteInterfaceToken failed");
473         return E_WRITE_DESCRIPTOR_ERR;
474     }
475 
476     if (!data.WriteString(volumeId)) {
477         LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
478         return E_WRITE_PARCEL_ERR;
479     }
480 
481     if (!data.WriteInt32(fsType)) {
482         LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteInt32 failed");
483         return E_WRITE_PARCEL_ERR;
484     }
485 
486     if (!data.WriteString(fsUuid)) {
487         LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
488         return E_WRITE_PARCEL_ERR;
489     }
490 
491     if (!data.WriteString(path)) {
492         LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
493         return E_WRITE_PARCEL_ERR;
494     }
495 
496     if (!data.WriteString(description)) {
497         LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
498         return E_WRITE_PARCEL_ERR;
499     }
500 
501     return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_MOUNTED), data, reply, option);
502 }
503 
NotifyVolumeStateChanged(std::string volumeId,VolumeState state)504 int32_t StorageManagerProxy::NotifyVolumeStateChanged(std::string volumeId, VolumeState state)
505 {
506     LOGI("StorageManagerProxy::NotifyVolumeStateChanged, volumeId:%{public}s", volumeId.c_str());
507     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
508     MessageParcel data;
509     MessageParcel reply;
510     MessageOption option(MessageOption::TF_SYNC);
511     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
512         LOGE("StorageManagerProxy::NotifyVolumeStateChanged, WriteInterfaceToken failed");
513         return E_WRITE_DESCRIPTOR_ERR;
514     }
515 
516     if (!data.WriteString(volumeId)) {
517         LOGE("StorageManagerProxy::NotifyVolumeStateChanged, WriteString failed");
518         return E_WRITE_PARCEL_ERR;
519     }
520 
521     if (!data.WriteInt32(state)) {
522         LOGE("StorageManagerProxy::NotifyVolumeStateChanged, WriteInt failed");
523         return E_WRITE_PARCEL_ERR;
524     }
525 
526     return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_STATE_CHANGED), data, reply,
527         option);
528 }
529 
Mount(std::string volumeId)530 int32_t StorageManagerProxy::Mount(std::string volumeId)
531 {
532     LOGI("StorageManagerProxy::Mount, volumeId:%{public}s", volumeId.c_str());
533     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
534     MessageParcel data;
535     MessageParcel reply;
536     MessageOption option(MessageOption::TF_SYNC);
537     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
538         LOGE("StorageManagerProxy::Mount, WriteInterfaceToken failed");
539         return E_WRITE_DESCRIPTOR_ERR;
540     }
541 
542     if (!data.WriteString(volumeId)) {
543         LOGE("StorageManagerProxy::Mount, WriteString failed");
544         return E_WRITE_PARCEL_ERR;
545     }
546     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT), data, reply, option);
547     if (err != E_OK) {
548         return err;
549     }
550     return reply.ReadInt32();
551 }
552 
Unmount(std::string volumeId)553 int32_t StorageManagerProxy::Unmount(std::string volumeId)
554 {
555     LOGI("StorageManagerProxy::Unmount, volumeId:%{public}s", volumeId.c_str());
556     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
557     MessageParcel data;
558     MessageParcel reply;
559     MessageOption option(MessageOption::TF_SYNC);
560     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
561         LOGE("StorageManagerProxy::Unmount, WriteInterfaceToken failed");
562         return E_WRITE_DESCRIPTOR_ERR;
563     }
564 
565     if (!data.WriteString(volumeId)) {
566         LOGE("StorageManagerProxy::Unmount, WriteString failed");
567         return E_WRITE_PARCEL_ERR;
568     }
569     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UNMOUNT), data, reply, option);
570     if (err != E_OK) {
571         return err;
572     }
573     return reply.ReadInt32();
574 }
575 
GetAllVolumes(std::vector<VolumeExternal> & vecOfVol)576 int32_t StorageManagerProxy::GetAllVolumes(std::vector<VolumeExternal> &vecOfVol)
577 {
578     LOGI("StorageManagerProxy::GetAllVolumes");
579     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
580     MessageParcel data;
581     MessageParcel reply;
582     MessageOption option(MessageOption::TF_SYNC);
583     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
584         LOGE("StorageManagerProxy::GetAllVolumes, WriteInterfaceToken failed");
585         return E_WRITE_DESCRIPTOR_ERR;
586     }
587 
588     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_ALL_VOLUMES), data, reply, option);
589     if (err != E_OK) {
590         return err;
591     }
592     err = reply.ReadInt32();
593     if (err != E_OK) {
594         return err;
595     }
596     uint size = reply.ReadUint32();
597     if (size == 0) {
598         return reply.ReadInt32();
599     }
600     for (uint i = 0; i < size; i++) {
601         std::unique_ptr<VolumeExternal> ve = VolumeExternal::Unmarshalling(reply);
602         LOGI("StorageManagerProxy::GetAllVolumes push %{public}s", ve->GetId().c_str());
603         vecOfVol.push_back(*ve);
604     }
605     return E_OK;
606 }
607 
NotifyDiskCreated(Disk disk)608 int32_t StorageManagerProxy::NotifyDiskCreated(Disk disk)
609 {
610     LOGI("StorageManagerProxy::NotifyDiskCreate, diskId:%{public}s", disk.GetDiskId().c_str());
611     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
612     MessageParcel data;
613     MessageParcel reply;
614     MessageOption option(MessageOption::TF_SYNC);
615     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
616         LOGE("StorageManagerProxy::NotifyDiskCreate, WriteInterfaceToken failed");
617         return E_WRITE_DESCRIPTOR_ERR;
618     }
619 
620     if (!disk.Marshalling(data)) {
621         LOGE("StorageManagerProxy::NotifyDiskCreate, WriteDiskInfo failed");
622         return E_WRITE_PARCEL_ERR;
623     }
624 
625     return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_DISK_CREATED), data, reply, option);
626 }
627 
NotifyDiskDestroyed(std::string diskId)628 int32_t StorageManagerProxy::NotifyDiskDestroyed(std::string diskId)
629 {
630     LOGI("StorageManagerProxy::NotifyDiskDestroyed, diskId:%{public}s", diskId.c_str());
631     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
632     MessageParcel data;
633     MessageParcel reply;
634     MessageOption option(MessageOption::TF_SYNC);
635     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
636         LOGE("StorageManagerProxy::NotifyDiskDestroyed, WriteInterfaceToken failed");
637         return E_WRITE_DESCRIPTOR_ERR;
638     }
639     if (!data.WriteString(diskId)) {
640         LOGE("StorageManagerProxy::NotifyDiskDestroyed, WriteString failed");
641         return E_WRITE_PARCEL_ERR;
642     }
643     return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_DISK_DESTROYED), data, reply, option);
644 }
645 
Partition(std::string diskId,int32_t type)646 int32_t StorageManagerProxy::Partition(std::string diskId, int32_t type)
647 {
648     LOGI("StorageManagerProxy::Partition, diskId:%{public}s", diskId.c_str());
649     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
650     MessageParcel data;
651     MessageParcel reply;
652     MessageOption option(MessageOption::TF_SYNC);
653     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
654         LOGE("StorageManagerProxy::Partition, WriteInterfaceToken failed");
655         return E_WRITE_DESCRIPTOR_ERR;
656     }
657     if (!data.WriteString(diskId)) {
658         LOGE("StorageManagerProxy::Partition, WriteString failed");
659         return E_WRITE_PARCEL_ERR;
660     }
661     if (!data.WriteInt32(type)) {
662         LOGE("StorageManagerProxy::Partition WriteInt32 failed");
663         return E_WRITE_PARCEL_ERR;
664     }
665     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::PARTITION), data, reply, option);
666     if (err != E_OK) {
667         return err;
668     }
669     return reply.ReadInt32();
670 }
671 
GetAllDisks(std::vector<Disk> & vecOfDisk)672 int32_t StorageManagerProxy::GetAllDisks(std::vector<Disk> &vecOfDisk)
673 {
674     LOGI("StorageManagerProxy::GetAllDisks");
675     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
676     MessageParcel data;
677     MessageParcel reply;
678     MessageOption option(MessageOption::TF_SYNC);
679     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
680         LOGE("StorageManagerProxy::GetAllDisks, WriteInterfaceToken failed");
681         return E_WRITE_DESCRIPTOR_ERR;
682     }
683 
684     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_ALL_DISKS), data, reply, option);
685     if (err != E_OK) {
686         return err;
687     }
688     err = reply.ReadInt32();
689     if (err != E_OK) {
690         return err;
691     }
692     uint size = reply.ReadUint32();
693     if (size == 0) {
694         return reply.ReadInt32();
695     }
696     for (uint i = 0; i < size; i++) {
697         std::unique_ptr<Disk> disk = Disk::Unmarshalling(reply);
698         LOGI("StorageManagerProxy::GetAllDisks push %{public}s", disk->GetDiskId().c_str());
699         vecOfDisk.push_back(*disk);
700     }
701     return E_OK;
702 }
703 
GetSystemSize(int64_t & systemSize)704 int32_t StorageManagerProxy::GetSystemSize(int64_t &systemSize)
705 {
706     LOGI("StorageManagerProxy::GetSystemSize");
707     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
708     MessageParcel data;
709     MessageParcel reply;
710     MessageOption option(MessageOption::TF_SYNC);
711     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
712         LOGE("StorageManagerProxy::GetSystemSize WriteInterfaceToken failed");
713         return E_WRITE_DESCRIPTOR_ERR;
714     }
715 
716     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_SYSTEM_SIZE), data, reply, option);
717     if (err != E_OK) {
718         return err;
719     }
720     err = reply.ReadInt32();
721     if (err != E_OK) {
722         return err;
723     }
724     systemSize = reply.ReadInt64();
725     return E_OK;
726 }
727 
GetTotalSize(int64_t & totalSize)728 int32_t StorageManagerProxy::GetTotalSize(int64_t &totalSize)
729 {
730     LOGI("StorageManagerProxy::GetTotalSize");
731     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
732     MessageParcel data;
733     MessageParcel reply;
734     MessageOption option(MessageOption::TF_SYNC);
735     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
736         LOGE("StorageManagerProxy::GetTotalSize WriteInterfaceToken failed");
737         return E_WRITE_DESCRIPTOR_ERR;
738     }
739 
740     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_TOTAL_SIZE), data, reply, option);
741     if (err != E_OK) {
742         return err;
743     }
744     err = reply.ReadInt32();
745     if (err != E_OK) {
746         return err;
747     }
748     totalSize = reply.ReadInt64();
749     return E_OK;
750 }
751 
GetFreeSize(int64_t & freeSize)752 int32_t StorageManagerProxy::GetFreeSize(int64_t &freeSize)
753 {
754     LOGI("StorageManagerProxy::GetFreeSize");
755     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
756     MessageParcel data;
757     MessageParcel reply;
758     MessageOption option(MessageOption::TF_SYNC);
759     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
760         LOGE("StorageManagerProxy::GetFreeSize WriteInterfaceToken failed");
761         return E_WRITE_DESCRIPTOR_ERR;
762     }
763 
764     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_FREE_SIZE), data, reply, option);
765     if (err != E_OK) {
766         return err;
767     }
768     err = reply.ReadInt32();
769     if (err != E_OK) {
770         return err;
771     }
772     freeSize = reply.ReadInt64();
773     return E_OK;
774 }
775 
GetUserStorageStats(StorageStats & storageStats)776 int32_t StorageManagerProxy::GetUserStorageStats(StorageStats &storageStats)
777 {
778     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
779     StorageStats result;
780     MessageParcel data;
781     MessageParcel reply;
782     MessageOption option(MessageOption::TF_SYNC);
783     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
784         return E_WRITE_DESCRIPTOR_ERR;
785     }
786 
787     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_CURR_USER_STATS), data, reply, option);
788     if (err != E_OK) {
789         return err;
790     }
791     err = reply.ReadInt32();
792     if (err != E_OK) {
793         return err;
794     }
795     storageStats = *StorageStats::Unmarshalling(reply);
796     return E_OK;
797 }
798 
GetUserStorageStats(int32_t userId,StorageStats & storageStats)799 int32_t StorageManagerProxy::GetUserStorageStats(int32_t userId, StorageStats &storageStats)
800 {
801     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
802     StorageStats result;
803     MessageParcel data;
804     MessageParcel reply;
805     MessageOption option(MessageOption::TF_SYNC);
806     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
807         return E_WRITE_DESCRIPTOR_ERR;
808     }
809 
810     if (!data.WriteInt32(userId)) {
811         return E_WRITE_PARCEL_ERR;
812     }
813     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS), data, reply, option);
814     if (err != E_OK) {
815         return err;
816     }
817     err = reply.ReadInt32();
818     if (err != E_OK) {
819         return err;
820     }
821     storageStats = *StorageStats::Unmarshalling(reply);
822     return E_OK;
823 }
824 
GetCurrentBundleStats(BundleStats & bundleStats)825 int32_t StorageManagerProxy::GetCurrentBundleStats(BundleStats &bundleStats)
826 {
827     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
828     BundleStats result;
829     MessageParcel data;
830     MessageParcel reply;
831     MessageOption option(MessageOption::TF_SYNC);
832     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
833         return E_WRITE_DESCRIPTOR_ERR;
834     }
835 
836     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_CURR_BUNDLE_STATS), data, reply,
837         option);
838     if (err != E_OK) {
839         return err;
840     }
841     err = reply.ReadInt32();
842     if (err != E_OK) {
843         return err;
844     }
845     bundleStats = *BundleStats::Unmarshalling(reply);
846     return E_OK;
847 }
848 
GetVolumeByUuid(std::string fsUuid,VolumeExternal & vc)849 int32_t StorageManagerProxy::GetVolumeByUuid(std::string fsUuid, VolumeExternal &vc)
850 {
851     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
852     MessageParcel data;
853     MessageParcel reply;
854     MessageOption option(MessageOption::TF_SYNC);
855     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
856         return E_WRITE_DESCRIPTOR_ERR;
857     }
858 
859     if (!data.WriteString(fsUuid)) {
860         return E_WRITE_PARCEL_ERR;
861     }
862 
863     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_VOL_BY_UUID), data, reply, option);
864     if (err != E_OK) {
865         return err;
866     }
867     vc = *VolumeExternal::Unmarshalling(reply);
868     return reply.ReadInt32();
869 }
870 
GetVolumeById(std::string volumeId,VolumeExternal & vc)871 int32_t StorageManagerProxy::GetVolumeById(std::string volumeId, VolumeExternal &vc)
872 {
873     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
874     MessageParcel data;
875     MessageParcel reply;
876     MessageOption option(MessageOption::TF_SYNC);
877     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
878         return E_WRITE_DESCRIPTOR_ERR;
879     }
880 
881     if (!data.WriteString(volumeId)) {
882         return E_WRITE_PARCEL_ERR;
883     }
884 
885     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_VOL_BY_ID), data, reply, option);
886     if (err != E_OK) {
887         return err;
888     }
889     vc = *VolumeExternal::Unmarshalling(reply);
890     return reply.ReadInt32();
891 }
892 
SetVolumeDescription(std::string fsUuid,std::string description)893 int32_t StorageManagerProxy::SetVolumeDescription(std::string fsUuid, std::string description)
894 {
895     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
896     MessageParcel data;
897     MessageParcel reply;
898     MessageOption option(MessageOption::TF_SYNC);
899     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
900         return E_WRITE_DESCRIPTOR_ERR;
901     }
902 
903     if (!data.WriteString(fsUuid)) {
904         return E_WRITE_PARCEL_ERR;
905     }
906 
907     if (!data.WriteString(description)) {
908         return E_WRITE_PARCEL_ERR;
909     }
910 
911     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::SET_VOL_DESC), data, reply, option);
912     if (err != E_OK) {
913         return err;
914     }
915     return reply.ReadInt32();
916 }
917 
Format(std::string volumeId,std::string fsType)918 int32_t StorageManagerProxy::Format(std::string volumeId, std::string fsType)
919 {
920     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
921     MessageParcel data;
922     MessageParcel reply;
923     MessageOption option(MessageOption::TF_SYNC);
924     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
925         return E_WRITE_DESCRIPTOR_ERR;
926     }
927 
928     if (!data.WriteString(volumeId)) {
929         return E_WRITE_PARCEL_ERR;
930     }
931 
932     if (!data.WriteString(fsType)) {
933         return E_WRITE_PARCEL_ERR;
934     }
935 
936     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::FORMAT), data, reply, option);
937     if (err != E_OK) {
938         return err;
939     }
940     return reply.ReadInt32();
941 }
942 
GetDiskById(std::string diskId,Disk & disk)943 int32_t StorageManagerProxy::GetDiskById(std::string diskId, Disk &disk)
944 {
945     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
946     MessageParcel data;
947     MessageParcel reply;
948     MessageOption option(MessageOption::TF_SYNC);
949     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
950         return E_WRITE_DESCRIPTOR_ERR;
951     }
952 
953     if (!data.WriteString(diskId)) {
954         return E_WRITE_PARCEL_ERR;
955     }
956 
957     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_DISK_BY_ID), data, reply, option);
958     if (err != E_OK) {
959         return err;
960     }
961     disk = *Disk::Unmarshalling(reply);
962     return reply.ReadInt32();
963 }
964 
CreateShareFile(const std::vector<std::string> & uriList,uint32_t tokenId,uint32_t flag)965 std::vector<int32_t> StorageManagerProxy::CreateShareFile(const std::vector<std::string> &uriList,
966                                                           uint32_t tokenId, uint32_t flag)
967 {
968     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
969     MessageParcel data;
970     MessageParcel reply;
971     MessageOption option(MessageOption::TF_SYNC);
972 
973     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
974         return std::vector<int32_t>{E_WRITE_DESCRIPTOR_ERR};
975     }
976 
977     if (!data.WriteStringVector(uriList)) {
978         return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
979     }
980 
981     if (!data.WriteUint32(tokenId)) {
982         return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
983     }
984 
985     if (!data.WriteUint32(flag)) {
986         return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
987     }
988 
989     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_SHARE_FILE), data, reply, option);
990     if (err != E_OK) {
991         return std::vector<int32_t>{err};
992     }
993 
994     std::vector<int32_t> retList;
995     if (!reply.ReadInt32Vector(&retList)) {
996         return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
997     };
998     return retList;
999 }
1000 
DeleteShareFile(uint32_t tokenId,const std::vector<std::string> & uriList)1001 int32_t StorageManagerProxy::DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &uriList)
1002 {
1003     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1004     MessageParcel data;
1005     MessageParcel reply;
1006     MessageOption option(MessageOption::TF_ASYNC);
1007 
1008     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1009         return E_WRITE_DESCRIPTOR_ERR;
1010     }
1011 
1012     if (!data.WriteUint32(tokenId)) {
1013         return E_WRITE_PARCEL_ERR;
1014     }
1015 
1016     if (!data.WriteStringVector(uriList)) {
1017         return E_WRITE_PARCEL_ERR;
1018     }
1019 
1020     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_SHARE_FILE), data, reply, option);
1021     if (err != E_OK) {
1022         return err;
1023     }
1024 
1025     return reply.ReadInt32();
1026 }
SetBundleQuota(const std::string & bundleName,int32_t uid,const std::string & bundleDataDirPath,int32_t limitSizeMb)1027 int32_t StorageManagerProxy::SetBundleQuota(const std::string &bundleName, int32_t uid,
1028     const std::string &bundleDataDirPath, int32_t limitSizeMb)
1029 {
1030     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1031     MessageParcel data;
1032     MessageParcel reply;
1033     MessageOption option(MessageOption::TF_SYNC);
1034 
1035     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1036         return E_WRITE_DESCRIPTOR_ERR;
1037     }
1038 
1039     if (!data.WriteString(bundleName)) {
1040         return E_WRITE_PARCEL_ERR;
1041     }
1042 
1043     if (!data.WriteInt32(uid)) {
1044         return E_WRITE_PARCEL_ERR;
1045     }
1046 
1047     if (!data.WriteString(bundleDataDirPath)) {
1048         return E_WRITE_PARCEL_ERR;
1049     }
1050 
1051     if (!data.WriteInt32(limitSizeMb)) {
1052         return E_WRITE_PARCEL_ERR;
1053     }
1054 
1055     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::SET_BUNDLE_QUOTA), data, reply, option);
1056     if (err != E_OK) {
1057         return err;
1058     }
1059 
1060     return reply.ReadInt32();
1061 }
1062 
UpdateMemoryPara(int32_t size,int32_t & oldSize)1063 int32_t StorageManagerProxy::UpdateMemoryPara(int32_t size, int32_t &oldSize)
1064 {
1065     MessageParcel data;
1066     MessageParcel reply;
1067     MessageOption option(MessageOption::TF_SYNC);
1068     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1069         return E_WRITE_DESCRIPTOR_ERR;
1070     }
1071     if (!data.WriteInt32(size)) {
1072         return E_WRITE_PARCEL_ERR;
1073     }
1074 
1075     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_MEM_PARA), data, reply, option);
1076     if (err != E_OK) {
1077         return err;
1078     }
1079     err = reply.ReadInt32();
1080     if (err != E_OK) {
1081         return err;
1082     }
1083     oldSize = reply.ReadInt32();
1084 
1085     return E_OK;
1086 }
1087 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1088 int32_t StorageManagerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
1089     MessageOption &option)
1090 {
1091     sptr<IRemoteObject> remote = Remote();
1092     if (remote == nullptr) {
1093         LOGE("remote is nullptr, code = %{public}d", code);
1094         return E_REMOTE_IS_NULLPTR;
1095     }
1096 
1097     int32_t result = remote->SendRequest(code, data, reply, option);
1098     if (result != E_OK) {
1099         LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
1100         return result;
1101     }
1102 
1103     return E_OK;
1104 }
1105 
GetUserStorageStatsByType(int32_t userId,StorageStats & storageStats,std::string type)1106 int32_t StorageManagerProxy::GetUserStorageStatsByType(int32_t userId, StorageStats &storageStats, std::string type)
1107 {
1108     HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1109     StorageStats result;
1110     MessageParcel data;
1111     MessageParcel reply;
1112     MessageOption option(MessageOption::TF_SYNC);
1113     if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1114         return E_WRITE_DESCRIPTOR_ERR;
1115     }
1116 
1117     if (!data.WriteInt32(userId)) {
1118         return E_WRITE_PARCEL_ERR;
1119     }
1120 
1121     if (!data.WriteString(type)) {
1122         return E_WRITE_PARCEL_ERR;
1123     }
1124     int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS_BY_TYPE), data, reply,
1125         option);
1126     if (err != E_OK) {
1127         return err;
1128     }
1129     err = reply.ReadInt32();
1130     if (err != E_OK) {
1131         return err;
1132     }
1133     storageStats = *StorageStats::Unmarshalling(reply);
1134     return E_OK;
1135 }
1136 } // StorageManager
1137 } // OHOS
1138