• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ipc/storage_manager_stub.h"
17 #include "accesstoken_kit.h"
18 #include "ipc_skeleton.h"
19 #include "storage_service_errno.h"
20 #include "storage_service_log.h"
21 
22 namespace OHOS {
23 namespace StorageManager {
24 constexpr pid_t ACCOUNT_UID = 3058;
25 const std::string PERMISSION_STORAGE_MANAGER = "ohos.permission.STORAGE_MANAGER";
26 const std::string PERMISSION_MOUNT_MANAGER = "ohos.permission.MOUNT_UNMOUNT_MANAGER";
27 const std::string PERMISSION_FORMAT_MANAGER = "ohos.permission.MOUNT_FORMAT_MANAGER";
CheckClientPermission(const std::string & permissionStr)28 bool CheckClientPermission(const std::string& permissionStr)
29 {
30     Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID();
31     auto uid = IPCSkeleton::GetCallingUid();
32     auto tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenCaller);
33     int res = Security::AccessToken::PermissionState::PERMISSION_DENIED;
34     if (tokenType == Security::AccessToken::TOKEN_NATIVE && uid == ACCOUNT_UID) {
35         res = Security::AccessToken::PermissionState::PERMISSION_GRANTED;
36     } else {
37         res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, permissionStr);
38     }
39 
40     if (res == Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
41         LOGI("StorageMangaer permissionCheck pass!");
42         return true;
43     }
44     LOGE("StorageManager permissionCheck error, need %{public}s", permissionStr.c_str());
45     return false;
46 }
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)47 int32_t StorageManagerStub::OnRemoteRequest(uint32_t code,
48     MessageParcel &data, MessageParcel &reply, MessageOption &option)
49 {
50     auto remoteDescriptor = data.ReadInterfaceToken();
51     if (GetDescriptor() != remoteDescriptor) {
52         return E_PERMISSION_DENIED;
53     }
54 
55     int err = 0;
56     switch (code) {
57         case PREPARE_ADD_USER:
58             err = HandlePrepareAddUser(data, reply);
59             break;
60         case REMOVE_USER:
61             err = HandleRemoveUser(data, reply);
62             break;
63         case PREPARE_START_USER:
64             err = HandlePrepareStartUser(data, reply);
65             break;
66         case STOP_USER:
67             err = HandleStopUser(data, reply);
68             break;
69         case GET_TOTAL:
70             err = HandleGetTotal(data, reply);
71             break;
72         case GET_FREE:
73             err = HandleGetFree(data, reply);
74             break;
75         case GET_SYSTEM_SIZE:
76             err = HandleGetSystemSize(data, reply);
77             break;
78         case GET_TOTAL_SIZE:
79             err = HandleGetTotalSize(data, reply);
80             break;
81         case GET_FREE_SIZE:
82             err = HandleGetFreeSize(data, reply);
83             break;
84         case GET_CURR_USER_STATS:
85             err = HandleGetCurrUserStorageStats(data, reply);
86             break;
87         case GET_USER_STATS:
88             err = HandleGetUserStorageStats(data, reply);
89             break;
90         case GET_CURR_BUNDLE_STATS:
91             err = HandleGetCurrentBundleStats(data, reply);
92             break;
93         case GET_BUNDLE_STATUS:
94             err = HandleGetBundleStatus(data, reply);
95             break;
96         case NOTIFY_VOLUME_CREATED:
97             err = HandleNotifyVolumeCreated(data, reply);
98             break;
99         case NOTIFY_VOLUME_MOUNTED:
100             err = HandleNotifyVolumeMounted(data, reply);
101             break;
102         case NOTIFY_VOLUME_DESTROYED:
103             err = HandleNotifyVolumeDestroyed(data, reply);
104             break;
105         case MOUNT:
106             err = HandleMount(data, reply);
107             break;
108         case UNMOUNT:
109             err = HandleUnmount(data, reply);
110             break;
111         case GET_ALL_VOLUMES:
112             err = HandleGetAllVolumes(data, reply);
113             break;
114         case NOTIFY_DISK_CREATED:
115             err = HandleNotifyDiskCreated(data, reply);
116             break;
117         case NOTIFY_DISK_DESTROYED:
118             err = HandleNotifyDiskDestroyed(data, reply);
119             break;
120         case PARTITION:
121             err = HandlePartition(data, reply);
122             break;
123         case GET_ALL_DISKS:
124             err = HandleGetAllDisks(data, reply);
125             break;
126         case GET_VOL_BY_UUID:
127             err = HandleGetVolumeByUuid(data, reply);
128             break;
129         case GET_VOL_BY_ID:
130             err = HandleGetVolumeById(data, reply);
131             break;
132         case SET_VOL_DESC:
133             err = HandleSetVolDesc(data, reply);
134             break;
135         case FORMAT:
136             err = HandleFormat(data, reply);
137             break;
138         case GET_DISK_BY_ID:
139             err = HandleGetDiskById(data, reply);
140             break;
141         case CREATE_USER_KEYS:
142             err = HandleGenerateUserKeys(data, reply);
143             break;
144         case DELETE_USER_KEYS:
145             err = HandleDeleteUserKeys(data, reply);
146             break;
147         case UPDATE_USER_AUTH:
148             err = HandleUpdateUserAuth(data, reply);
149             break;
150         case ACTIVE_USER_KEY:
151             err = HandleActiveUserKey(data, reply);
152             break;
153         case INACTIVE_USER_KEY:
154             err = HandleInactiveUserKey(data, reply);
155             break;
156         case UPDATE_KEY_CONTEXT:
157             err = HandleUpdateKeyContext(data, reply);
158             break;
159         case CREATE_SHARE_FILE:
160             err = HandleCreateShareFile(data, reply);
161             break;
162         case DELETE_SHARE_FILE:
163             err = HandleDeleteShareFile(data, reply);
164             break;
165         default: {
166             LOGI("use IPCObjectStub default OnRemoteRequest");
167             err = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
168             break;
169         }
170     }
171     return err;
172 }
173 
HandlePrepareAddUser(MessageParcel & data,MessageParcel & reply)174 int32_t StorageManagerStub::HandlePrepareAddUser(MessageParcel &data, MessageParcel &reply)
175 {
176     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
177         return E_PERMISSION_DENIED;
178     }
179     int32_t userId = data.ReadInt32();
180     uint32_t flags = data.ReadUint32();
181     LOGI("StorageManagerStub::HandlePrepareAddUser, userId:%{public}d", userId);
182     int err = PrepareAddUser(userId, flags);
183     if (!reply.WriteUint32(err)) {
184         LOGE("StorageManagerStub::HandlePrepareAddUser call PrepareAddUser failed");
185         return  E_WRITE_REPLY_ERR;
186     }
187     return E_OK;
188 }
189 
HandleRemoveUser(MessageParcel & data,MessageParcel & reply)190 int32_t StorageManagerStub::HandleRemoveUser(MessageParcel &data, MessageParcel &reply)
191 {
192     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
193         return E_PERMISSION_DENIED;
194     }
195     int32_t userId = data.ReadInt32();
196     uint32_t flags = data.ReadUint32();
197     LOGI("StorageManagerStub::HandleRemoveUser, userId:%{public}d", userId);
198     int err = RemoveUser(userId, flags);
199     if (!reply.WriteUint32(err)) {
200         LOGE("StorageManagerStub::HandleRemoveUser call RemoveUser failed");
201         return E_WRITE_REPLY_ERR;
202     }
203     return E_OK;
204 }
205 
HandlePrepareStartUser(MessageParcel & data,MessageParcel & reply)206 int32_t StorageManagerStub::HandlePrepareStartUser(MessageParcel &data, MessageParcel &reply)
207 {
208     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
209         return E_PERMISSION_DENIED;
210     }
211     int32_t userId = data.ReadInt32();
212     LOGI("StorageManagerStub::HandlePrepareStartUser, userId:%{public}d", userId);
213     int err = PrepareStartUser(userId);
214     if (!reply.WriteUint32(err)) {
215         LOGE("StorageManagerStub::HandlePrepareStartUser call PrepareStartUser failed");
216         return E_WRITE_REPLY_ERR;
217     }
218     return E_OK;
219 }
220 
HandleStopUser(MessageParcel & data,MessageParcel & reply)221 int32_t StorageManagerStub::HandleStopUser(MessageParcel &data, MessageParcel &reply)
222 {
223     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
224         return E_PERMISSION_DENIED;
225     }
226     int32_t userId = data.ReadInt32();
227     LOGI("StorageManagerStub::HandleStopUser, userId:%{public}d", userId);
228     int err = StopUser(userId);
229     if (!reply.WriteUint32(err)) {
230         LOGE("StorageManagerStub::HandleStopUser call StopUser failed");
231         return E_WRITE_REPLY_ERR;
232     }
233     return E_OK;
234 }
235 
HandleGetTotal(MessageParcel & data,MessageParcel & reply)236 int32_t StorageManagerStub::HandleGetTotal(MessageParcel &data, MessageParcel &reply)
237 {
238     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
239         return E_PERMISSION_DENIED;
240     }
241     LOGE("StorageManagerStub::HandleGetTotal Begin.");
242     std::string volumeId = data.ReadString();
243     int64_t totalSize;
244     int32_t err = GetTotalSizeOfVolume(volumeId, totalSize);
245     if (!reply.WriteInt32(err)) {
246         LOGE("StorageManagerStub::HandleGetTotal call OnUserDGetTotalSizeOfVolume failed");
247         return  E_WRITE_REPLY_ERR;
248     }
249     if (!reply.WriteInt64(totalSize)) {
250         return  E_WRITE_REPLY_ERR;
251     }
252     return E_OK;
253 }
254 
HandleGetFree(MessageParcel & data,MessageParcel & reply)255 int32_t StorageManagerStub::HandleGetFree(MessageParcel &data, MessageParcel &reply)
256 {
257     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
258         return E_PERMISSION_DENIED;
259     }
260     std::string volumeId = data.ReadString();
261     int64_t freeSize;
262     int32_t err = GetFreeSizeOfVolume(volumeId, freeSize);
263     if (!reply.WriteInt32(err)) {
264         LOGE("StorageManagerStub::HandleGetFree call GetFreeSizeOfVolume failed");
265         return  E_WRITE_REPLY_ERR;
266     }
267     if (!reply.WriteInt64(freeSize)) {
268         return  E_WRITE_REPLY_ERR;
269     }
270     return E_OK;
271 }
272 
HandleGetBundleStatus(MessageParcel & data,MessageParcel & reply)273 int32_t StorageManagerStub::HandleGetBundleStatus(MessageParcel &data, MessageParcel &reply)
274 {
275     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
276         return E_PERMISSION_DENIED;
277     }
278     std::string pkgName = data.ReadString();
279     BundleStats bundleStats;
280     int32_t err = GetBundleStats(pkgName, bundleStats);
281     if (!reply.WriteInt32(err)) {
282         return  E_WRITE_REPLY_ERR;
283     }
284     if (!bundleStats.Marshalling(reply)) {
285         return  E_WRITE_REPLY_ERR;
286     }
287     return E_OK;
288 }
289 
HandleGetSystemSize(MessageParcel & data,MessageParcel & reply)290 int32_t StorageManagerStub::HandleGetSystemSize(MessageParcel &data, MessageParcel &reply)
291 {
292     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
293         return E_PERMISSION_DENIED;
294     }
295     int64_t systemSize;
296     int32_t err = GetSystemSize(systemSize);
297     if (!reply.WriteInt32(err)) {
298         return  E_WRITE_REPLY_ERR;
299     }
300     if (!reply.WriteInt64(systemSize)) {
301         LOGE("StorageManagerStub::HandleGetFree call GetSystemSize failed");
302         return  E_WRITE_REPLY_ERR;
303     }
304     return E_OK;
305 }
306 
HandleGetTotalSize(MessageParcel & data,MessageParcel & reply)307 int32_t StorageManagerStub::HandleGetTotalSize(MessageParcel &data, MessageParcel &reply)
308 {
309     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
310         return E_PERMISSION_DENIED;
311     }
312     int64_t totalSize;
313     int32_t err = GetTotalSize(totalSize);
314     if (!reply.WriteInt32(err)) {
315         return  E_WRITE_REPLY_ERR;
316     }
317     if (!reply.WriteInt64(totalSize)) {
318         LOGE("StorageManagerStub::HandleGetFree call GetTotalSize failed");
319         return  E_WRITE_REPLY_ERR;
320     }
321     return E_OK;
322 }
323 
HandleGetFreeSize(MessageParcel & data,MessageParcel & reply)324 int32_t StorageManagerStub::HandleGetFreeSize(MessageParcel &data, MessageParcel &reply)
325 {
326     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
327         return E_PERMISSION_DENIED;
328     }
329     int64_t freeSize;
330     int32_t err = GetFreeSize(freeSize);
331     if (!reply.WriteInt32(err)) {
332         return  E_WRITE_REPLY_ERR;
333     }
334     if (!reply.WriteInt64(freeSize)) {
335         LOGE("StorageManagerStub::HandleGetFree call GetFreeSize failed");
336         return  E_WRITE_REPLY_ERR;
337     }
338     return E_OK;
339 }
340 
HandleGetCurrUserStorageStats(MessageParcel & data,MessageParcel & reply)341 int32_t StorageManagerStub::HandleGetCurrUserStorageStats(MessageParcel &data, MessageParcel &reply)
342 {
343     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
344         return E_PERMISSION_DENIED;
345     }
346     StorageStats storageStats;
347     int32_t err = GetUserStorageStats(storageStats);
348     if (!reply.WriteInt32(err)) {
349         return  E_WRITE_REPLY_ERR;
350     }
351     if (!storageStats.Marshalling(reply)) {
352         return  E_WRITE_REPLY_ERR;
353     }
354     return E_OK;
355 }
356 
HandleGetUserStorageStats(MessageParcel & data,MessageParcel & reply)357 int32_t StorageManagerStub::HandleGetUserStorageStats(MessageParcel &data, MessageParcel &reply)
358 {
359     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
360         return E_PERMISSION_DENIED;
361     }
362     int32_t userId = data.ReadInt32();
363     StorageStats storageStats;
364     int32_t err = GetUserStorageStats(userId, storageStats);
365     if (!reply.WriteInt32(err)) {
366         return  E_WRITE_REPLY_ERR;
367     }
368     if (!storageStats.Marshalling(reply)) {
369         return  E_WRITE_REPLY_ERR;
370     }
371     return E_OK;
372 }
373 
HandleGetCurrentBundleStats(MessageParcel & data,MessageParcel & reply)374 int32_t StorageManagerStub::HandleGetCurrentBundleStats(MessageParcel &data, MessageParcel &reply)
375 {
376     BundleStats bundleStats;
377     int32_t err = GetCurrentBundleStats(bundleStats);
378     if (!reply.WriteInt32(err)) {
379         return  E_WRITE_REPLY_ERR;
380     }
381     if (!bundleStats.Marshalling(reply)) {
382         return  E_WRITE_REPLY_ERR;
383     }
384     return E_OK;
385 }
HandleGetAllVolumes(MessageParcel & data,MessageParcel & reply)386 int32_t StorageManagerStub::HandleGetAllVolumes(MessageParcel &data, MessageParcel &reply)
387 {
388     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
389         return E_PERMISSION_DENIED;
390     }
391     std::vector<VolumeExternal> ve;
392     int32_t err = GetAllVolumes(ve);
393     if (!reply.WriteInt32(err)) {
394         return  E_WRITE_REPLY_ERR;
395     }
396     uint size = ve.size();
397     if (size == 0) {
398         LOGE("StorageManagerStub::No volume.");
399         if (!reply.WriteUint32(0)) {
400             return  E_WRITE_REPLY_ERR;
401         }
402         return E_OK;
403     }
404     if (!reply.WriteUint32(ve.size())) {
405         return  E_WRITE_REPLY_ERR;
406     }
407     for (uint i = 0; i < size; i++) {
408         if (!ve[i].Marshalling(reply)) {
409             return  E_WRITE_REPLY_ERR;
410         }
411     }
412     return E_OK;
413 }
414 
HandleNotifyVolumeCreated(MessageParcel & data,MessageParcel & reply)415 int32_t StorageManagerStub::HandleNotifyVolumeCreated(MessageParcel &data, MessageParcel &reply)
416 {
417     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
418         return E_PERMISSION_DENIED;
419     }
420     std::unique_ptr<VolumeCore> vc = VolumeCore::Unmarshalling(data);
421     NotifyVolumeCreated(*vc);
422     LOGI("StorageManagerStub::HandleNotifyVolumeCreated");
423     return E_OK;
424 }
425 
HandleNotifyVolumeMounted(MessageParcel & data,MessageParcel & reply)426 int32_t StorageManagerStub::HandleNotifyVolumeMounted(MessageParcel &data, MessageParcel &reply)
427 {
428     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
429         return E_PERMISSION_DENIED;
430     }
431     std::string volumeId = data.ReadString();
432     int32_t fsType = data.ReadInt32();
433     std::string fsUuid = data.ReadString();
434     std::string path = data.ReadString();
435     std::string description = data.ReadString();
436     NotifyVolumeMounted(volumeId, fsType, fsUuid, path, description);
437     LOGI("StorageManagerStub::HandleNotifyVolumeMounted");
438     return E_OK;
439 }
440 
HandleNotifyVolumeDestroyed(MessageParcel & data,MessageParcel & reply)441 int32_t StorageManagerStub::HandleNotifyVolumeDestroyed(MessageParcel &data, MessageParcel &reply)
442 {
443     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
444         return E_PERMISSION_DENIED;
445     }
446     std::string volumeId = data.ReadString();
447     NotifyVolumeDestroyed(volumeId);
448     LOGI("StorageManagerStub::HandleNotifyVolumeDestroyed");
449     return E_OK;
450 }
451 
HandleMount(MessageParcel & data,MessageParcel & reply)452 int32_t StorageManagerStub::HandleMount(MessageParcel &data, MessageParcel &reply)
453 {
454     if (!CheckClientPermission(PERMISSION_MOUNT_MANAGER)) {
455         return E_PERMISSION_DENIED;
456     }
457     std::string volumeId = data.ReadString();
458     int err = Mount(volumeId);
459     if (!reply.WriteUint32(err)) {
460         LOGE("StorageManagerStub::HandleMount call Mount failed");
461         return  E_WRITE_REPLY_ERR;
462     }
463     return E_OK;
464 }
465 
HandleUnmount(MessageParcel & data,MessageParcel & reply)466 int32_t StorageManagerStub::HandleUnmount(MessageParcel &data, MessageParcel &reply)
467 {
468     if (!CheckClientPermission(PERMISSION_MOUNT_MANAGER)) {
469         return E_PERMISSION_DENIED;
470     }
471     std::string volumeId = data.ReadString();
472     int err = Unmount(volumeId);
473     if (!reply.WriteUint32(err)) {
474         LOGE("StorageManagerStub::HandleUnmount call Mount failed");
475         return  E_WRITE_REPLY_ERR;
476     }
477     return E_OK;
478 }
479 
HandleNotifyDiskCreated(MessageParcel & data,MessageParcel & reply)480 int32_t StorageManagerStub::HandleNotifyDiskCreated(MessageParcel &data, MessageParcel &reply)
481 {
482     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
483         return E_PERMISSION_DENIED;
484     }
485     auto disk = Disk::Unmarshalling(data);
486     NotifyDiskCreated(*disk);
487     return E_OK;
488 }
489 
HandleNotifyDiskDestroyed(MessageParcel & data,MessageParcel & reply)490 int32_t StorageManagerStub::HandleNotifyDiskDestroyed(MessageParcel &data, MessageParcel &reply)
491 {
492     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
493         return E_PERMISSION_DENIED;
494     }
495     std::string diskId = data.ReadString();
496     NotifyDiskDestroyed(diskId);
497     return E_OK;
498 }
499 
HandlePartition(MessageParcel & data,MessageParcel & reply)500 int32_t StorageManagerStub::HandlePartition(MessageParcel &data, MessageParcel &reply)
501 {
502     if (!CheckClientPermission(PERMISSION_FORMAT_MANAGER)) {
503         return E_PERMISSION_DENIED;
504     }
505     std::string diskId = data.ReadString();
506     int32_t type = data.ReadInt32();
507     int err = Partition(diskId, type);
508     if (!reply.WriteUint32(err)) {
509         LOGE("StorageManagerStub::HandlePartition call Partition failed");
510         return E_WRITE_REPLY_ERR;
511     }
512     return E_OK;
513 }
514 
HandleGetAllDisks(MessageParcel & data,MessageParcel & reply)515 int32_t StorageManagerStub::HandleGetAllDisks(MessageParcel &data, MessageParcel &reply)
516 {
517     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
518         return E_PERMISSION_DENIED;
519     }
520     std::vector<Disk> disks;
521     int32_t err = GetAllDisks(disks);
522     if (!reply.WriteUint32(err)) {
523         return E_WRITE_REPLY_ERR;
524     }
525     uint size = disks.size();
526     if (size == 0) {
527         LOGE("StorageManagerStub::No Disk.");
528         if (!reply.WriteUint32(0)) {
529             return  E_WRITE_REPLY_ERR;
530         }
531         return E_OK;
532     }
533     if (!reply.WriteUint32(disks.size())) {
534         return  E_WRITE_REPLY_ERR;
535     }
536     for (uint i = 0; i < size; i++) {
537         if (!disks[i].Marshalling(reply)) {
538             return  E_WRITE_REPLY_ERR;
539         }
540     }
541     return E_OK;
542 }
543 
HandleGetVolumeByUuid(MessageParcel & data,MessageParcel & reply)544 int32_t StorageManagerStub::HandleGetVolumeByUuid(MessageParcel &data, MessageParcel &reply)
545 {
546     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
547         return E_PERMISSION_DENIED;
548     }
549     std::string fsUuid = data.ReadString();
550     VolumeExternal vc;
551     int err = GetVolumeByUuid(fsUuid, vc);
552     if (!vc.Marshalling(reply)) {
553         return E_WRITE_REPLY_ERR;
554     }
555     if (!reply.WriteUint32(err)) {
556         LOGE("StorageManagerStub::HandleGetVolumeByUuid call GetVolumeByUuid failed");
557         return E_WRITE_REPLY_ERR;
558     }
559     return E_OK;
560 }
561 
HandleGetVolumeById(MessageParcel & data,MessageParcel & reply)562 int32_t StorageManagerStub::HandleGetVolumeById(MessageParcel &data, MessageParcel &reply)
563 {
564     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
565         return E_PERMISSION_DENIED;
566     }
567     std::string volId = data.ReadString();
568     VolumeExternal vc;
569     int err = GetVolumeById(volId, vc);
570     if (!vc.Marshalling(reply)) {
571         return E_WRITE_REPLY_ERR;
572     }
573     if (!reply.WriteUint32(err)) {
574         LOGE("StorageManagerStub::HandleGetVolumeById call GetVolumeById failed");
575         return E_WRITE_REPLY_ERR;
576     }
577     return E_OK;
578 }
579 
HandleSetVolDesc(MessageParcel & data,MessageParcel & reply)580 int32_t StorageManagerStub::HandleSetVolDesc(MessageParcel &data, MessageParcel &reply)
581 {
582     if (!CheckClientPermission(PERMISSION_MOUNT_MANAGER)) {
583         return E_PERMISSION_DENIED;
584     }
585     std::string fsUuid = data.ReadString();
586     std::string desc = data.ReadString();
587     int err = SetVolumeDescription(fsUuid, desc);
588     if (!reply.WriteUint32(err)) {
589         LOGE("StorageManagerStub::HandleSetVolDesc call SetVolumeDescription failed");
590         return E_WRITE_REPLY_ERR;
591     }
592     return E_OK;
593 }
594 
HandleFormat(MessageParcel & data,MessageParcel & reply)595 int32_t StorageManagerStub::HandleFormat(MessageParcel &data, MessageParcel &reply)
596 {
597     if (!CheckClientPermission(PERMISSION_FORMAT_MANAGER)) {
598         return E_PERMISSION_DENIED;
599     }
600     std::string volId = data.ReadString();
601     std::string fsType = data.ReadString();
602     int err = Format(volId, fsType);
603     if (!reply.WriteUint32(err)) {
604         LOGE("StorageManagerStub::HandleFormat call Format failed");
605         return E_WRITE_REPLY_ERR;
606     }
607     return E_OK;
608 }
609 
HandleGetDiskById(MessageParcel & data,MessageParcel & reply)610 int32_t StorageManagerStub::HandleGetDiskById(MessageParcel &data, MessageParcel &reply)
611 {
612     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
613         return E_PERMISSION_DENIED;
614     }
615     std::string volId = data.ReadString();
616     Disk disk;
617     int err = GetDiskById(volId, disk);
618     if (!disk.Marshalling(reply)) {
619         return E_WRITE_REPLY_ERR;
620     }
621     if (!reply.WriteUint32(err)) {
622         LOGE("StorageManagerStub::HandleGetDiskById call GetDiskById failed");
623         return E_WRITE_REPLY_ERR;
624     }
625     return E_OK;
626 }
627 
HandleGenerateUserKeys(MessageParcel & data,MessageParcel & reply)628 int32_t StorageManagerStub::HandleGenerateUserKeys(MessageParcel &data, MessageParcel &reply)
629 {
630     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
631         return E_PERMISSION_DENIED;
632     }
633     uint32_t userId = data.ReadUint32();
634     uint32_t flags = data.ReadUint32();
635     int32_t err = GenerateUserKeys(userId, flags);
636     if (!reply.WriteInt32(err)) {
637         LOGE("Write reply error code failed");
638         return E_WRITE_REPLY_ERR;
639     }
640 
641     return E_OK;
642 }
643 
HandleDeleteUserKeys(MessageParcel & data,MessageParcel & reply)644 int32_t StorageManagerStub::HandleDeleteUserKeys(MessageParcel &data, MessageParcel &reply)
645 {
646     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
647         return E_PERMISSION_DENIED;
648     }
649     uint32_t userId = data.ReadUint32();
650     int32_t err = DeleteUserKeys(userId);
651     if (!reply.WriteInt32(err)) {
652         LOGE("Write reply error code failed");
653         return E_WRITE_REPLY_ERR;
654     }
655 
656     return E_OK;
657 }
658 
HandleUpdateUserAuth(MessageParcel & data,MessageParcel & reply)659 int32_t StorageManagerStub::HandleUpdateUserAuth(MessageParcel &data, MessageParcel &reply)
660 {
661     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
662         return E_PERMISSION_DENIED;
663     }
664     uint32_t userId = data.ReadUint32();
665 
666     std::vector<uint8_t> token;
667     std::vector<uint8_t> oldSecret;
668     std::vector<uint8_t> newSecret;
669     data.ReadUInt8Vector(&token);
670     data.ReadUInt8Vector(&oldSecret);
671     data.ReadUInt8Vector(&newSecret);
672 
673     int32_t err = UpdateUserAuth(userId, token, oldSecret, newSecret);
674     if (!reply.WriteInt32(err)) {
675         LOGE("Write reply error code failed");
676         return E_WRITE_REPLY_ERR;
677     }
678 
679     return E_OK;
680 }
681 
HandleActiveUserKey(MessageParcel & data,MessageParcel & reply)682 int32_t StorageManagerStub::HandleActiveUserKey(MessageParcel &data, MessageParcel &reply)
683 {
684     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
685         return E_PERMISSION_DENIED;
686     }
687     uint32_t userId = data.ReadUint32();
688 
689     std::vector<uint8_t> token;
690     std::vector<uint8_t> secret;
691     data.ReadUInt8Vector(&token);
692     data.ReadUInt8Vector(&secret);
693 
694     int32_t err = ActiveUserKey(userId, token, secret);
695     if (!reply.WriteInt32(err)) {
696         LOGE("Write reply error code failed");
697         return E_WRITE_REPLY_ERR;
698     }
699 
700     return E_OK;
701 }
702 
HandleInactiveUserKey(MessageParcel & data,MessageParcel & reply)703 int32_t StorageManagerStub::HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply)
704 {
705     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
706         return E_PERMISSION_DENIED;
707     }
708     uint32_t userId = data.ReadUint32();
709     int32_t err = InactiveUserKey(userId);
710     if (!reply.WriteInt32(err)) {
711         LOGE("Write reply error code failed");
712         return E_WRITE_REPLY_ERR;
713     }
714 
715     return E_OK;
716 }
717 
HandleUpdateKeyContext(MessageParcel & data,MessageParcel & reply)718 int32_t StorageManagerStub::HandleUpdateKeyContext(MessageParcel &data, MessageParcel &reply)
719 {
720     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
721         return E_PERMISSION_DENIED;
722     }
723     uint32_t userId = data.ReadUint32();
724     int32_t err = UpdateKeyContext(userId);
725     if (!reply.WriteInt32(err)) {
726         LOGE("Write reply error code failed");
727         return E_WRITE_REPLY_ERR;
728     }
729 
730     return E_OK;
731 }
732 
HandleCreateShareFile(MessageParcel & data,MessageParcel & reply)733 int32_t StorageManagerStub::HandleCreateShareFile(MessageParcel &data, MessageParcel &reply)
734 {
735     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
736         return E_PERMISSION_DENIED;
737     }
738     std::string uri = data.ReadString();
739     uint32_t tokenId = data.ReadUint32();
740     uint32_t flag = data.ReadUint32();
741     int err = CreateShareFile(uri, tokenId, flag);
742     if (!reply.WriteInt32(err)) {
743         return E_WRITE_REPLY_ERR;
744     }
745     return E_OK;
746 }
747 
HandleDeleteShareFile(MessageParcel & data,MessageParcel & reply)748 int32_t StorageManagerStub::HandleDeleteShareFile(MessageParcel &data, MessageParcel &reply)
749 {
750     if (!CheckClientPermission(PERMISSION_STORAGE_MANAGER)) {
751         return E_PERMISSION_DENIED;
752     }
753     uint32_t tokenId = data.ReadUint32();
754     std::vector<std::string> sharePathList;
755     if (!data.ReadStringVector(&sharePathList)) {
756         return E_WRITE_REPLY_ERR;
757     }
758 
759     int err = DeleteShareFile(tokenId, sharePathList);
760     if (!reply.WriteInt32(err)) {
761         return E_WRITE_REPLY_ERR;
762     }
763     return E_OK;
764 }
765 } // StorageManager
766 } // OHOS
767