1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ipc/storage_daemon_stub.h"
17 
18 #include "ipc/storage_daemon_ipc_interface_code.h"
19 #include "storage_service_errno.h"
20 #include "storage_service_log.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace StorageDaemon {
25 using namespace std;
26 
StorageDaemonStub()27 StorageDaemonStub::StorageDaemonStub()
28 {
29     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::SHUTDOWN)] =
30         &StorageDaemonStub::HandleShutdown;
31     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::CHECK)] =
32         &StorageDaemonStub::HandleCheck;
33     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT)] =
34         &StorageDaemonStub::HandleMount;
35     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::UMOUNT)] =
36         &StorageDaemonStub::HandleUMount;
37     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::PARTITION)] =
38         &StorageDaemonStub::HandlePartition;
39     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::FORMAT)] =
40         &StorageDaemonStub::HandleFormat;
41     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::SET_VOL_DESC)] =
42         &StorageDaemonStub::HandleSetVolDesc;
43     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::PREPARE_USER_DIRS)] =
44         &StorageDaemonStub::HandlePrepareUserDirs;
45     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::DESTROY_USER_DIRS)] =
46         &StorageDaemonStub::HandleDestroyUserDirs;
47     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::START_USER)] =
48         &StorageDaemonStub::HandleStartUser;
49     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::STOP_USER)] =
50         &StorageDaemonStub::HandleStopUser;
51     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY)] =
52         &StorageDaemonStub::HandleInitGlobalKey;
53     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS)] =
54         &StorageDaemonStub::HandleInitGlobalUserKeys;
55     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_USER_KEYS)] =
56         &StorageDaemonStub::HandleGenerateUserKeys;
57     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_USER_KEYS)] =
58         &StorageDaemonStub::HandleDeleteUserKeys;
59     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_USER_AUTH)] =
60         &StorageDaemonStub::HandleUpdateUserAuth;
61     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::ACTIVE_USER_KEY)] =
62         &StorageDaemonStub::HandleActiveUserKey;
63     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::INACTIVE_USER_KEY)] =
64         &StorageDaemonStub::HandleInactiveUserKey;
65     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::LOCK_USER_SCREEN)] =
66         &StorageDaemonStub::HandleLockUserScreen;
67     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::UNLOCK_USER_SCREEN)] =
68         &StorageDaemonStub::HandleUnlockUserScreen;
69     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::LOCK_SCREEN_STATUS)] =
70         &StorageDaemonStub::HandleGetLockScreenStatus;
71     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_KEY_CONTEXT)] =
72         &StorageDaemonStub::HandleUpdateKeyContext;
73     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT_CRYPTO_PATH_AGAIN)] =
74         &StorageDaemonStub::HandleMountCryptoPathAgain;
75     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_SHARE_FILE)] =
76         &StorageDaemonStub::HandleCreateShareFile;
77     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_SHARE_FILE)] =
78         &StorageDaemonStub::HandleDeleteShareFile;
79     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::SET_BUNDLE_QUOTA)] =
80         &StorageDaemonStub::HandleSetBundleQuota;
81     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_SPACE)] =
82         &StorageDaemonStub::HandleGetOccupiedSpace;
83     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_MEM_PARA)] =
84         &StorageDaemonStub::HandleUpdateMemoryPara;
85     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_BUNDLE_STATS_INCREASE)] =
86         &StorageDaemonStub::HandleGetBundleStatsForIncrease;
87     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::GENERATE_APP_KEY)] =
88         &StorageDaemonStub::HandleGenerateAppkey;
89     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_APP_KEY)] =
90         &StorageDaemonStub::HandleDeleteAppkey;
91     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT_DFS_DOCS)] =
92         &StorageDaemonStub::HandleMountDfsDocs;
93     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::UMOUNT_DFS_DOCS)] =
94         &StorageDaemonStub::HandleUMountDfsDocs;
95     opToInterfaceMap_[static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_FILE_ENCRYPT_STATUS)] =
96         &StorageDaemonStub::HandleGetFileEncryptStatus;
97 }
98 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)99 int32_t StorageDaemonStub::OnRemoteRequest(uint32_t code,
100                                            MessageParcel &data,
101                                            MessageParcel &reply,
102                                            MessageOption &option)
103 {
104     if (data.ReadInterfaceToken() != GetDescriptor()) {
105         return E_PERMISSION_DENIED;
106     }
107     switch (code) {
108         case static_cast<uint32_t>(StorageDaemonInterfaceCode::SHUTDOWN):
109         case static_cast<uint32_t>(StorageDaemonInterfaceCode::CHECK):
110         case static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT):
111         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UMOUNT):
112         case static_cast<uint32_t>(StorageDaemonInterfaceCode::PARTITION):
113         case static_cast<uint32_t>(StorageDaemonInterfaceCode::FORMAT):
114         case static_cast<uint32_t>(StorageDaemonInterfaceCode::SET_VOL_DESC):
115             return OnRemoteRequestForBase(code, data, reply);
116         case static_cast<uint32_t>(StorageDaemonInterfaceCode::PREPARE_USER_DIRS):
117         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DESTROY_USER_DIRS):
118         case static_cast<uint32_t>(StorageDaemonInterfaceCode::START_USER):
119         case static_cast<uint32_t>(StorageDaemonInterfaceCode::STOP_USER):
120         case static_cast<uint32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER):
121         case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY):
122         case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS):
123         case static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_USER_KEYS):
124         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_USER_KEYS):
125         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_USER_AUTH):
126         case static_cast<uint32_t>(StorageDaemonInterfaceCode::ACTIVE_USER_KEY):
127         case static_cast<uint32_t>(StorageDaemonInterfaceCode::INACTIVE_USER_KEY):
128         case static_cast<uint32_t>(StorageDaemonInterfaceCode::LOCK_USER_SCREEN):
129         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UNLOCK_USER_SCREEN):
130             return OnRemoteRequestForUser(code, data, reply);
131         case static_cast<uint32_t>(StorageDaemonInterfaceCode::LOCK_SCREEN_STATUS):
132         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_KEY_CONTEXT):
133         case static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT_CRYPTO_PATH_AGAIN):
134         case static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_SHARE_FILE):
135         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_SHARE_FILE):
136         case static_cast<uint32_t>(StorageDaemonInterfaceCode::SET_BUNDLE_QUOTA):
137         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_SPACE):
138         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_MEM_PARA):
139         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_BUNDLE_STATS_INCREASE):
140         case static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT_DFS_DOCS):
141         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UMOUNT_DFS_DOCS):
142         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GENERATE_APP_KEY):
143         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_APP_KEY):
144         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_FILE_ENCRYPT_STATUS):
145             return OnRemoteRequestForApp(code, data, reply);
146         default:
147             LOGE("Cannot response request %d: unknown tranction", code);
148             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
149     }
150 }
151 
OnRemoteRequestForBase(uint32_t code,MessageParcel & data,MessageParcel & reply)152 int32_t StorageDaemonStub::OnRemoteRequestForBase(uint32_t code, MessageParcel &data, MessageParcel &reply)
153 {
154     switch (code) {
155         case static_cast<uint32_t>(StorageDaemonInterfaceCode::SHUTDOWN):
156             return HandleShutdown(data, reply);
157         case static_cast<uint32_t>(StorageDaemonInterfaceCode::CHECK):
158             return HandleCheck(data, reply);
159         case static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT):
160             return HandleMount(data, reply);
161         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UMOUNT):
162             return HandleUMount(data, reply);
163         case static_cast<uint32_t>(StorageDaemonInterfaceCode::PARTITION):
164             return HandlePartition(data, reply);
165         case static_cast<uint32_t>(StorageDaemonInterfaceCode::FORMAT):
166             return HandleFormat(data, reply);
167         case static_cast<uint32_t>(StorageDaemonInterfaceCode::SET_VOL_DESC):
168             return HandleSetVolDesc(data, reply);
169         default:
170             LOGE("Cannot response request %d: unknown tranction", code);
171             return E_SYS_ERR;
172     }
173 }
OnRemoteRequestForUser(uint32_t code,MessageParcel & data,MessageParcel & reply)174 int32_t StorageDaemonStub::OnRemoteRequestForUser(uint32_t code, MessageParcel &data, MessageParcel &reply)
175 {
176     switch (code) {
177         case static_cast<uint32_t>(StorageDaemonInterfaceCode::PREPARE_USER_DIRS):
178             return HandlePrepareUserDirs(data, reply);
179         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DESTROY_USER_DIRS):
180             return HandleDestroyUserDirs(data, reply);
181         case static_cast<uint32_t>(StorageDaemonInterfaceCode::START_USER):
182             return HandleStartUser(data, reply);
183         case static_cast<uint32_t>(StorageDaemonInterfaceCode::STOP_USER):
184             return HandleStopUser(data, reply);
185         case static_cast<uint32_t>(StorageDaemonInterfaceCode::COMPLETE_ADD_USER):
186             return HandleCompleteAddUser(data, reply);
187         case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_KEY):
188             return HandleInitGlobalKey(data, reply);
189         case static_cast<uint32_t>(StorageDaemonInterfaceCode::INIT_GLOBAL_USER_KEYS):
190             return HandleInitGlobalUserKeys(data, reply);
191         case static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_USER_KEYS):
192             return HandleGenerateUserKeys(data, reply);
193         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_USER_KEYS):
194             return HandleDeleteUserKeys(data, reply);
195         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_USER_AUTH):
196             return HandleUpdateUserAuth(data, reply);
197         case static_cast<uint32_t>(StorageDaemonInterfaceCode::ACTIVE_USER_KEY):
198             return HandleActiveUserKey(data, reply);
199         case static_cast<uint32_t>(StorageDaemonInterfaceCode::INACTIVE_USER_KEY):
200             return HandleInactiveUserKey(data, reply);
201         case static_cast<uint32_t>(StorageDaemonInterfaceCode::LOCK_USER_SCREEN):
202             return HandleLockUserScreen(data, reply);
203         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UNLOCK_USER_SCREEN):
204             return HandleUnlockUserScreen(data, reply);
205         default:
206             LOGE("Cannot response request %d: unknown tranction", code);
207             return E_SYS_ERR;
208     }
209 }
OnRemoteRequestForApp(uint32_t code,MessageParcel & data,MessageParcel & reply)210 int32_t StorageDaemonStub::OnRemoteRequestForApp(uint32_t code, MessageParcel &data, MessageParcel &reply)
211 {
212     switch (code) {
213         case static_cast<uint32_t>(StorageDaemonInterfaceCode::LOCK_SCREEN_STATUS):
214             return HandleGetLockScreenStatus(data, reply);
215         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_KEY_CONTEXT):
216             return HandleUpdateKeyContext(data, reply);
217         case static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT_CRYPTO_PATH_AGAIN):
218             return HandleMountCryptoPathAgain(data, reply);
219         case static_cast<uint32_t>(StorageDaemonInterfaceCode::CREATE_SHARE_FILE):
220             return HandleCreateShareFile(data, reply);
221         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_SHARE_FILE):
222             return HandleDeleteShareFile(data, reply);
223         case static_cast<uint32_t>(StorageDaemonInterfaceCode::SET_BUNDLE_QUOTA):
224             return HandleSetBundleQuota(data, reply);
225         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_SPACE):
226             return HandleGetOccupiedSpace(data, reply);
227         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UPDATE_MEM_PARA):
228             return HandleUpdateMemoryPara(data, reply);
229         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_BUNDLE_STATS_INCREASE):
230             return HandleGetBundleStatsForIncrease(data, reply);
231         case static_cast<uint32_t>(StorageDaemonInterfaceCode::MOUNT_DFS_DOCS):
232             return HandleMountDfsDocs(data, reply);
233         case static_cast<uint32_t>(StorageDaemonInterfaceCode::UMOUNT_DFS_DOCS):
234             return HandleUMountDfsDocs(data, reply);
235         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GENERATE_APP_KEY):
236             return HandleGenerateAppkey(data, reply);
237         case static_cast<uint32_t>(StorageDaemonInterfaceCode::DELETE_APP_KEY):
238             return HandleDeleteAppkey(data, reply);
239         case static_cast<uint32_t>(StorageDaemonInterfaceCode::GET_FILE_ENCRYPT_STATUS):
240             return HandleGetFileEncryptStatus(data, reply);
241         default:
242             LOGE("Cannot response request %d: unknown tranction", code);
243             return E_SYS_ERR;
244     }
245 }
246 
HandleShutdown(MessageParcel & data,MessageParcel & reply)247 int32_t StorageDaemonStub::HandleShutdown(MessageParcel &data, MessageParcel &reply)
248 {
249     Shutdown();
250     return E_OK;
251 }
252 
HandleMount(MessageParcel & data,MessageParcel & reply)253 int32_t StorageDaemonStub::HandleMount(MessageParcel &data, MessageParcel &reply)
254 {
255     std::string volId = data.ReadString();
256     uint32_t flags = data.ReadUint32();
257 
258     int err = Mount(volId, flags);
259     if (!reply.WriteInt32(err)) {
260         return  E_WRITE_REPLY_ERR;
261     }
262 
263     return E_OK;
264 }
265 
HandleUMount(MessageParcel & data,MessageParcel & reply)266 int32_t StorageDaemonStub::HandleUMount(MessageParcel &data, MessageParcel &reply)
267 {
268     std::string volId = data.ReadString();
269 
270     int err = UMount(volId);
271     if (!reply.WriteInt32(err)) {
272         return  E_WRITE_REPLY_ERR;
273     }
274 
275     return E_OK;
276 }
277 
HandleCheck(MessageParcel & data,MessageParcel & reply)278 int32_t StorageDaemonStub::HandleCheck(MessageParcel &data, MessageParcel &reply)
279 {
280     std::string volId = data.ReadString();
281 
282     int err = Check(volId);
283     if (!reply.WriteInt32(err)) {
284         return  E_WRITE_REPLY_ERR;
285     }
286 
287     return E_OK;
288 }
289 
HandleFormat(MessageParcel & data,MessageParcel & reply)290 int32_t StorageDaemonStub::HandleFormat(MessageParcel &data, MessageParcel &reply)
291 {
292     std::string volId = data.ReadString();
293     std::string fsType = data.ReadString();
294 
295     int err = Format(volId, fsType);
296     if (!reply.WriteInt32(err)) {
297         return  E_WRITE_REPLY_ERR;
298     }
299 
300     return E_OK;
301 }
302 
HandlePartition(MessageParcel & data,MessageParcel & reply)303 int32_t StorageDaemonStub::HandlePartition(MessageParcel &data, MessageParcel &reply)
304 {
305     std::string volId = data.ReadString();
306     int32_t type = data.ReadInt32();
307 
308     int err = Partition(volId, type);
309     if (!reply.WriteInt32(err)) {
310         return  E_WRITE_REPLY_ERR;
311     }
312 
313     return E_OK;
314 }
315 
HandleSetVolDesc(MessageParcel & data,MessageParcel & reply)316 int32_t StorageDaemonStub::HandleSetVolDesc(MessageParcel &data, MessageParcel &reply)
317 {
318     std::string volId = data.ReadString();
319     std::string description = data.ReadString();
320 
321     int err = SetVolumeDescription(volId, description);
322     if (!reply.WriteInt32(err)) {
323         return E_WRITE_REPLY_ERR;
324     }
325 
326     return E_OK;
327 }
328 
HandlePrepareUserDirs(MessageParcel & data,MessageParcel & reply)329 int32_t StorageDaemonStub::HandlePrepareUserDirs(MessageParcel &data, MessageParcel &reply)
330 {
331     int32_t userId = data.ReadInt32();
332     uint32_t flags = data.ReadUint32();
333 
334     int err = PrepareUserDirs(userId, flags);
335     if (!reply.WriteInt32(err)) {
336         return  E_WRITE_REPLY_ERR;
337     }
338 
339     return E_OK;
340 }
341 
HandleDestroyUserDirs(MessageParcel & data,MessageParcel & reply)342 int32_t StorageDaemonStub::HandleDestroyUserDirs(MessageParcel &data, MessageParcel &reply)
343 {
344     int32_t userId = data.ReadInt32();
345     uint32_t flags = data.ReadUint32();
346 
347     int err = DestroyUserDirs(userId, flags);
348     if (!reply.WriteInt32(err)) {
349         return  E_WRITE_REPLY_ERR;
350     }
351 
352     return E_OK;
353 }
354 
HandleStartUser(MessageParcel & data,MessageParcel & reply)355 int32_t StorageDaemonStub::HandleStartUser(MessageParcel &data, MessageParcel &reply)
356 {
357     int32_t userId = data.ReadInt32();
358 
359     int32_t err = StartUser(userId);
360     if (!reply.WriteInt32(err)) {
361         return E_WRITE_REPLY_ERR;
362     }
363 
364     return E_OK;
365 }
366 
HandleStopUser(MessageParcel & data,MessageParcel & reply)367 int32_t StorageDaemonStub::HandleStopUser(MessageParcel &data, MessageParcel &reply)
368 {
369     int32_t userId = data.ReadInt32();
370 
371     int32_t err = StopUser(userId);
372     if (!reply.WriteInt32(err)) {
373         return E_WRITE_REPLY_ERR;
374     }
375 
376     return E_OK;
377 }
378 
HandleCompleteAddUser(MessageParcel & data,MessageParcel & reply)379 int32_t StorageDaemonStub::HandleCompleteAddUser(MessageParcel &data, MessageParcel &reply)
380 {
381     int32_t userId = data.ReadInt32();
382 
383     int32_t err = CompleteAddUser(userId);
384     if (!reply.WriteInt32(err)) {
385         return E_WRITE_REPLY_ERR;
386     }
387 
388     return E_OK;
389 }
390 
HandleInitGlobalKey(MessageParcel & data,MessageParcel & reply)391 int32_t StorageDaemonStub::HandleInitGlobalKey(MessageParcel &data, MessageParcel &reply)
392 {
393     int err = InitGlobalKey();
394     if (!reply.WriteInt32(err)) {
395         return E_WRITE_REPLY_ERR;
396     }
397 
398     return E_OK;
399 }
400 
HandleInitGlobalUserKeys(MessageParcel & data,MessageParcel & reply)401 int32_t StorageDaemonStub::HandleInitGlobalUserKeys(MessageParcel &data, MessageParcel &reply)
402 {
403     int err = InitGlobalUserKeys();
404     if (!reply.WriteInt32(err)) {
405         return E_WRITE_REPLY_ERR;
406     }
407 
408     return E_OK;
409 }
410 
HandleGenerateUserKeys(MessageParcel & data,MessageParcel & reply)411 int32_t StorageDaemonStub::HandleGenerateUserKeys(MessageParcel &data, MessageParcel &reply)
412 {
413     uint32_t userId = data.ReadUint32();
414     uint32_t flags = data.ReadUint32();
415 
416     int err = GenerateUserKeys(userId, flags);
417     if (!reply.WriteInt32(err)) {
418         return E_WRITE_REPLY_ERR;
419     }
420 
421     return E_OK;
422 }
423 
HandleDeleteUserKeys(MessageParcel & data,MessageParcel & reply)424 int32_t StorageDaemonStub::HandleDeleteUserKeys(MessageParcel &data, MessageParcel &reply)
425 {
426     uint32_t userId = data.ReadUint32();
427 
428     int err = DeleteUserKeys(userId);
429     if (!reply.WriteInt32(err)) {
430         return E_WRITE_REPLY_ERR;
431     }
432 
433     return E_OK;
434 }
435 
HandleUpdateUserAuth(MessageParcel & data,MessageParcel & reply)436 int32_t StorageDaemonStub::HandleUpdateUserAuth(MessageParcel &data, MessageParcel &reply)
437 {
438     uint32_t userId = data.ReadUint32();
439     uint64_t secureUid = data.ReadUint64();
440 
441     std::vector<uint8_t> token;
442     std::vector<uint8_t> oldSecret;
443     std::vector<uint8_t> newSecret;
444     data.ReadUInt8Vector(&token);
445     data.ReadUInt8Vector(&oldSecret);
446     data.ReadUInt8Vector(&newSecret);
447 
448     int err = UpdateUserAuth(userId, secureUid, token, oldSecret, newSecret);
449     if (!reply.WriteInt32(err)) {
450         return E_WRITE_REPLY_ERR;
451     }
452 
453     return E_OK;
454 }
455 
HandleActiveUserKey(MessageParcel & data,MessageParcel & reply)456 int32_t StorageDaemonStub::HandleActiveUserKey(MessageParcel &data, MessageParcel &reply)
457 {
458     uint32_t userId = data.ReadUint32();
459 
460     std::vector<uint8_t> token;
461     std::vector<uint8_t> secret;
462     data.ReadUInt8Vector(&token);
463     data.ReadUInt8Vector(&secret);
464 
465     int err = ActiveUserKey(userId, token, secret);
466     if (!reply.WriteInt32(err)) {
467         return E_WRITE_REPLY_ERR;
468     }
469 
470     return E_OK;
471 }
472 
HandleInactiveUserKey(MessageParcel & data,MessageParcel & reply)473 int32_t StorageDaemonStub::HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply)
474 {
475     uint32_t userId = data.ReadUint32();
476 
477     int err = InactiveUserKey(userId);
478     if (!reply.WriteInt32(err)) {
479         return E_WRITE_REPLY_ERR;
480     }
481 
482     return E_OK;
483 }
484 
HandleLockUserScreen(MessageParcel & data,MessageParcel & reply)485 int32_t StorageDaemonStub::HandleLockUserScreen(MessageParcel &data, MessageParcel &reply)
486 {
487     uint32_t userId = data.ReadUint32();
488 
489     int err = LockUserScreen(userId);
490     if (!reply.WriteInt32(err)) {
491         return E_WRITE_REPLY_ERR;
492     }
493 
494     return E_OK;
495 }
496 
HandleUnlockUserScreen(MessageParcel & data,MessageParcel & reply)497 int32_t StorageDaemonStub::HandleUnlockUserScreen(MessageParcel &data, MessageParcel &reply)
498 {
499     uint32_t userId = data.ReadUint32();
500 
501     std::vector<uint8_t> token;
502     std::vector<uint8_t> secret;
503     data.ReadUInt8Vector(&token);
504     data.ReadUInt8Vector(&secret);
505 
506     int err = UnlockUserScreen(userId, token, secret);
507     if (!reply.WriteInt32(err)) {
508         return E_WRITE_REPLY_ERR;
509     }
510 
511     return E_OK;
512 }
513 
HandleGetLockScreenStatus(MessageParcel & data,MessageParcel & reply)514 int32_t StorageDaemonStub::HandleGetLockScreenStatus(MessageParcel &data, MessageParcel &reply)
515 {
516     uint32_t userId = data.ReadUint32();
517     bool lockScreenStatus = false;
518     int err = GetLockScreenStatus(userId, lockScreenStatus);
519     if (!reply.WriteBool(lockScreenStatus)) {
520         return E_WRITE_REPLY_ERR;
521     }
522     if (!reply.WriteInt32(err)) {
523         return E_WRITE_REPLY_ERR;
524     }
525 
526     return E_OK;
527 }
528 
HandleGenerateAppkey(MessageParcel & data,MessageParcel & reply)529 int32_t StorageDaemonStub::HandleGenerateAppkey(MessageParcel &data, MessageParcel &reply)
530 {
531     uint32_t userId = data.ReadUint32();
532     uint32_t hashId = data.ReadUint32();
533     std::string keyId;
534     int err = GenerateAppkey(userId, hashId, keyId);
535     if (!reply.WriteString(keyId)) {
536         return E_WRITE_REPLY_ERR;
537     }
538     if (!reply.WriteInt32(err)) {
539         return E_WRITE_REPLY_ERR;
540     }
541 
542     return E_OK;
543 }
544 
HandleDeleteAppkey(MessageParcel & data,MessageParcel & reply)545 int32_t StorageDaemonStub::HandleDeleteAppkey(MessageParcel &data, MessageParcel &reply)
546 {
547     uint32_t userId = data.ReadUint32();
548     std::string keyId = data.ReadString();
549     int err = DeleteAppkey(userId, keyId);
550     if (!reply.WriteInt32(err)) {
551         return E_WRITE_REPLY_ERR;
552     }
553 
554     return E_OK;
555 }
556 
HandleUpdateKeyContext(MessageParcel & data,MessageParcel & reply)557 int32_t StorageDaemonStub::HandleUpdateKeyContext(MessageParcel &data, MessageParcel &reply)
558 {
559     uint32_t userId = data.ReadUint32();
560     int err = UpdateKeyContext(userId);
561     if (!reply.WriteInt32(err)) {
562         return E_WRITE_REPLY_ERR;
563     }
564 
565     return E_OK;
566 }
567 
HandleMountCryptoPathAgain(MessageParcel & data,MessageParcel & reply)568 int32_t StorageDaemonStub::HandleMountCryptoPathAgain(MessageParcel &data, MessageParcel &reply)
569 {
570     uint32_t userId = data.ReadUint32();
571     int32_t err = MountCryptoPathAgain(userId);
572     if (!reply.WriteInt32(err)) {
573         return E_WRITE_REPLY_ERR;
574     }
575     return E_OK;
576 }
577 
HandleCreateShareFile(MessageParcel & data,MessageParcel & reply)578 int32_t StorageDaemonStub::HandleCreateShareFile(MessageParcel &data, MessageParcel &reply)
579 {
580     std::vector<std::string> uriList;
581     if (!data.ReadStringVector(&uriList)) {
582         return E_WRITE_REPLY_ERR;
583     }
584     uint32_t tokenId = data.ReadUint32();
585     uint32_t flag = data.ReadUint32();
586     std::vector<int32_t> retList = CreateShareFile(uriList, tokenId, flag);
587     if (!reply.WriteInt32Vector(retList)) {
588         return E_WRITE_REPLY_ERR;
589     }
590     return E_OK;
591 }
592 
HandleDeleteShareFile(MessageParcel & data,MessageParcel & reply)593 int32_t StorageDaemonStub::HandleDeleteShareFile(MessageParcel &data, MessageParcel &reply)
594 {
595     uint32_t tokenId = data.ReadUint32();
596     std::vector<std::string> uriList;
597     if (!data.ReadStringVector(&uriList)) {
598         return E_WRITE_REPLY_ERR;
599     }
600     int err = DeleteShareFile(tokenId, uriList);
601     if (!reply.WriteInt32(err)) {
602         return E_WRITE_REPLY_ERR;
603     }
604     return E_OK;
605 }
606 
HandleSetBundleQuota(MessageParcel & data,MessageParcel & reply)607 int32_t StorageDaemonStub::HandleSetBundleQuota(MessageParcel &data, MessageParcel &reply)
608 {
609     std::string bundleName = data.ReadString();
610     int32_t uid = data.ReadInt32();
611     std::string bundleDataDirPath = data.ReadString();
612     int32_t limitSizeMb = data.ReadInt32();
613     int err = SetBundleQuota(bundleName, uid, bundleDataDirPath, limitSizeMb);
614     if (!reply.WriteInt32(err)) {
615         return E_WRITE_REPLY_ERR;
616     }
617     return E_OK;
618 }
619 
HandleGetOccupiedSpace(MessageParcel & data,MessageParcel & reply)620 int32_t StorageDaemonStub::HandleGetOccupiedSpace(MessageParcel &data, MessageParcel &reply)
621 {
622     int32_t idType = data.ReadInt32();
623     int32_t id = data.ReadInt32();
624     int64_t size = 0;
625     int err = GetOccupiedSpace(idType, id, size);
626     if (!reply.WriteInt32(err)) {
627         return E_WRITE_REPLY_ERR;
628     }
629     if (!reply.WriteInt64(size)) {
630         LOGE("StorageManagerStub::HandleGetFree call GetTotalSize failed");
631         return  E_WRITE_REPLY_ERR;
632     }
633     return E_OK;
634 }
HandleUpdateMemoryPara(MessageParcel & data,MessageParcel & reply)635 int32_t StorageDaemonStub::HandleUpdateMemoryPara(MessageParcel &data, MessageParcel &reply)
636 {
637     int32_t size = data.ReadInt32();
638     int32_t oldSize = 0;
639     int err = UpdateMemoryPara(size, oldSize);
640     if (!reply.WriteInt32(err)) {
641         return E_WRITE_REPLY_ERR;
642     }
643     if (!reply.WriteInt32(oldSize)) {
644     LOGE("StorageManagerStub::HandleUpdateMemoryPara call Write oldSize failed");
645         return E_WRITE_REPLY_ERR;
646     }
647     return E_OK;
648 }
649 
HandleGetBundleStatsForIncrease(MessageParcel & data,MessageParcel & reply)650 int32_t StorageDaemonStub::HandleGetBundleStatsForIncrease(MessageParcel &data, MessageParcel &reply)
651 {
652     uint32_t userId = data.ReadUint32();
653     std::vector<std::string> bundleNames;
654     if (!data.ReadStringVector(&bundleNames)) {
655         return E_WRITE_REPLY_ERR;
656     }
657     std::vector<int64_t> incrementalBackTimes;
658     if (!data.ReadInt64Vector(&incrementalBackTimes)) {
659         return E_WRITE_REPLY_ERR;
660     }
661 
662     std::vector<int64_t> pkgFileSizes;
663     std::vector<int64_t> incPkgFileSizes;
664     int32_t err = GetBundleStatsForIncrease(userId, bundleNames, incrementalBackTimes, pkgFileSizes, incPkgFileSizes);
665     if (!reply.WriteInt32(err)) {
666         return E_WRITE_REPLY_ERR;
667     }
668     if (!reply.WriteInt64Vector(pkgFileSizes)) {
669         LOGE("StorageDaemonStub::HandleGetBundleStatsForIncrease call GetBundleStatsForIncrease failed");
670         return  E_WRITE_REPLY_ERR;
671     }
672     if (!reply.WriteInt64Vector(incPkgFileSizes)) {
673         LOGE("StorageDaemonStub::HandleGetBundleStatsForIncrease call GetBundleStatsForIncrease failed");
674         return  E_WRITE_REPLY_ERR;
675     }
676     return E_OK;
677 }
678 
HandleMountDfsDocs(MessageParcel & data,MessageParcel & reply)679 int32_t StorageDaemonStub::HandleMountDfsDocs(MessageParcel &data, MessageParcel &reply)
680 {
681     LOGI("StorageDaemonStub::HandleMountDfsDocs start.");
682     int32_t userId = data.ReadInt32();
683     std::string relativePath = data.ReadString();
684     std::string networkId = data.ReadString();
685     std::string deviceId = data.ReadString();
686 
687     int32_t err = MountDfsDocs(userId, relativePath, networkId, deviceId);
688     if (!reply.WriteInt32(err)) {
689         return E_WRITE_REPLY_ERR;
690     }
691     return E_OK;
692 }
693 
HandleUMountDfsDocs(MessageParcel & data,MessageParcel & reply)694 int32_t StorageDaemonStub::HandleUMountDfsDocs(MessageParcel &data, MessageParcel &reply)
695 {
696     LOGI("StorageDaemonStub::HandleUMountDfsDocs start.");
697     int32_t userId = data.ReadInt32();
698     std::string relativePath = data.ReadString();
699     std::string networkId = data.ReadString();
700     std::string deviceId = data.ReadString();
701 
702     int32_t err = UMountDfsDocs(userId, relativePath, networkId, deviceId);
703     if (!reply.WriteInt32(err)) {
704         return E_WRITE_REPLY_ERR;
705     }
706     return E_OK;
707 }
708 
HandleGetFileEncryptStatus(MessageParcel & data,MessageParcel & reply)709 int32_t StorageDaemonStub::HandleGetFileEncryptStatus(MessageParcel &data, MessageParcel &reply)
710 {
711     uint32_t userId = data.ReadUint32();
712     bool needCheckDirMount = data.ReadBool();
713     bool isEncrypted = true;
714     int err = GetFileEncryptStatus(userId, isEncrypted, needCheckDirMount);
715     if (!reply.WriteInt32(err)) {
716         return E_WRITE_REPLY_ERR;
717     }
718     if (!reply.WriteBool(isEncrypted)) {
719         return E_WRITE_REPLY_ERR;
720     }
721     return E_OK;
722 }
723 } // StorageDaemon
724 } // OHOS
725