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 #include "utils/storage_utils.h"
22
23 namespace OHOS {
24 namespace StorageManager {
PrepareAddUser(int32_t userId,uint32_t flags)25 int32_t StorageManagerProxy::PrepareAddUser(int32_t userId, uint32_t flags)
26 {
27 LOGI("StorageManagerProxy::PrepareAddUser, userId:%{public}d", userId);
28 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option(MessageOption::TF_SYNC);
32 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
33 LOGE("StorageManagerProxy::PrepareAddUser, WriteInterfaceToken failed");
34 return E_WRITE_DESCRIPTOR_ERR;
35 }
36 if (!data.WriteInt32(userId)) {
37 LOGE("StorageManagerProxy::PrepareAddUser, WriteInt32 failed");
38 return E_WRITE_PARCEL_ERR;
39 }
40 if (!data.WriteUint32(flags)) {
41 LOGE("StorageManagerProxy::PrepareAddUser, WriteUint32 failed");
42 return E_WRITE_PARCEL_ERR;
43 }
44 int32_t err = SendRequest(
45 static_cast<int32_t>(StorageManagerInterfaceCode::PREPARE_ADD_USER), data, reply, option);
46 if (err != E_OK) {
47 return err;
48 }
49 return reply.ReadUint32();
50 }
51
RemoveUser(int32_t userId,uint32_t flags)52 int32_t StorageManagerProxy::RemoveUser(int32_t userId, uint32_t flags)
53 {
54 LOGI("StorageManagerProxy::RemoveUser, userId:%{public}d", userId);
55 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
56 MessageParcel data;
57 MessageParcel reply;
58 MessageOption option(MessageOption::TF_SYNC);
59 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
60 LOGE("StorageManagerProxy::RemoveUser, WriteInterfaceToken failed");
61 return E_WRITE_DESCRIPTOR_ERR;
62 }
63 if (!data.WriteInt32(userId)) {
64 LOGE("StorageManagerProxy::RemoveUser, WriteInt32 failed");
65 return E_WRITE_PARCEL_ERR;
66 }
67 if (!data.WriteUint32(flags)) {
68 LOGE("StorageManagerProxy::RemoveUser, WriteUint32 failed");
69 return E_WRITE_PARCEL_ERR;
70 }
71 int32_t err = SendRequest(
72 static_cast<int32_t>(StorageManagerInterfaceCode::REMOVE_USER), data, reply, option);
73 if (err != E_OK) {
74 return err;
75 }
76 return reply.ReadUint32();
77 }
78
PrepareStartUser(int32_t userId)79 int32_t StorageManagerProxy::PrepareStartUser(int32_t userId)
80 {
81 LOGI("StorageManagerProxy::PrepareStartUser, userId:%{public}d", userId);
82 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option(MessageOption::TF_SYNC);
86 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
87 LOGE("StorageManagerProxy::PrepareStartUser, WriteInterfaceToken failed");
88 return E_WRITE_DESCRIPTOR_ERR;
89 }
90 if (!data.WriteInt32(userId)) {
91 LOGE("StorageManagerProxy::PrepareStartUser, WriteInt32 failed");
92 return E_WRITE_PARCEL_ERR;
93 }
94 int32_t err = SendRequest(
95 static_cast<int32_t>(StorageManagerInterfaceCode::PREPARE_START_USER), data, reply, option);
96 if (err != E_OK) {
97 return err;
98 }
99 return reply.ReadUint32();
100 }
101
StopUser(int32_t userId)102 int32_t StorageManagerProxy::StopUser(int32_t userId)
103 {
104 LOGI("StorageManagerProxy::StopUser, userId:%{public}d", userId);
105 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
106 MessageParcel data;
107 MessageParcel reply;
108 MessageOption option(MessageOption::TF_SYNC);
109 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
110 LOGE("StorageManagerProxy::StopUser, WriteInterfaceToken failed");
111 return E_WRITE_DESCRIPTOR_ERR;
112 }
113 if (!data.WriteInt32(userId)) {
114 LOGE("StorageManagerProxy::StopUser, WriteInt32 failed");
115 return E_WRITE_PARCEL_ERR;
116 }
117 int32_t err = SendRequest(
118 static_cast<int32_t>(StorageManagerInterfaceCode::STOP_USER), data, reply, option);
119 if (err != E_OK) {
120 return err;
121 }
122 return reply.ReadUint32();
123 }
124
CompleteAddUser(int32_t userId)125 int32_t StorageManagerProxy::CompleteAddUser(int32_t userId)
126 {
127 LOGI("StorageManagerProxy::CompleteAddUser, userId:%{public}d", userId);
128 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
129 MessageParcel data;
130 MessageParcel reply;
131 MessageOption option(MessageOption::TF_SYNC);
132 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
133 LOGE("StorageManagerProxy::CompleteAddUser, WriteInterfaceToken failed");
134 return E_WRITE_DESCRIPTOR_ERR;
135 }
136 if (!data.WriteInt32(userId)) {
137 LOGE("StorageManagerProxy::CompleteAddUser, WriteInt32 failed");
138 return E_WRITE_PARCEL_ERR;
139 }
140 int32_t err = SendRequest(
141 static_cast<int32_t>(StorageManagerInterfaceCode::COMPLETE_ADD_USER), data, reply, option);
142 if (err != E_OK) {
143 return err;
144 }
145 return reply.ReadUint32();
146 }
147
GenerateUserKeys(uint32_t userId,uint32_t flags)148 int32_t StorageManagerProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
149 {
150 LOGI("user ID: %{public}u, flags: %{public}u", userId, flags);
151 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
152 MessageParcel data;
153 MessageParcel reply;
154 MessageOption option(MessageOption::TF_SYNC);
155 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
156 LOGE("WriteInterfaceToken failed");
157 return E_WRITE_DESCRIPTOR_ERR;
158 }
159 if (!data.WriteUint32(userId)) {
160 LOGE("Write user ID failed");
161 return E_WRITE_PARCEL_ERR;
162 }
163 if (!data.WriteUint32(flags)) {
164 LOGE("Write key flags failed");
165 return E_WRITE_PARCEL_ERR;
166 }
167 int32_t err = SendRequest(
168 static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_USER_KEYS), data, reply, option);
169 if (err != E_OK) {
170 return err;
171 }
172
173 return reply.ReadInt32();
174 }
175
DeleteUserKeys(uint32_t userId)176 int32_t StorageManagerProxy::DeleteUserKeys(uint32_t userId)
177 {
178 LOGI("user ID: %{public}u", userId);
179 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
180 MessageParcel data;
181 MessageParcel reply;
182 MessageOption option(MessageOption::TF_SYNC);
183 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
184 LOGE("WriteInterfaceToken failed");
185 return E_WRITE_DESCRIPTOR_ERR;
186 }
187 if (!data.WriteUint32(userId)) {
188 LOGE("Write user ID failed");
189 return E_WRITE_PARCEL_ERR;
190 }
191 int32_t err = SendRequest(
192 static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_USER_KEYS), data, reply, option);
193 if (err != E_OK) {
194 return err;
195 }
196
197 return reply.ReadInt32();
198 }
199
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)200 int32_t StorageManagerProxy::UpdateUserAuth(uint32_t userId, uint64_t secureUid,
201 const std::vector<uint8_t> &token,
202 const std::vector<uint8_t> &oldSecret,
203 const std::vector<uint8_t> &newSecret)
204 {
205 LOGI("user ID: %{public}u", userId);
206 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
207 MessageParcel data;
208 MessageParcel reply;
209 MessageOption option(MessageOption::TF_SYNC);
210 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
211 LOGE("WriteInterfaceToken failed");
212 return E_WRITE_DESCRIPTOR_ERR;
213 }
214 if (!data.WriteUint32(userId)) {
215 LOGE("Write user ID failed");
216 return E_WRITE_PARCEL_ERR;
217 }
218 if (!data.WriteUint64(secureUid)) {
219 LOGE("Write user ID failed");
220 return E_WRITE_PARCEL_ERR;
221 }
222 if (!data.WriteUInt8Vector(token)) {
223 LOGE("Write token failed");
224 return E_WRITE_PARCEL_ERR;
225 }
226 if (!data.WriteUInt8Vector(oldSecret)) {
227 LOGE("Write oldSecret failed");
228 return E_WRITE_PARCEL_ERR;
229 }
230 if (!data.WriteUInt8Vector(newSecret)) {
231 LOGE("Write newSecret failed");
232 return E_WRITE_PARCEL_ERR;
233 }
234
235 int32_t err = SendRequest(
236 static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_USER_AUTH), data, reply, option);
237 if (err != E_OK) {
238 return err;
239 }
240
241 return reply.ReadInt32();
242 }
243
UpdateUseAuthWithRecoveryKey(const std::vector<uint8_t> & authToken,const std::vector<uint8_t> & newSecret,uint64_t secureUid,uint32_t userId,std::vector<std::vector<uint8_t>> & plainText)244 int32_t StorageManagerProxy::UpdateUseAuthWithRecoveryKey(const std::vector<uint8_t> &authToken,
245 const std::vector<uint8_t> &newSecret,
246 uint64_t secureUid,
247 uint32_t userId,
248 std::vector<std::vector<uint8_t>> &plainText)
249 {
250 LOGI("user ID: %{public}u", userId);
251 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
252 MessageParcel data;
253 MessageParcel reply;
254 MessageOption option(MessageOption::TF_SYNC);
255 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
256 LOGE("WriteInterfaceToken failed");
257 return E_WRITE_DESCRIPTOR_ERR;
258 }
259
260 if (!data.WriteUint32(userId)) {
261 LOGE("Write user ID failed");
262 return E_WRITE_PARCEL_ERR;
263 }
264 if (!data.WriteUint64(secureUid)) {
265 LOGE("Write secure UID failed");
266 return E_WRITE_PARCEL_ERR;
267 }
268 if (!data.WriteUInt8Vector(authToken)) {
269 LOGE("Write token failed");
270 return E_WRITE_PARCEL_ERR;
271 }
272 if (!data.WriteUInt8Vector(newSecret)) {
273 LOGE("Write new secret failed");
274 return E_WRITE_PARCEL_ERR;
275 }
276 for (uint32_t i = 0; i < plainText.size(); i++) {
277 if (!data.WriteUInt8Vector(plainText[i])) {
278 return E_WRITE_PARCEL_ERR;
279 }
280 }
281
282 int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_USER_AUTH_RECOVER_KEY), data, reply,
283 option);
284 if (err != E_OK) {
285 return err;
286 }
287
288 return reply.ReadInt32();
289 }
290
ActiveUserKey(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)291 int32_t StorageManagerProxy::ActiveUserKey(uint32_t userId,
292 const std::vector<uint8_t> &token,
293 const std::vector<uint8_t> &secret)
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 if (!data.WriteUInt8Vector(token)) {
309 LOGE("Write token failed");
310 return E_WRITE_PARCEL_ERR;
311 }
312 if (!data.WriteUInt8Vector(secret)) {
313 LOGE("Write secret failed");
314 return E_WRITE_PARCEL_ERR;
315 }
316
317 int32_t err = SendRequest(
318 static_cast<int32_t>(StorageManagerInterfaceCode::ACTIVE_USER_KEY), data, reply, option);
319 if (err != E_OK) {
320 return err;
321 }
322
323 return reply.ReadInt32();
324 }
325
InactiveUserKey(uint32_t userId)326 int32_t StorageManagerProxy::InactiveUserKey(uint32_t userId)
327 {
328 LOGI("user ID: %{public}u", userId);
329 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
330 MessageParcel data;
331 MessageParcel reply;
332 MessageOption option(MessageOption::TF_SYNC);
333 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
334 LOGE("WriteInterfaceToken failed");
335 return E_WRITE_DESCRIPTOR_ERR;
336 }
337 if (!data.WriteUint32(userId)) {
338 LOGE("Write user ID failed");
339 return E_WRITE_PARCEL_ERR;
340 }
341 int32_t err = SendRequest(
342 static_cast<int32_t>(StorageManagerInterfaceCode::INACTIVE_USER_KEY), data, reply, option);
343 if (err != E_OK) {
344 return err;
345 }
346
347 return reply.ReadInt32();
348 }
349
LockUserScreen(uint32_t userId)350 int32_t StorageManagerProxy::LockUserScreen(uint32_t userId)
351 {
352 LOGI("user ID: %{public}u", userId);
353 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
354 MessageParcel data;
355 MessageParcel reply;
356 MessageOption option(MessageOption::TF_ASYNC);
357 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
358 LOGE("WriteInterfaceToken failed");
359 return E_WRITE_DESCRIPTOR_ERR;
360 }
361 if (!data.WriteUint32(userId)) {
362 LOGE("Write user ID failed");
363 return E_WRITE_PARCEL_ERR;
364 }
365 int32_t err = SendRequest(
366 static_cast<int32_t>(StorageManagerInterfaceCode::LOCK_USER_SCREEN), data, reply, option);
367 if (err != E_OK) {
368 return err;
369 }
370
371 return reply.ReadInt32();
372 }
373
UnlockUserScreen(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)374 int32_t StorageManagerProxy::UnlockUserScreen(uint32_t userId,
375 const std::vector<uint8_t> &token,
376 const std::vector<uint8_t> &secret)
377 {
378 LOGI("user ID: %{public}u", userId);
379 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
380 MessageParcel data;
381 MessageParcel reply;
382 MessageOption option(MessageOption::TF_SYNC);
383 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
384 LOGE("WriteInterfaceToken failed");
385 return E_WRITE_DESCRIPTOR_ERR;
386 }
387 if (!data.WriteUint32(userId)) {
388 LOGE("Write user ID failed");
389 return E_WRITE_PARCEL_ERR;
390 }
391 if (!data.WriteUInt8Vector(token)) {
392 LOGE("Write token failed");
393 return E_WRITE_PARCEL_ERR;
394 }
395 if (!data.WriteUInt8Vector(secret)) {
396 LOGE("Write secret failed");
397 return E_WRITE_PARCEL_ERR;
398 }
399 int32_t err = SendRequest(
400 static_cast<int32_t>(StorageManagerInterfaceCode::UNLOCK_USER_SCREEN), data, reply, option);
401 if (err != E_OK) {
402 return err;
403 }
404
405 return reply.ReadInt32();
406 }
407
GetLockScreenStatus(uint32_t userId,bool & lockScreenStatus)408 int32_t StorageManagerProxy::GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus)
409 {
410 LOGI("user ID: %{public}u", userId);
411 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
412 MessageParcel data;
413 MessageParcel reply;
414 MessageOption option(MessageOption::TF_SYNC);
415 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
416 LOGE("WriteInterfaceToken failed");
417 return E_WRITE_DESCRIPTOR_ERR;
418 }
419 if (!data.WriteUint32(userId)) {
420 LOGE("Write user ID failed");
421 return E_WRITE_PARCEL_ERR;
422 }
423 int32_t err = SendRequest(
424 static_cast<int32_t>(StorageManagerInterfaceCode::LOCK_SCREEN_STATUS), data, reply, option);
425 if (err != E_OK) {
426 return err;
427 }
428 lockScreenStatus = reply.ReadBool();
429 return reply.ReadInt32();
430 }
431
UpdateKeyContext(uint32_t userId,bool needRemoveTmpKey)432 int32_t StorageManagerProxy::UpdateKeyContext(uint32_t userId, bool needRemoveTmpKey)
433 {
434 LOGI("user ID: %{public}u", userId);
435 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
436 MessageParcel data;
437 MessageParcel reply;
438 MessageOption option(MessageOption::TF_SYNC);
439 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
440 LOGE("WriteInterfaceToken failed");
441 return E_WRITE_DESCRIPTOR_ERR;
442 }
443 if (!data.WriteUint32(userId)) {
444 LOGE("Write user ID failed");
445 return E_WRITE_PARCEL_ERR;
446 }
447 if (!data.WriteBool(needRemoveTmpKey)) {
448 LOGE("Write needRemoveTmpKey failed");
449 return E_WRITE_PARCEL_ERR;
450 }
451 int32_t err = SendRequest(
452 static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_KEY_CONTEXT), data, reply, option);
453 if (err != E_OK) {
454 return err;
455 }
456
457 return reply.ReadInt32();
458 }
459
GenerateAppkey(uint32_t hashId,uint32_t userId,std::string & keyId)460 int32_t StorageManagerProxy::GenerateAppkey(uint32_t hashId, uint32_t userId, std::string &keyId)
461 {
462 LOGI("userId ID: %{public}u", userId);
463 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
464 MessageParcel data;
465 MessageParcel reply;
466 MessageOption option(MessageOption::TF_SYNC);
467 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
468 LOGE("WriteInterfaceToken failed");
469 return E_WRITE_DESCRIPTOR_ERR;
470 }
471 if (!data.WriteUint32(hashId)) {
472 LOGE("Write hashId failed");
473 return E_WRITE_PARCEL_ERR;
474 }
475 if (!data.WriteUint32(userId)) {
476 LOGE("Write appUid failed");
477 return E_WRITE_PARCEL_ERR;
478 }
479 int32_t err = SendRequest(
480 static_cast<int32_t>(StorageManagerInterfaceCode::GENERATE_APP_KEY), data, reply, option);
481 if (err != E_OK) {
482 return err;
483 }
484 keyId = reply.ReadString();
485 return reply.ReadInt32();
486 }
487
DeleteAppkey(const std::string keyId)488 int32_t StorageManagerProxy::DeleteAppkey(const std::string keyId)
489 {
490 LOGI("DeleteAppkey enter ");
491 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
492 MessageParcel data;
493 MessageParcel reply;
494 MessageOption option(MessageOption::TF_SYNC);
495 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
496 LOGE("WriteInterfaceToken failed");
497 return E_WRITE_DESCRIPTOR_ERR;
498 }
499 if (!data.WriteString(keyId)) {
500 LOGE("Write key ID failed");
501 return E_WRITE_PARCEL_ERR;
502 }
503 int32_t err = SendRequest(
504 static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_APP_KEY), data, reply, option);
505 if (err != E_OK) {
506 return err;
507 }
508
509 return reply.ReadInt32();
510 }
511
CreateRecoverKey(uint32_t userId,uint32_t userType,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)512 int32_t StorageManagerProxy::CreateRecoverKey(uint32_t userId,
513 uint32_t userType,
514 const std::vector<uint8_t> &token,
515 const std::vector<uint8_t> &secret)
516 {
517 LOGI("user ID: %{public}u", userId);
518 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
519 MessageParcel data;
520 MessageParcel reply;
521 MessageOption option(MessageOption::TF_SYNC);
522 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
523 LOGE("StorageManagerProxy::CreateRecoverKey, WriteInterfaceToken failed");
524 return E_WRITE_DESCRIPTOR_ERR;
525 }
526 if (!data.WriteUint32(userId)) {
527 LOGE("Write user id failed");
528 return E_WRITE_PARCEL_ERR;
529 }
530 if (!data.WriteUint32(userType)) {
531 LOGE("Write user type failed");
532 return E_WRITE_PARCEL_ERR;
533 }
534 if (!data.WriteUInt8Vector(token)) {
535 LOGE("Write token failed");
536 return E_WRITE_PARCEL_ERR;
537 }
538 if (!data.WriteUInt8Vector(secret)) {
539 LOGE("Write recover secret failed");
540 return E_WRITE_PARCEL_ERR;
541 }
542
543 int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_RECOVER_KEY), data, reply, option);
544 if (err != E_OK) {
545 return err;
546 }
547
548 return reply.ReadInt32();
549 }
550
SetRecoverKey(const std::vector<uint8_t> & key)551 int32_t StorageManagerProxy::SetRecoverKey(const std::vector<uint8_t> &key)
552 {
553 LOGI("enter");
554 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
555 MessageParcel data;
556 MessageParcel reply;
557 MessageOption option(MessageOption::TF_SYNC);
558 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
559 LOGE("StorageManagerProxy::SetRecoverKey, WriteInterfaceToken failed");
560 return E_WRITE_DESCRIPTOR_ERR;
561 }
562 if (!data.WriteUInt8Vector(key)) {
563 LOGE("Write recover key failed");
564 return E_WRITE_PARCEL_ERR;
565 }
566
567 int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::SET_RECOVER_KEY), data, reply, option);
568 if (err != E_OK) {
569 return err;
570 }
571
572 return reply.ReadInt32();
573 }
574
GetFreeSizeOfVolume(std::string volumeUuid,int64_t & freeSize)575 int32_t StorageManagerProxy::GetFreeSizeOfVolume(std::string volumeUuid, int64_t &freeSize)
576 {
577 LOGI("StorageManagerProxy::GetFreeSizeOfVolume, volumeUuid:%{public}s",
578 GetAnonyString(volumeUuid).c_str());
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::GetFreeSizeOfVolume, WriteInterfaceToken failed");
585 return E_WRITE_DESCRIPTOR_ERR;
586 }
587
588 if (!data.WriteString(volumeUuid)) {
589 LOGE("StorageManagerProxy::GetFreeSizeOfVolume, WriteString failed");
590 return E_WRITE_PARCEL_ERR;
591 }
592 int32_t err = SendRequest(
593 static_cast<int32_t>(StorageManagerInterfaceCode::GET_FREE), data, reply, option);
594 if (err != E_OK) {
595 return err;
596 }
597 err = reply.ReadInt32();
598 if (err != E_OK) {
599 return err;
600 }
601 freeSize = reply.ReadInt64();
602 return E_OK;
603 }
604
GetTotalSizeOfVolume(std::string volumeUuid,int64_t & totalSize)605 int32_t StorageManagerProxy::GetTotalSizeOfVolume(std::string volumeUuid, int64_t &totalSize)
606 {
607 LOGI("StorageManagerProxy::GetTotalSizeOfVolume, volumeUuid:%{public}s",
608 GetAnonyString(volumeUuid).c_str());
609 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
610 MessageParcel data;
611 MessageParcel reply;
612 MessageOption option(MessageOption::TF_SYNC);
613 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
614 LOGE("StorageManagerProxy::GetTotalSizeOfVolume, WriteInterfaceToken failed");
615 return E_WRITE_DESCRIPTOR_ERR;
616 }
617
618 if (!data.WriteString(volumeUuid)) {
619 LOGE("StorageManagerProxy::GetTotalSizeOfVolume, WriteString failed");
620 return E_WRITE_PARCEL_ERR;
621 }
622 int32_t err = SendRequest(
623 static_cast<int32_t>(StorageManagerInterfaceCode::GET_TOTAL), data, reply, option);
624 if (err != E_OK) {
625 return err;
626 }
627 err = reply.ReadInt32();
628 if (err != E_OK) {
629 return err;
630 }
631 totalSize = reply.ReadInt64();
632 return E_OK;
633 }
634
GetBundleStats(std::string pkgName,BundleStats & bundleStats,int32_t appIndex,uint32_t statFlag)635 int32_t StorageManagerProxy::GetBundleStats(std::string pkgName, BundleStats &bundleStats,
636 int32_t appIndex, uint32_t statFlag)
637 {
638 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
639 MessageParcel data;
640 MessageParcel reply;
641 MessageOption option(MessageOption::TF_SYNC);
642 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
643 LOGE("StorageManagerProxy::GetBundleStats, WriteInterfaceToken failed");
644 return E_WRITE_DESCRIPTOR_ERR;
645 }
646
647 if (!data.WriteString(pkgName)) {
648 LOGE("StorageManagerProxy::GetBundleStats, WriteString failed");
649 return E_WRITE_PARCEL_ERR;
650 }
651
652 if (!data.WriteInt32(appIndex)) {
653 LOGE("StorageManagerProxy::GetBundleStats, WriteInt32 failed");
654 return E_WRITE_PARCEL_ERR;
655 }
656
657 if (!data.WriteUint32(statFlag)) {
658 LOGE("StorageManagerProxy::GetBundleStats, WriteInt32 failed");
659 return E_WRITE_PARCEL_ERR;
660 }
661
662 int32_t err = SendRequest(
663 static_cast<int32_t>(StorageManagerInterfaceCode::GET_BUNDLE_STATUS), data, reply, option);
664 if (err != E_OK) {
665 return err;
666 }
667 err = reply.ReadInt32();
668 if (err != E_OK) {
669 return err;
670 }
671 bundleStats = *BundleStats::Unmarshalling(reply);
672 return E_OK;
673 }
674
NotifyVolumeCreated(VolumeCore vc)675 int32_t StorageManagerProxy::NotifyVolumeCreated(VolumeCore vc)
676 {
677 LOGI("StorageManagerProxy::NotifyVolumeCreated, volumeUuid:%{public}s",
678 GetAnonyString(vc.GetId()).c_str());
679 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
680 MessageParcel data;
681 MessageParcel reply;
682 MessageOption option(MessageOption::TF_SYNC);
683 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
684 LOGE("StorageManagerProxy::NotifyVolumeCreated, WriteInterfaceToken failed");
685 return E_WRITE_DESCRIPTOR_ERR;
686 }
687
688 if (!vc.Marshalling(data)) {
689 LOGE("StorageManagerProxy::NotifyVolumeCreated, WriteVolumeInfo failed");
690 return E_WRITE_PARCEL_ERR;
691 }
692
693 return SendRequest(
694 static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_CREATED), data, reply, option);
695 }
696
NotifyVolumeMounted(std::string volumeId,int32_t fsType,std::string fsUuid,std::string path,std::string description)697 int32_t StorageManagerProxy::NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
698 std::string path, std::string description)
699 {
700 LOGI("StorageManagerProxy::NotifyVolumeMounted, volumeUuid:%{public}s",
701 GetAnonyString(volumeId).c_str());
702 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
703 MessageParcel data;
704 MessageParcel reply;
705 MessageOption option(MessageOption::TF_SYNC);
706 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
707 LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteInterfaceToken failed");
708 return E_WRITE_DESCRIPTOR_ERR;
709 }
710
711 if (!data.WriteString(volumeId)) {
712 LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
713 return E_WRITE_PARCEL_ERR;
714 }
715
716 if (!data.WriteInt32(fsType)) {
717 LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteInt32 failed");
718 return E_WRITE_PARCEL_ERR;
719 }
720
721 if (!data.WriteString(fsUuid)) {
722 LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
723 return E_WRITE_PARCEL_ERR;
724 }
725
726 if (!data.WriteString(path)) {
727 LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
728 return E_WRITE_PARCEL_ERR;
729 }
730
731 if (!data.WriteString(description)) {
732 LOGE("StorageManagerProxy::NotifyVolumeMounted, WriteString failed");
733 return E_WRITE_PARCEL_ERR;
734 }
735
736 return SendRequest(
737 static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_MOUNTED), data, reply, option);
738 }
739
NotifyVolumeStateChanged(std::string volumeId,VolumeState state)740 int32_t StorageManagerProxy::NotifyVolumeStateChanged(std::string volumeId, VolumeState state)
741 {
742 LOGI("StorageManagerProxy::NotifyVolumeStateChanged, volumeId:%{public}s", volumeId.c_str());
743 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
744 MessageParcel data;
745 MessageParcel reply;
746 MessageOption option(MessageOption::TF_SYNC);
747 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
748 LOGE("StorageManagerProxy::NotifyVolumeStateChanged, WriteInterfaceToken failed");
749 return E_WRITE_DESCRIPTOR_ERR;
750 }
751
752 if (!data.WriteString(volumeId)) {
753 LOGE("StorageManagerProxy::NotifyVolumeStateChanged, WriteString failed");
754 return E_WRITE_PARCEL_ERR;
755 }
756
757 if (!data.WriteInt32(state)) {
758 LOGE("StorageManagerProxy::NotifyVolumeStateChanged, WriteInt failed");
759 return E_WRITE_PARCEL_ERR;
760 }
761
762 return SendRequest(
763 static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_VOLUME_STATE_CHANGED), data, reply,
764 option);
765 }
766
Mount(std::string volumeId)767 int32_t StorageManagerProxy::Mount(std::string volumeId)
768 {
769 LOGI("StorageManagerProxy::Mount, volumeId:%{public}s", volumeId.c_str());
770 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
771 MessageParcel data;
772 MessageParcel reply;
773 MessageOption option(MessageOption::TF_SYNC);
774 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
775 LOGE("StorageManagerProxy::Mount, WriteInterfaceToken failed");
776 return E_WRITE_DESCRIPTOR_ERR;
777 }
778
779 if (!data.WriteString(volumeId)) {
780 LOGE("StorageManagerProxy::Mount, WriteString failed");
781 return E_WRITE_PARCEL_ERR;
782 }
783 int32_t err = SendRequest(
784 static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT), data, reply, option);
785 if (err != E_OK) {
786 return err;
787 }
788 return reply.ReadInt32();
789 }
790
Unmount(std::string volumeId)791 int32_t StorageManagerProxy::Unmount(std::string volumeId)
792 {
793 LOGI("StorageManagerProxy::Unmount, volumeId:%{public}s", volumeId.c_str());
794 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
795 MessageParcel data;
796 MessageParcel reply;
797 MessageOption option(MessageOption::TF_SYNC);
798 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
799 LOGE("StorageManagerProxy::Unmount, WriteInterfaceToken failed");
800 return E_WRITE_DESCRIPTOR_ERR;
801 }
802
803 if (!data.WriteString(volumeId)) {
804 LOGE("StorageManagerProxy::Unmount, WriteString failed");
805 return E_WRITE_PARCEL_ERR;
806 }
807 int32_t err = SendRequest(
808 static_cast<int32_t>(StorageManagerInterfaceCode::UNMOUNT), data, reply, option);
809 if (err != E_OK) {
810 return err;
811 }
812 return reply.ReadInt32();
813 }
814
GetAllVolumes(std::vector<VolumeExternal> & vecOfVol)815 int32_t StorageManagerProxy::GetAllVolumes(std::vector<VolumeExternal> &vecOfVol)
816 {
817 LOGI("StorageManagerProxy::GetAllVolumes");
818 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
819 MessageParcel data;
820 MessageParcel reply;
821 MessageOption option(MessageOption::TF_SYNC);
822 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
823 LOGE("StorageManagerProxy::GetAllVolumes, WriteInterfaceToken failed");
824 return E_WRITE_DESCRIPTOR_ERR;
825 }
826
827 int32_t err = SendRequest(
828 static_cast<int32_t>(StorageManagerInterfaceCode::GET_ALL_VOLUMES), data, reply, option);
829 if (err != E_OK) {
830 return err;
831 }
832 err = reply.ReadInt32();
833 if (err != E_OK) {
834 return err;
835 }
836 uint size = reply.ReadUint32();
837 if (size == 0) {
838 return reply.ReadInt32();
839 }
840 for (uint32_t i = 0; i < size; i++) {
841 std::unique_ptr<VolumeExternal> ve = VolumeExternal::Unmarshalling(reply);
842 LOGI("StorageManagerProxy::GetAllVolumes push %{public}s", ve->GetId().c_str());
843 vecOfVol.push_back(*ve);
844 }
845 return E_OK;
846 }
847
NotifyDiskCreated(Disk disk)848 int32_t StorageManagerProxy::NotifyDiskCreated(Disk disk)
849 {
850 LOGI("StorageManagerProxy::NotifyDiskCreate, diskId:%{public}s", GetAnonyString(disk.GetDiskId()).c_str());
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 LOGE("StorageManagerProxy::NotifyDiskCreate, WriteInterfaceToken failed");
857 return E_WRITE_DESCRIPTOR_ERR;
858 }
859
860 if (!disk.Marshalling(data)) {
861 LOGE("StorageManagerProxy::NotifyDiskCreate, WriteDiskInfo failed");
862 return E_WRITE_PARCEL_ERR;
863 }
864
865 return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_DISK_CREATED), data, reply, option);
866 }
867
NotifyDiskDestroyed(std::string diskId)868 int32_t StorageManagerProxy::NotifyDiskDestroyed(std::string diskId)
869 {
870 LOGI("StorageManagerProxy::NotifyDiskDestroyed, diskId:%{public}s", GetAnonyString(diskId).c_str());
871 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
872 MessageParcel data;
873 MessageParcel reply;
874 MessageOption option(MessageOption::TF_SYNC);
875 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
876 LOGE("StorageManagerProxy::NotifyDiskDestroyed, WriteInterfaceToken failed");
877 return E_WRITE_DESCRIPTOR_ERR;
878 }
879 if (!data.WriteString(diskId)) {
880 LOGE("StorageManagerProxy::NotifyDiskDestroyed, WriteString failed");
881 return E_WRITE_PARCEL_ERR;
882 }
883 return SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_DISK_DESTROYED), data, reply, option);
884 }
885
Partition(std::string diskId,int32_t type)886 int32_t StorageManagerProxy::Partition(std::string diskId, int32_t type)
887 {
888 LOGI("StorageManagerProxy::Partition, diskId:%{public}s", GetAnonyString(diskId).c_str());
889 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
890 MessageParcel data;
891 MessageParcel reply;
892 MessageOption option(MessageOption::TF_SYNC);
893 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
894 LOGE("StorageManagerProxy::Partition, WriteInterfaceToken failed");
895 return E_WRITE_DESCRIPTOR_ERR;
896 }
897 if (!data.WriteString(diskId)) {
898 LOGE("StorageManagerProxy::Partition, WriteString failed");
899 return E_WRITE_PARCEL_ERR;
900 }
901 if (!data.WriteInt32(type)) {
902 LOGE("StorageManagerProxy::Partition WriteInt32 failed");
903 return E_WRITE_PARCEL_ERR;
904 }
905 int32_t err = SendRequest(
906 static_cast<int32_t>(StorageManagerInterfaceCode::PARTITION), data, reply, option);
907 if (err != E_OK) {
908 return err;
909 }
910 return reply.ReadInt32();
911 }
912
GetAllDisks(std::vector<Disk> & vecOfDisk)913 int32_t StorageManagerProxy::GetAllDisks(std::vector<Disk> &vecOfDisk)
914 {
915 LOGI("StorageManagerProxy::GetAllDisks");
916 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
917 MessageParcel data;
918 MessageParcel reply;
919 MessageOption option(MessageOption::TF_SYNC);
920 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
921 LOGE("StorageManagerProxy::GetAllDisks, WriteInterfaceToken failed");
922 return E_WRITE_DESCRIPTOR_ERR;
923 }
924
925 int32_t err = SendRequest(
926 static_cast<int32_t>(StorageManagerInterfaceCode::GET_ALL_DISKS), data, reply, option);
927 if (err != E_OK) {
928 return err;
929 }
930 err = reply.ReadInt32();
931 if (err != E_OK) {
932 return err;
933 }
934 uint size = reply.ReadUint32();
935 if (size == 0) {
936 return reply.ReadInt32();
937 }
938 for (uint32_t i = 0; i < size; i++) {
939 std::unique_ptr<Disk> disk = Disk::Unmarshalling(reply);
940 LOGI("StorageManagerProxy::GetAllDisks push %{public}s", GetAnonyString(disk->GetDiskId()).c_str());
941 vecOfDisk.push_back(*disk);
942 }
943 return E_OK;
944 }
945
GetSystemSize(int64_t & systemSize)946 int32_t StorageManagerProxy::GetSystemSize(int64_t &systemSize)
947 {
948 LOGI("StorageManagerProxy::GetSystemSize");
949 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
950 MessageParcel data;
951 MessageParcel reply;
952 MessageOption option(MessageOption::TF_SYNC);
953 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
954 LOGE("StorageManagerProxy::GetSystemSize WriteInterfaceToken failed");
955 return E_WRITE_DESCRIPTOR_ERR;
956 }
957
958 int32_t err = SendRequest(
959 static_cast<int32_t>(StorageManagerInterfaceCode::GET_SYSTEM_SIZE), data, reply, option);
960 if (err != E_OK) {
961 return err;
962 }
963 err = reply.ReadInt32();
964 if (err != E_OK) {
965 return err;
966 }
967 systemSize = reply.ReadInt64();
968 return E_OK;
969 }
970
GetTotalSize(int64_t & totalSize)971 int32_t StorageManagerProxy::GetTotalSize(int64_t &totalSize)
972 {
973 LOGI("StorageManagerProxy::GetTotalSize");
974 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
975 MessageParcel data;
976 MessageParcel reply;
977 MessageOption option(MessageOption::TF_SYNC);
978 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
979 LOGE("StorageManagerProxy::GetTotalSize WriteInterfaceToken failed");
980 return E_WRITE_DESCRIPTOR_ERR;
981 }
982
983 int32_t err = SendRequest(
984 static_cast<int32_t>(StorageManagerInterfaceCode::GET_TOTAL_SIZE), data, reply, option);
985 if (err != E_OK) {
986 return err;
987 }
988 err = reply.ReadInt32();
989 if (err != E_OK) {
990 return err;
991 }
992 totalSize = reply.ReadInt64();
993 return E_OK;
994 }
995
GetFreeSize(int64_t & freeSize)996 int32_t StorageManagerProxy::GetFreeSize(int64_t &freeSize)
997 {
998 LOGI("StorageManagerProxy::GetFreeSize");
999 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1000 MessageParcel data;
1001 MessageParcel reply;
1002 MessageOption option(MessageOption::TF_SYNC);
1003 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1004 LOGE("StorageManagerProxy::GetFreeSize WriteInterfaceToken failed");
1005 return E_WRITE_DESCRIPTOR_ERR;
1006 }
1007
1008 int32_t err = SendRequest(
1009 static_cast<int32_t>(StorageManagerInterfaceCode::GET_FREE_SIZE), data, reply, option);
1010 if (err != E_OK) {
1011 return err;
1012 }
1013 err = reply.ReadInt32();
1014 if (err != E_OK) {
1015 return err;
1016 }
1017 freeSize = reply.ReadInt64();
1018 return E_OK;
1019 }
1020
GetUserStorageStats(StorageStats & storageStats)1021 int32_t StorageManagerProxy::GetUserStorageStats(StorageStats &storageStats)
1022 {
1023 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1024 StorageStats result;
1025 MessageParcel data;
1026 MessageParcel reply;
1027 MessageOption option(MessageOption::TF_SYNC);
1028 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1029 return E_WRITE_DESCRIPTOR_ERR;
1030 }
1031
1032 int32_t err = SendRequest(
1033 static_cast<int32_t>(StorageManagerInterfaceCode::GET_CURR_USER_STATS), data, reply, option);
1034 if (err != E_OK) {
1035 return err;
1036 }
1037 err = reply.ReadInt32();
1038 if (err != E_OK) {
1039 return err;
1040 }
1041 storageStats = *StorageStats::Unmarshalling(reply);
1042 return E_OK;
1043 }
1044
GetUserStorageStats(int32_t userId,StorageStats & storageStats)1045 int32_t StorageManagerProxy::GetUserStorageStats(int32_t userId, StorageStats &storageStats)
1046 {
1047 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1048 StorageStats result;
1049 MessageParcel data;
1050 MessageParcel reply;
1051 MessageOption option(MessageOption::TF_SYNC);
1052 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1053 return E_WRITE_DESCRIPTOR_ERR;
1054 }
1055
1056 if (!data.WriteInt32(userId)) {
1057 return E_WRITE_PARCEL_ERR;
1058 }
1059 int32_t err = SendRequest(
1060 static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS), data, reply, option);
1061 if (err != E_OK) {
1062 return err;
1063 }
1064 err = reply.ReadInt32();
1065 if (err != E_OK) {
1066 return err;
1067 }
1068 storageStats = *StorageStats::Unmarshalling(reply);
1069 return E_OK;
1070 }
1071
GetCurrentBundleStats(BundleStats & bundleStats,uint32_t statFlag)1072 int32_t StorageManagerProxy::GetCurrentBundleStats(BundleStats &bundleStats, uint32_t statFlag)
1073 {
1074 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1075 BundleStats result;
1076 MessageParcel data;
1077 MessageParcel reply;
1078 MessageOption option(MessageOption::TF_SYNC);
1079 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1080 return E_WRITE_DESCRIPTOR_ERR;
1081 }
1082
1083 if (!data.WriteUint32(statFlag)) {
1084 return E_WRITE_PARCEL_ERR;
1085 }
1086
1087 int32_t err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::GET_CURR_BUNDLE_STATS), data, reply,
1088 option);
1089 if (err != E_OK) {
1090 return err;
1091 }
1092 err = reply.ReadInt32();
1093 if (err != E_OK) {
1094 return err;
1095 }
1096 bundleStats = *BundleStats::Unmarshalling(reply);
1097 return E_OK;
1098 }
1099
GetVolumeByUuid(std::string fsUuid,VolumeExternal & vc)1100 int32_t StorageManagerProxy::GetVolumeByUuid(std::string fsUuid, VolumeExternal &vc)
1101 {
1102 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1103 MessageParcel data;
1104 MessageParcel reply;
1105 MessageOption option(MessageOption::TF_SYNC);
1106 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1107 return E_WRITE_DESCRIPTOR_ERR;
1108 }
1109
1110 if (!data.WriteString(fsUuid)) {
1111 return E_WRITE_PARCEL_ERR;
1112 }
1113
1114 int32_t err = SendRequest(
1115 static_cast<int32_t>(StorageManagerInterfaceCode::GET_VOL_BY_UUID), data, reply, option);
1116 if (err != E_OK) {
1117 return err;
1118 }
1119 vc = *VolumeExternal::Unmarshalling(reply);
1120 return reply.ReadInt32();
1121 }
1122
GetVolumeById(std::string volumeId,VolumeExternal & vc)1123 int32_t StorageManagerProxy::GetVolumeById(std::string volumeId, VolumeExternal &vc)
1124 {
1125 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1126 MessageParcel data;
1127 MessageParcel reply;
1128 MessageOption option(MessageOption::TF_SYNC);
1129 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1130 return E_WRITE_DESCRIPTOR_ERR;
1131 }
1132
1133 if (!data.WriteString(volumeId)) {
1134 return E_WRITE_PARCEL_ERR;
1135 }
1136
1137 int32_t err = SendRequest(
1138 static_cast<int32_t>(StorageManagerInterfaceCode::GET_VOL_BY_ID), data, reply, option);
1139 if (err != E_OK) {
1140 return err;
1141 }
1142 vc = *VolumeExternal::Unmarshalling(reply);
1143 return reply.ReadInt32();
1144 }
1145
SetVolumeDescription(std::string fsUuid,std::string description)1146 int32_t StorageManagerProxy::SetVolumeDescription(std::string fsUuid, std::string description)
1147 {
1148 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1149 MessageParcel data;
1150 MessageParcel reply;
1151 MessageOption option(MessageOption::TF_SYNC);
1152 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1153 return E_WRITE_DESCRIPTOR_ERR;
1154 }
1155
1156 if (!data.WriteString(fsUuid)) {
1157 return E_WRITE_PARCEL_ERR;
1158 }
1159
1160 if (!data.WriteString(description)) {
1161 return E_WRITE_PARCEL_ERR;
1162 }
1163
1164 int32_t err = SendRequest(
1165 static_cast<int32_t>(StorageManagerInterfaceCode::SET_VOL_DESC), data, reply, option);
1166 if (err != E_OK) {
1167 return err;
1168 }
1169 return reply.ReadInt32();
1170 }
1171
Format(std::string volumeId,std::string fsType)1172 int32_t StorageManagerProxy::Format(std::string volumeId, std::string fsType)
1173 {
1174 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1175 MessageParcel data;
1176 MessageParcel reply;
1177 MessageOption option(MessageOption::TF_SYNC);
1178 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1179 return E_WRITE_DESCRIPTOR_ERR;
1180 }
1181
1182 if (!data.WriteString(volumeId)) {
1183 return E_WRITE_PARCEL_ERR;
1184 }
1185
1186 if (!data.WriteString(fsType)) {
1187 return E_WRITE_PARCEL_ERR;
1188 }
1189
1190 int32_t err = SendRequest(
1191 static_cast<int32_t>(StorageManagerInterfaceCode::FORMAT), data, reply, option);
1192 if (err != E_OK) {
1193 return err;
1194 }
1195 return reply.ReadInt32();
1196 }
1197
GetDiskById(std::string diskId,Disk & disk)1198 int32_t StorageManagerProxy::GetDiskById(std::string diskId, Disk &disk)
1199 {
1200 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1201 MessageParcel data;
1202 MessageParcel reply;
1203 MessageOption option(MessageOption::TF_SYNC);
1204 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1205 return E_WRITE_DESCRIPTOR_ERR;
1206 }
1207
1208 if (!data.WriteString(diskId)) {
1209 return E_WRITE_PARCEL_ERR;
1210 }
1211
1212 int32_t err = SendRequest(
1213 static_cast<int32_t>(StorageManagerInterfaceCode::GET_DISK_BY_ID), data, reply, option);
1214 if (err != E_OK) {
1215 return err;
1216 }
1217 disk = *Disk::Unmarshalling(reply);
1218 return reply.ReadInt32();
1219 }
1220
CreateShareFile(const std::vector<std::string> & uriList,uint32_t tokenId,uint32_t flag)1221 std::vector<int32_t> StorageManagerProxy::CreateShareFile(const std::vector<std::string> &uriList,
1222 uint32_t tokenId, uint32_t flag)
1223 {
1224 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1225 MessageParcel data;
1226 MessageParcel reply;
1227 MessageOption option(MessageOption::TF_SYNC);
1228
1229 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1230 return std::vector<int32_t>{E_WRITE_DESCRIPTOR_ERR};
1231 }
1232
1233 if (!data.WriteStringVector(uriList)) {
1234 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
1235 }
1236
1237 if (!data.WriteUint32(tokenId)) {
1238 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
1239 }
1240
1241 if (!data.WriteUint32(flag)) {
1242 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
1243 }
1244
1245 int32_t err = SendRequest(
1246 static_cast<int32_t>(StorageManagerInterfaceCode::CREATE_SHARE_FILE), data, reply, option);
1247 if (err != E_OK) {
1248 return std::vector<int32_t>{err};
1249 }
1250
1251 std::vector<int32_t> retList;
1252 if (!reply.ReadInt32Vector(&retList)) {
1253 return std::vector<int32_t>{E_WRITE_PARCEL_ERR};
1254 };
1255 return retList;
1256 }
1257
DeleteShareFile(uint32_t tokenId,const std::vector<std::string> & uriList)1258 int32_t StorageManagerProxy::DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &uriList)
1259 {
1260 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1261 MessageParcel data;
1262 MessageParcel reply;
1263 MessageOption option(MessageOption::TF_ASYNC);
1264
1265 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1266 return E_WRITE_DESCRIPTOR_ERR;
1267 }
1268
1269 if (!data.WriteUint32(tokenId)) {
1270 return E_WRITE_PARCEL_ERR;
1271 }
1272
1273 if (!data.WriteStringVector(uriList)) {
1274 return E_WRITE_PARCEL_ERR;
1275 }
1276
1277 int32_t err = SendRequest(
1278 static_cast<int32_t>(StorageManagerInterfaceCode::DELETE_SHARE_FILE), data, reply, option);
1279 if (err != E_OK) {
1280 return err;
1281 }
1282
1283 return reply.ReadInt32();
1284 }
SetBundleQuota(const std::string & bundleName,int32_t uid,const std::string & bundleDataDirPath,int32_t limitSizeMb)1285 int32_t StorageManagerProxy::SetBundleQuota(const std::string &bundleName, int32_t uid,
1286 const std::string &bundleDataDirPath, int32_t limitSizeMb)
1287 {
1288 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1289 MessageParcel data;
1290 MessageParcel reply;
1291 MessageOption option(MessageOption::TF_SYNC);
1292
1293 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1294 return E_WRITE_DESCRIPTOR_ERR;
1295 }
1296
1297 if (!data.WriteString(bundleName)) {
1298 return E_WRITE_PARCEL_ERR;
1299 }
1300
1301 if (!data.WriteInt32(uid)) {
1302 return E_WRITE_PARCEL_ERR;
1303 }
1304
1305 if (!data.WriteString(bundleDataDirPath)) {
1306 return E_WRITE_PARCEL_ERR;
1307 }
1308
1309 if (!data.WriteInt32(limitSizeMb)) {
1310 return E_WRITE_PARCEL_ERR;
1311 }
1312
1313 int32_t err = SendRequest(
1314 static_cast<int32_t>(StorageManagerInterfaceCode::SET_BUNDLE_QUOTA), data, reply, option);
1315 if (err != E_OK) {
1316 return err;
1317 }
1318
1319 return reply.ReadInt32();
1320 }
1321
1322
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)1323 int32_t StorageManagerProxy::GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames,
1324 const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes,
1325 std::vector<int64_t> &incPkgFileSizes)
1326 {
1327 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1328 MessageParcel data;
1329 MessageParcel reply;
1330 MessageOption option(MessageOption::TF_SYNC);
1331 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1332 return E_WRITE_DESCRIPTOR_ERR;
1333 }
1334
1335 if (!data.WriteInt32(userId)) {
1336 return E_WRITE_PARCEL_ERR;
1337 }
1338
1339 if (!data.WriteStringVector(bundleNames)) {
1340 return E_WRITE_PARCEL_ERR;
1341 }
1342
1343 if (!data.WriteInt64Vector(incrementalBackTimes)) {
1344 return E_WRITE_PARCEL_ERR;
1345 }
1346
1347 int32_t err = SendRequest(
1348 static_cast<int32_t>(StorageManagerInterfaceCode::GET_BUNDLE_STATS_INCREASE), data, reply,
1349 option);
1350 if (err != E_OK) {
1351 return err;
1352 }
1353 err = reply.ReadInt32();
1354 if (err != E_OK) {
1355 return err;
1356 }
1357 if (!reply.ReadInt64Vector(&pkgFileSizes)) {
1358 LOGE("StorageManagerProxy::SendRequest read pkgFileSizes");
1359 return E_WRITE_REPLY_ERR;
1360 }
1361 if (!reply.ReadInt64Vector(&incPkgFileSizes)) {
1362 LOGE("StorageManagerProxy::SendRequest read incPkgFileSizes");
1363 return E_WRITE_REPLY_ERR;
1364 }
1365
1366 return E_OK;
1367 }
1368
UpdateMemoryPara(int32_t size,int32_t & oldSize)1369 int32_t StorageManagerProxy::UpdateMemoryPara(int32_t size, int32_t &oldSize)
1370 {
1371 MessageParcel data;
1372 MessageParcel reply;
1373 MessageOption option(MessageOption::TF_SYNC);
1374 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1375 return E_WRITE_DESCRIPTOR_ERR;
1376 }
1377 if (!data.WriteInt32(size)) {
1378 return E_WRITE_PARCEL_ERR;
1379 }
1380
1381 int32_t err = SendRequest(
1382 static_cast<int32_t>(StorageManagerInterfaceCode::UPDATE_MEM_PARA), data, reply, option);
1383 if (err != E_OK) {
1384 return err;
1385 }
1386 err = reply.ReadInt32();
1387 if (err != E_OK) {
1388 return err;
1389 }
1390 oldSize = reply.ReadInt32();
1391
1392 return E_OK;
1393 }
1394
NotifyMtpMounted(const std::string & id,const std::string & path,const std::string & desc,const std::string & uuid)1395 int32_t StorageManagerProxy::NotifyMtpMounted(const std::string &id, const std::string &path, const std::string &desc,
1396 const std::string &uuid)
1397 {
1398 LOGI("StorageManagerProxy::NotifyMtpMounted, path:%{public}s", path.c_str());
1399 MessageParcel data;
1400 MessageParcel reply;
1401 MessageOption option(MessageOption::TF_SYNC);
1402 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1403 LOGE("StorageManagerProxy::NotifyMtpMounted, WriteInterfaceToken failed");
1404 return E_WRITE_DESCRIPTOR_ERR;
1405 }
1406
1407 if (!data.WriteString(id)) {
1408 LOGE("StorageManagerProxy::NotifyMtpMounted id, WriteInterfaceToken failed");
1409 return E_WRITE_PARCEL_ERR;
1410 }
1411
1412 if (!data.WriteString(path)) {
1413 LOGE("StorageManagerProxy::NotifyMtpMounted path, WriteInterfaceToken failed");
1414 return E_WRITE_PARCEL_ERR;
1415 }
1416
1417 if (!data.WriteString(desc)) {
1418 LOGE("StorageManagerProxy::NotifyMtpMounted desc, WriteInterfaceToken failed");
1419 return E_WRITE_PARCEL_ERR;
1420 }
1421
1422 if (!data.WriteString(uuid)) {
1423 LOGE("StorageManagerProxy::NotifyMtpMounted uuid, WriteInterfaceToken failed");
1424 return E_WRITE_PARCEL_ERR;
1425 }
1426
1427 int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_MTP_MOUNT), data, reply, option);
1428 if (err != E_OK) {
1429 LOGE("StorageManagerProxy::NotifyMtpMounted, SendRequest failed");
1430 return err;
1431 }
1432 return reply.ReadInt32();
1433 }
1434
NotifyMtpUnmounted(const std::string & id,const std::string & path,const bool isBadRemove)1435 int32_t StorageManagerProxy::NotifyMtpUnmounted(const std::string &id, const std::string &path, const bool isBadRemove)
1436 {
1437 LOGI("StorageManagerProxy::NotifyMtpUnmounted, path:%{public}s", path.c_str());
1438 MessageParcel data;
1439 MessageParcel reply;
1440 MessageOption option(MessageOption::TF_SYNC);
1441 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1442 LOGE("StorageManagerProxy::NotifyMtpUnmounted, WriteInterfaceToken failed");
1443 return E_WRITE_DESCRIPTOR_ERR;
1444 }
1445
1446 if (!data.WriteString(id)) {
1447 LOGE("StorageManagerProxy::NotifyMtpUnmounted id, WriteInterfaceToken failed");
1448 return E_WRITE_DESCRIPTOR_ERR;
1449 }
1450
1451 if (!data.WriteString(path)) {
1452 LOGE("StorageManagerProxy::NotifyMtpUnmounted path, WriteInterfaceToken failed");
1453 return E_WRITE_DESCRIPTOR_ERR;
1454 }
1455
1456 if (!data.WriteBool(isBadRemove)) {
1457 LOGE("StorageManagerProxy::NotifyMtpUnmounted isBadRemove, WriteInterfaceToken failed");
1458 return E_WRITE_DESCRIPTOR_ERR;
1459 }
1460
1461 int err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::NOTIFY_MTP_UNMOUNT), data, reply, option);
1462 if (err != E_OK) {
1463 LOGE("StorageManagerProxy::NotifyMtpUnmounted, SendRequest failed");
1464 return err;
1465 }
1466 return reply.ReadInt32();
1467 }
1468
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1469 int32_t StorageManagerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
1470 MessageOption &option)
1471 {
1472 sptr<IRemoteObject> remote = Remote();
1473 if (remote == nullptr) {
1474 LOGE("remote is nullptr, code = %{public}d", code);
1475 return E_REMOTE_IS_NULLPTR;
1476 }
1477
1478 int32_t result = remote->SendRequest(code, data, reply, option);
1479 if (result != E_OK) {
1480 LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
1481 return result;
1482 }
1483
1484 return E_OK;
1485 }
1486
GetUserStorageStatsByType(int32_t userId,StorageStats & storageStats,std::string type)1487 int32_t StorageManagerProxy::GetUserStorageStatsByType(int32_t userId, StorageStats &storageStats, std::string type)
1488 {
1489 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1490 StorageStats result;
1491 MessageParcel data;
1492 MessageParcel reply;
1493 MessageOption option(MessageOption::TF_SYNC);
1494 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1495 return E_WRITE_DESCRIPTOR_ERR;
1496 }
1497
1498 if (!data.WriteInt32(userId)) {
1499 return E_WRITE_PARCEL_ERR;
1500 }
1501
1502 if (!data.WriteString(type)) {
1503 return E_WRITE_PARCEL_ERR;
1504 }
1505 int32_t err = SendRequest(
1506 static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_STATS_BY_TYPE), data, reply,
1507 option);
1508 if (err != E_OK) {
1509 return err;
1510 }
1511 err = reply.ReadInt32();
1512 if (err != E_OK) {
1513 return err;
1514 }
1515 storageStats = *StorageStats::Unmarshalling(reply);
1516 return E_OK;
1517 }
1518
MountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)1519 int32_t StorageManagerProxy::MountDfsDocs(int32_t userId, const std::string &relativePath,
1520 const std::string &networkId, const std::string &deviceId)
1521 {
1522 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1523 MessageParcel data;
1524 MessageParcel reply;
1525 MessageOption option(MessageOption::TF_SYNC);
1526
1527 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1528 LOGE("StorageManagerProxy::MountDfsDocs, WriteInterfaceToken failed");
1529 return E_WRITE_DESCRIPTOR_ERR;
1530 }
1531 if (!data.WriteInt32(userId) || !data.WriteString(relativePath) ||
1532 !data.WriteString(networkId) || !data.WriteString(deviceId)) {
1533 LOGE("StorageManagerProxy::MountDfsDocs, Write failed");
1534 return E_WRITE_PARCEL_ERR;
1535 }
1536
1537 int32_t err = SendRequest(
1538 static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT_DFS_DOCS), data, reply, option);
1539 if (err != E_OK) {
1540 return err;
1541 }
1542
1543 return reply.ReadInt32();
1544 }
1545
UMountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)1546 int32_t StorageManagerProxy::UMountDfsDocs(int32_t userId, const std::string &relativePath,
1547 const std::string &networkId, const std::string &deviceId)
1548 {
1549 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1550 MessageParcel data;
1551 MessageParcel reply;
1552 MessageOption option(MessageOption::TF_SYNC);
1553
1554 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1555 LOGE("StorageManagerProxy::UMountDfsDocs, WriteInterfaceToken failed");
1556 return E_WRITE_DESCRIPTOR_ERR;
1557 }
1558 if (!data.WriteInt32(userId) || !data.WriteString(relativePath) ||
1559 !data.WriteString(networkId) || !data.WriteString(deviceId)) {
1560 LOGE("StorageManagerProxy::UMountDfsDocs, Write failed");
1561 return E_WRITE_PARCEL_ERR;
1562 }
1563
1564 int32_t err = SendRequest(
1565 static_cast<int32_t>(StorageManagerInterfaceCode::UMOUNT_DFS_DOCS), data, reply, option);
1566 if (err != E_OK) {
1567 return err;
1568 }
1569
1570 return reply.ReadInt32();
1571 }
1572
GetFileEncryptStatus(uint32_t userId,bool & isEncrypted,bool needCheckDirMount)1573 int32_t StorageManagerProxy::GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount)
1574 {
1575 LOGI("user ID: %{public}u", userId);
1576 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1577 MessageParcel data;
1578 MessageParcel reply;
1579 MessageOption option(MessageOption::TF_SYNC);
1580 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1581 LOGE("WriteInterfaceToken failed");
1582 return E_WRITE_DESCRIPTOR_ERR;
1583 }
1584 if (!data.WriteUint32(userId)) {
1585 LOGE("Write user ID failed");
1586 return E_WRITE_PARCEL_ERR;
1587 }
1588 if (!data.WriteBool(needCheckDirMount)) {
1589 LOGE("Write user ID failed");
1590 return E_WRITE_PARCEL_ERR;
1591 }
1592 int32_t err = SendRequest(
1593 static_cast<int32_t>(StorageManagerInterfaceCode::GET_FILE_ENCRYPT_STATUS), data, reply, option);
1594 if (err != E_OK) {
1595 return err;
1596 }
1597 isEncrypted = reply.ReadBool();
1598 return reply.ReadInt32();
1599 }
1600
MountMediaFuse(int32_t userId,int32_t & devFd)1601 int32_t StorageManagerProxy::MountMediaFuse(int32_t userId, int32_t &devFd)
1602 {
1603 #ifdef STORAGE_SERVICE_MEDIA_FUSE
1604 MessageParcel data;
1605 MessageParcel reply;
1606 MessageOption option(MessageOption::TF_SYNC);
1607
1608 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1609 LOGE("WriteInterfaceToken failed");
1610 return E_WRITE_DESCRIPTOR_ERR;
1611 }
1612
1613 if (!data.WriteInt32(userId)) {
1614 LOGE("WriteInt32 failed");
1615 return E_WRITE_PARCEL_ERR;
1616 }
1617
1618 int32_t err = SendRequest(
1619 static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT_MEDIA_FUSE), data, reply, option);
1620 if (err != E_OK) {
1621 return err;
1622 }
1623
1624 int32_t ret = reply.ReadInt32();
1625 if (ret == E_OK) {
1626 devFd = reply.ReadFileDescriptor();
1627 }
1628
1629 return ret;
1630 #else
1631 return E_OK;
1632 #endif
1633 }
1634
UMountMediaFuse(int32_t userId)1635 int32_t StorageManagerProxy::UMountMediaFuse(int32_t userId)
1636 {
1637 #ifdef STORAGE_SERVICE_MEDIA_FUSE
1638 MessageParcel data;
1639 MessageParcel reply;
1640 MessageOption option(MessageOption::TF_SYNC);
1641
1642 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1643 LOGE("WriteInterfaceToken failed");
1644 return E_WRITE_DESCRIPTOR_ERR;
1645 }
1646
1647 if (!data.WriteInt32(userId)) {
1648 LOGE("WriteInt32 failed");
1649 return E_WRITE_PARCEL_ERR;
1650 }
1651
1652 int32_t err = SendRequest(
1653 static_cast<int32_t>(StorageManagerInterfaceCode::UMOUNT_MEDIA_FUSE), data, reply, option);
1654 if (err != E_OK) {
1655 return err;
1656 }
1657
1658 return reply.ReadInt32();
1659 #else
1660 return E_OK;
1661 #endif
1662 }
1663
GetUserNeedActiveStatus(uint32_t userId,bool & needActive)1664 int32_t StorageManagerProxy::GetUserNeedActiveStatus(uint32_t userId, bool &needActive)
1665 {
1666 LOGI("user ID: %{public}u", userId);
1667 HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__);
1668 MessageParcel data;
1669 MessageParcel reply;
1670 MessageOption option(MessageOption::TF_SYNC);
1671 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1672 LOGE("WriteInterfaceToken failed");
1673 return E_WRITE_DESCRIPTOR_ERR;
1674 }
1675 if (!data.WriteUint32(userId)) {
1676 LOGE("Write user ID failed");
1677 return E_WRITE_PARCEL_ERR;
1678 }
1679 int32_t err = SendRequest(
1680 static_cast<int32_t>(StorageManagerInterfaceCode::GET_USER_NEED_ACTIVE_STATUS), data, reply, option);
1681 if (err != E_OK) {
1682 return err;
1683 }
1684 needActive = reply.ReadBool();
1685 return reply.ReadInt32();
1686 }
1687
MountFileMgrFuse(int32_t userId,const std::string & path,int32_t & fuseFd)1688 int32_t StorageManagerProxy::MountFileMgrFuse(int32_t userId, const std::string &path, int32_t &fuseFd)
1689 {
1690 MessageParcel data;
1691 MessageParcel reply;
1692 MessageOption option(MessageOption::TF_SYNC);
1693
1694 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1695 LOGE("WriteInterfaceToken failed");
1696 return E_WRITE_DESCRIPTOR_ERR;
1697 }
1698
1699 if (!data.WriteInt32(userId) || !data.WriteString(path)) {
1700 LOGE("WriteInt32 failed");
1701 return E_WRITE_PARCEL_ERR;
1702 }
1703
1704 int32_t err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::MOUNT_FILE_MGR_FUSE),
1705 data, reply, option);
1706 if (err != E_OK) {
1707 return err;
1708 }
1709 int32_t ret = reply.ReadInt32();
1710 if (ret == E_OK) {
1711 fuseFd = reply.ReadFileDescriptor();
1712 }
1713 return ret;
1714 }
1715
UMountFileMgrFuse(int32_t userId,const std::string & path)1716 int32_t StorageManagerProxy::UMountFileMgrFuse(int32_t userId, const std::string &path)
1717 {
1718 MessageParcel data;
1719 MessageParcel reply;
1720 MessageOption option(MessageOption::TF_SYNC);
1721
1722 if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
1723 LOGE("WriteInterfaceToken failed");
1724 return E_WRITE_DESCRIPTOR_ERR;
1725 }
1726
1727 if (!data.WriteInt32(userId) || !data.WriteString(path)) {
1728 LOGE("WriteInt32 failed");
1729 return E_WRITE_PARCEL_ERR;
1730 }
1731
1732 int32_t err = SendRequest(static_cast<int32_t>(StorageManagerInterfaceCode::UMOUNT_FILE_MGR_FUSE),
1733 data, reply, option);
1734 if (err != E_OK) {
1735 return err;
1736 }
1737 return reply.ReadInt32();
1738 }
1739 } // StorageManager
1740 } // OHOS
1741