1 /*
2 * Copyright (c) 2022-2025 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 <chrono>
17 #include <ctime>
18 #include <thread>
19 #include "storage_daemon_client.h"
20 #include "iservice_registry.h"
21 #include "libfscrypt/fscrypt_utils.h"
22 #include "storage_service_errno.h"
23 #include "storage_service_log.h"
24 #include "system_ability_definition.h"
25 #include "utils/storage_radar.h"
26
27 using namespace OHOS::StorageService;
28 namespace {
29 constexpr uint32_t STORAGE_DAEMON_SFIFT = 1;
30 constexpr uint32_t CHECK_SERVICE_TIMES = 1000;
31 constexpr uint32_t LOG_CHECK_INTERVAL = 50;
32 constexpr uint32_t SLEEP_TIME_PRE_CHECK = 20; // 20ms
33 constexpr uint32_t STORAGE_SERVICE_FLAG = (1 << STORAGE_DAEMON_SFIFT);
34 constexpr int32_t STORAGE_DAEMON_SAID = OHOS::STORAGE_MANAGER_DAEMON_ID;
35 }
36
37 namespace OHOS {
38 namespace StorageDaemon {
GetStorageDaemonProxy(void)39 sptr<IStorageDaemon> StorageDaemonClient::GetStorageDaemonProxy(void)
40 {
41 auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
42 if (samgr == nullptr) {
43 LOGE("samgr empty error");
44 return nullptr;
45 }
46
47 sptr<IRemoteObject> object = samgr->GetSystemAbility(OHOS::STORAGE_MANAGER_DAEMON_ID);
48 if (object == nullptr) {
49 LOGE("storage daemon client samgr ablity empty error");
50 return nullptr;
51 }
52
53 return iface_cast<IStorageDaemon>(object);
54 }
55
CheckServiceStatus(uint32_t serviceFlags)56 int32_t StorageDaemonClient::CheckServiceStatus(uint32_t serviceFlags)
57 {
58 LOGW("CheckServiceStatus start");
59
60 auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
61 if (samgr == nullptr) {
62 LOGW("samgr is nullptr, retry");
63 for (uint32_t i = 0; i < CHECK_SERVICE_TIMES; i++) {
64 samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
65 if (samgr != nullptr) {
66 break;
67 }
68 if (i % LOG_CHECK_INTERVAL == 0) {
69 LOGW("check samgr %{public}u times", i);
70 }
71 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_PRE_CHECK));
72 }
73 if (samgr == nullptr) {
74 LOGE("samgr is nullptr, retry failed.");
75 return E_SA_IS_NULLPTR;
76 }
77 }
78
79 if (serviceFlags & STORAGE_SERVICE_FLAG) {
80 bool exist = false;
81 for (uint32_t i = 0; i < CHECK_SERVICE_TIMES; i++) {
82 auto object = samgr->CheckSystemAbility(STORAGE_DAEMON_SAID, exist);
83 if (object != nullptr) {
84 break;
85 }
86 if (i % LOG_CHECK_INTERVAL == 0) {
87 LOGW("check storage daemon status %{public}u times", i);
88 }
89 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_PRE_CHECK));
90 }
91 if (exist == false) {
92 LOGE("storage daemon service system ability error");
93 return E_SERVICE_IS_NULLPTR;
94 }
95 }
96 LOGW("CheckServiceStatus end, success");
97
98 return E_OK;
99 }
100
PrepareUserDirs(int32_t userId,uint32_t flags)101 int32_t StorageDaemonClient::PrepareUserDirs(int32_t userId, uint32_t flags)
102 {
103 LOGI("StorageDaemonClient::PrepareUserDirs, userId:%{public}d, flags:%{public}u", userId, flags);
104 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
105 if (status != E_OK) {
106 LOGE("service check failed");
107 std::string extraData = "flags=" + std::to_string(flags);
108 StorageRadar::ReportUserManager("PrepareUserDirs::CheckServiceStatus", userId, status, extraData);
109 return status;
110 }
111
112 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
113 if (client == nullptr) {
114 LOGE("get storage daemon service failed");
115 std::string extraData = "flags=" + std::to_string(flags);
116 StorageRadar::ReportUserManager("PrepareUserDirs::GetStorageDaemonProxy", userId, E_SA_IS_NULLPTR, extraData);
117 return E_SA_IS_NULLPTR;
118 }
119 return client->PrepareUserDirs(userId, flags);
120 }
121
DestroyUserDirs(int32_t userId,uint32_t flags)122 int32_t StorageDaemonClient::DestroyUserDirs(int32_t userId, uint32_t flags)
123 {
124 LOGI("StorageDaemonClient::DestroyUserDirs, userId:%{public}d, flags:%{public}u", userId, flags);
125 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
126 if (status != E_OK) {
127 LOGE("service check failed");
128 std::string extraData = "flags=" + std::to_string(flags);
129 StorageRadar::ReportUserManager("DestroyUserDirs::CheckServiceStatus", userId, status, extraData);
130 return status;
131 }
132
133 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
134 if (client == nullptr) {
135 LOGE("get storage daemon service failed");
136 std::string extraData = "flags=" + std::to_string(flags);
137 StorageRadar::ReportUserManager("DestroyUserDirs::GetStorageDaemonProxy", userId, E_SA_IS_NULLPTR, extraData);
138 return E_SA_IS_NULLPTR;
139 }
140 return client->DestroyUserDirs(userId, flags);
141 }
142
StartUser(int32_t userId)143 int32_t StorageDaemonClient::StartUser(int32_t userId)
144 {
145 LOGI("StorageDaemonClient::StartUser, userId:%{public}d", userId);
146 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
147 if (status != E_OK) {
148 LOGE("service check failed");
149 StorageRadar::ReportUserManager("StartUser::CheckServiceStatus", userId, status, "");
150 return status;
151 }
152
153 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
154 if (client == nullptr) {
155 LOGE("get storage daemon service failed");
156 StorageRadar::ReportUserManager("StartUser::GetStorageDaemonProxy", userId, E_SA_IS_NULLPTR, "");
157 return E_SA_IS_NULLPTR;
158 }
159
160 return client->StartUser(userId);
161 }
162
StopUser(int32_t userId)163 int32_t StorageDaemonClient::StopUser(int32_t userId)
164 {
165 LOGI("StorageDaemonClient::StopUser, userId:%{public}d", userId);
166 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
167 if (status != E_OK) {
168 LOGE("service check failed");
169 StorageRadar::ReportUserManager("StartUser::CheckServiceStatus", userId, status, "");
170 return status;
171 }
172
173 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
174 if (client == nullptr) {
175 LOGE("get storage daemon service failed");
176 StorageRadar::ReportUserManager("StartUser::GetStorageDaemonProxy", userId, E_SA_IS_NULLPTR, "");
177 return E_SA_IS_NULLPTR;
178 }
179
180 return client->StopUser(userId);
181 }
182
PrepareUserSpace(uint32_t userId,const std::string & volumId,uint32_t flags)183 int32_t StorageDaemonClient::PrepareUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags)
184 {
185 LOGI("StorageDaemonClient::PrepareUserSpace, userId:%{public}u, volumId:%{public}s, flags:%{publc}u",
186 userId, volumId.c_str(), flags);
187 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
188 if (status != E_OK) {
189 LOGE("service check failed");
190 return status;
191 }
192
193 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
194 if (client == nullptr) {
195 LOGE("get storage daemon service failed");
196 return E_SA_IS_NULLPTR;
197 }
198
199 return client->PrepareUserDirs(userId, flags);
200 }
201
DestroyUserSpace(uint32_t userId,const std::string & volumId,uint32_t flags)202 int32_t StorageDaemonClient::DestroyUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags)
203 {
204 LOGI("StorageDaemonClient::DestroyUserSpace, userId:%{public}u, volumId:%{public}s, flags:%{publc}u",
205 userId, volumId.c_str(), flags);
206 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
207 if (status != E_OK) {
208 LOGE("service check failed");
209 return status;
210 }
211
212 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
213 if (client == nullptr) {
214 LOGE("get storage daemon service failed");
215 return E_SA_IS_NULLPTR;
216 }
217
218 return client->DestroyUserDirs(userId, flags);
219 }
220
InitGlobalKey(void)221 int32_t StorageDaemonClient::InitGlobalKey(void)
222 {
223 int32_t status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
224 if (status != E_OK) {
225 LOGE("service check failed");
226 StorageRadar::ReportUserKeyResult("InitGlobalKey::CheckServiceStatus", 0, status, "EL1", "");
227 return status;
228 }
229
230 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
231 if (client == nullptr) {
232 LOGE("get storage daemon service failed");
233 StorageRadar::ReportUserKeyResult("InitGlobalKey::GetStorageDaemonProxy", 0, E_SA_IS_NULLPTR, "EL1", "");
234 return E_SA_IS_NULLPTR;
235 }
236
237 return client->InitGlobalKey();
238 }
239
InitGlobalUserKeys(void)240 int32_t StorageDaemonClient::InitGlobalUserKeys(void)
241 {
242 int32_t status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
243 if (status != E_OK) {
244 LOGE("service check failed");
245 StorageRadar::ReportUserKeyResult("InitGlobalUserKeys::CheckServiceStatus", 0, status, "EL1", "");
246 return status;
247 }
248
249 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
250 if (client == nullptr) {
251 LOGE("get storage daemon service failed");
252 StorageRadar::ReportUserKeyResult("InitGlobalUserKeys::GetStorageDaemonProxy", 0, E_SA_IS_NULLPTR, "EL1", "");
253 return E_SA_IS_NULLPTR;
254 }
255
256 return client->InitGlobalUserKeys();
257 }
258
GenerateUserKeys(uint32_t userId,uint32_t flags)259 int32_t StorageDaemonClient::GenerateUserKeys(uint32_t userId, uint32_t flags)
260 {
261 LOGI("StorageDaemonClient::GenerateUserKeys, userId: %{public}u, flags:%{public}u", userId, flags);
262 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
263 if (status != E_OK) {
264 LOGE("service check failed");
265 return status;
266 }
267
268 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
269 if (client == nullptr) {
270 LOGE("get storage daemon service failed");
271 return E_SA_IS_NULLPTR;
272 }
273
274 return client->GenerateUserKeys(userId, flags);
275 }
276
DeleteUserKeys(uint32_t userId)277 int32_t StorageDaemonClient::DeleteUserKeys(uint32_t userId)
278 {
279 LOGI("StorageDaemonClient::DeleteUserKeys, userId: %{public}u", userId);
280 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
281 if (status != E_OK) {
282 LOGE("service check failed");
283 return status;
284 }
285
286 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
287 if (client == nullptr) {
288 LOGE("get storage daemon service failed");
289 return E_SA_IS_NULLPTR;
290 }
291
292 return client->DeleteUserKeys(userId);
293 }
294
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)295 int32_t StorageDaemonClient::UpdateUserAuth(uint32_t userId, uint64_t secureUid,
296 const std::vector<uint8_t> &token,
297 const std::vector<uint8_t> &oldSecret,
298 const std::vector<uint8_t> &newSecret)
299 {
300 LOGI("StorageDaemonClient::UpdateUserAuth, userId: %{public}u, token:%{public}d,"
301 "oldSecret:%{public}d, newSecret:%{public}d", userId, token.empty(), oldSecret.empty(), newSecret.empty());
302 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
303 if (status != E_OK) {
304 LOGE("service check failed");
305 return status;
306 }
307
308 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
309 if (client == nullptr) {
310 LOGE("get storage daemon service failed");
311 return E_SA_IS_NULLPTR;
312 }
313
314 return client->UpdateUserAuth(userId, secureUid, token, oldSecret, newSecret);
315 }
316
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)317 int32_t StorageDaemonClient::UpdateUseAuthWithRecoveryKey(const std::vector<uint8_t> &authToken,
318 const std::vector<uint8_t> &newSecret,
319 uint64_t secureUid,
320 uint32_t userId,
321 std::vector<std::vector<uint8_t>> &plainText)
322 {
323 LOGI("StorageDaemonClient::UpdateUseAuthWithRecoveryKey, authToken: %{public}d, newSecret:%{public}d,"
324 "userId:%{public}d", authToken.empty(), newSecret.empty(), userId);
325 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
326 if (status != E_OK) {
327 LOGE("service check failed");
328 return status;
329 }
330
331 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
332 if (client == nullptr) {
333 LOGE("get storage daemon service failed");
334 return E_SA_IS_NULLPTR;
335 }
336
337 return client->UpdateUseAuthWithRecoveryKey(authToken, newSecret, secureUid, userId, plainText);
338 }
339
ActiveUserKey(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)340 int32_t StorageDaemonClient::ActiveUserKey(uint32_t userId,
341 const std::vector<uint8_t> &token,
342 const std::vector<uint8_t> &secret)
343 {
344 LOGI("StorageDaemonClient::ActiveUserKey, userId: %{public}u, token:%{public}d, secret:%{public}d",
345 userId, token.empty(), secret.empty());
346 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
347 if (status != E_OK) {
348 LOGE("service check failed");
349 return status;
350 }
351
352 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
353 if (client == nullptr) {
354 LOGE("get storage daemon service failed");
355 return E_SA_IS_NULLPTR;
356 }
357
358 return client->ActiveUserKey(userId, token, secret);
359 }
360
InactiveUserKey(uint32_t userId)361 int32_t StorageDaemonClient::InactiveUserKey(uint32_t userId)
362 {
363 LOGI("StorageDaemonClient::InactiveUserKey, userId: %{public}u", userId);
364 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
365 if (status != E_OK) {
366 LOGE("service check failed");
367 return status;
368 }
369 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
370 if (client == nullptr) {
371 LOGE("get storage daemon service failed");
372 return E_SA_IS_NULLPTR;
373 }
374
375 return client->InactiveUserKey(userId);
376 }
377
LockUserScreen(uint32_t userId)378 int32_t StorageDaemonClient::LockUserScreen(uint32_t userId)
379 {
380 LOGI("StorageDaemonClient::LockUserScreen, userId: %{public}u", userId);
381 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
382 if (status != E_OK) {
383 LOGE("service check failed");
384 return status;
385 }
386
387 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
388 if (client == nullptr) {
389 LOGE("get storage daemon service failed");
390 return E_SA_IS_NULLPTR;
391 }
392
393 return client->LockUserScreen(userId);
394 }
395
UnlockUserScreen(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)396 int32_t StorageDaemonClient::UnlockUserScreen(uint32_t userId, const std::vector<uint8_t> &token,
397 const std::vector<uint8_t> &secret)
398 {
399 LOGI("StorageDaemonClient::UnlockUserScreen, userId: %{public}u, token:%{public}d, secret:%{public}d",
400 userId, token.empty(), secret.empty());
401 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
402 if (status != E_OK) {
403 LOGE("service check failed");
404 return status;
405 }
406
407 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
408 if (client == nullptr) {
409 LOGE("get storage daemon service failed");
410 return E_SA_IS_NULLPTR;
411 }
412
413 return client->UnlockUserScreen(userId, token, secret);
414 }
415
GetLockScreenStatus(uint32_t userId,bool & lockScreenStatus)416 int32_t StorageDaemonClient::GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus)
417 {
418 LOGI("StorageDaemonClient::GetLockScreenStatus, userId: %{public}u", userId);
419 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
420 if (status != E_OK) {
421 LOGE("service check failed");
422 return status;
423 }
424
425 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
426 if (client == nullptr) {
427 LOGE("get storage daemon service failed");
428 return E_SA_IS_NULLPTR;
429 }
430
431 return client->GetLockScreenStatus(userId, lockScreenStatus);
432 }
433
UpdateKeyContext(uint32_t userId,bool needRemoveTmpKey)434 int32_t StorageDaemonClient::UpdateKeyContext(uint32_t userId, bool needRemoveTmpKey)
435 {
436 LOGI("StorageDaemonClient::UpdateKeyContext, userId: %{public}u", userId);
437 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
438 if (status != E_OK) {
439 LOGE("service check failed");
440 return status;
441 }
442
443 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
444 if (client == nullptr) {
445 LOGE("get storage daemon service failed");
446 return E_SA_IS_NULLPTR;
447 }
448
449 return client->UpdateKeyContext(userId, needRemoveTmpKey);
450 }
451
GenerateAppkey(uint32_t userId,uint32_t hashId,std::string & keyId)452 int32_t StorageDaemonClient::GenerateAppkey(uint32_t userId, uint32_t hashId, std::string &keyId)
453 {
454 LOGI("StorageDaemonClient::GenerateAppkey, userId: %{public}u, hashId:%{public}u", userId, hashId);
455 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
456 if (status != E_OK) {
457 LOGE("service check failed");
458 return status;
459 }
460
461 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
462 if (client == nullptr) {
463 LOGE("get storage daemon service failed");
464 return E_SA_IS_NULLPTR;
465 }
466
467 return client->GenerateAppkey(userId, hashId, keyId, false);
468 }
469
DeleteAppkey(uint32_t userId,const std::string keyId)470 int32_t StorageDaemonClient::DeleteAppkey(uint32_t userId, const std::string keyId)
471 {
472 LOGI("StorageDaemonClient::DeleteAppkey, userId: %{public}u, keyId:%{public}s", userId, keyId.c_str());
473 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
474 if (status != E_OK) {
475 LOGE("service check failed");
476 return status;
477 }
478
479 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
480 if (client == nullptr) {
481 LOGE("get storage daemon service failed");
482 return E_SA_IS_NULLPTR;
483 }
484
485 return client->DeleteAppkey(userId, keyId);
486 }
487
CreateRecoverKey(uint32_t userId,uint32_t userType,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)488 int32_t StorageDaemonClient::CreateRecoverKey(uint32_t userId,
489 uint32_t userType,
490 const std::vector<uint8_t> &token,
491 const std::vector<uint8_t> &secret)
492 {
493 LOGI("StorageDaemonClient::CreateRecoverKey, userId: %{public}u, userType:%{public}u,token:%{public}d,"
494 "secret:%{public}d", userId, userType, token.empty(), secret.empty());
495 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
496 if (status != E_OK) {
497 LOGE("service check failed");
498 return status;
499 }
500
501 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
502 if (client == nullptr) {
503 LOGE("get storage daemon service failed");
504 return E_SA_IS_NULLPTR;
505 }
506
507 return client->CreateRecoverKey(userId, userType, token, secret);
508 }
509
SetRecoverKey(const std::vector<uint8_t> & key)510 int32_t StorageDaemonClient::SetRecoverKey(const std::vector<uint8_t> &key)
511 {
512 LOGI("StorageDaemonClient::SetRecoverKey, key:%{public}d", key.empty());
513 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
514 if (status != E_OK) {
515 LOGE("service check failed");
516 return status;
517 }
518
519 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
520 if (client == nullptr) {
521 LOGE("get storage daemon service failed");
522 return E_SA_IS_NULLPTR;
523 }
524
525 return client->SetRecoverKey(key);
526 }
527
MountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)528 int32_t StorageDaemonClient::MountDfsDocs(int32_t userId, const std::string &relativePath,
529 const std::string &networkId, const std::string &deviceId)
530 {
531 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
532 if (status != E_OK) {
533 LOGE("service check failed");
534 return status;
535 }
536
537 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
538 if (client == nullptr) {
539 LOGE("Get StorageDaemon service failed!");
540 return E_SA_IS_NULLPTR;
541 }
542
543 return client->MountDfsDocs(userId, relativePath, networkId, deviceId);
544 }
545
UMountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)546 int32_t StorageDaemonClient::UMountDfsDocs(int32_t userId, const std::string &relativePath,
547 const std::string &networkId, const std::string &deviceId)
548 {
549 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
550 if (status != E_OK) {
551 LOGE("service check failed");
552 return status;
553 }
554
555 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
556 if (client == nullptr) {
557 LOGE("Get StorageDaemon service failed!");
558 return E_SA_IS_NULLPTR;
559 }
560
561 return client->UMountDfsDocs(userId, relativePath, networkId, deviceId);
562 }
563
FscryptEnable(const std::string & fscryptOptions)564 int32_t StorageDaemonClient::FscryptEnable(const std::string &fscryptOptions)
565 {
566 #ifdef USER_CRYPTO_MANAGER
567 int ret = SetFscryptSysparam(fscryptOptions.c_str());
568 if (ret) {
569 LOGE("Init fscrypt policy failed ret %{public}d", ret);
570 return ret;
571 }
572 #endif
573
574 return 0;
575 }
576
GetFileEncryptStatus(uint32_t userId,bool & isEncrypted,bool needCheckDirMount)577 int32_t StorageDaemonClient::GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount)
578 {
579 LOGI("StorageDaemonClient::GetFileEncryptStatus, userId:%{public}d", userId);
580 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
581 if (status != E_OK) {
582 LOGE("service check failed");
583 return status;
584 }
585
586 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
587 if (client == nullptr) {
588 LOGE("Get StorageDaemon service failed!");
589 return E_SA_IS_NULLPTR;
590 }
591
592 return client->GetFileEncryptStatus(userId, isEncrypted, needCheckDirMount);
593 }
594
GetUserNeedActiveStatus(uint32_t userId,bool & needActive)595 int32_t StorageDaemonClient::GetUserNeedActiveStatus(uint32_t userId, bool &needActive)
596 {
597 LOGI("StorageDaemonClient::GetUserNeedActiveStatus, userId:%{public}d", userId);
598 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
599 if (status != E_OK) {
600 LOGE("service check failed");
601 return status;
602 }
603
604 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
605 if (client == nullptr) {
606 LOGE("Get StorageDaemon service failed!");
607 return E_SA_IS_NULLPTR;
608 }
609
610 return client->GetUserNeedActiveStatus(userId, needActive);
611 }
612
MountFileMgrFuse(int32_t userId,const std::string & path,int32_t & fuseFd)613 int32_t StorageDaemonClient::MountFileMgrFuse(int32_t userId, const std::string &path, int32_t &fuseFd)
614 {
615 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
616 if (status != E_OK) {
617 LOGE("service check failed");
618 return status;
619 }
620 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
621 if (client == nullptr) {
622 LOGE("Get StorageDaemon service failed!");
623 return E_SA_IS_NULLPTR;
624 }
625 return client->MountFileMgrFuse(userId, path, fuseFd);
626 }
627
UMountFileMgrFuse(int32_t userId,const std::string & path)628 int32_t StorageDaemonClient::UMountFileMgrFuse(int32_t userId, const std::string &path)
629 {
630 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
631 if (status != E_OK) {
632 LOGE("service check failed");
633 return status;
634 }
635 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
636 if (client == nullptr) {
637 LOGE("Get StorageDaemon service failed!");
638 return E_SA_IS_NULLPTR;
639 }
640 return client->UMountFileMgrFuse(userId, path);
641 }
642
IsFileOccupied(const std::string & path,const std::vector<std::string> & inputList,std::vector<std::string> & outputList,bool & isOccupy)643 int32_t StorageDaemonClient::IsFileOccupied(const std::string &path, const std::vector<std::string> &inputList,
644 std::vector<std::string> &outputList, bool &isOccupy)
645 {
646 LOGI("StorageDaemonClient::IsFileOccupied");
647 auto status = CheckServiceStatus(STORAGE_SERVICE_FLAG);
648 if (status != E_OK) {
649 LOGE("service check failed");
650 return status;
651 }
652 sptr<IStorageDaemon> client = GetStorageDaemonProxy();
653 if (client == nullptr) {
654 LOGE("Get StorageDaemon service failed!");
655 return E_SA_IS_NULLPTR;
656 }
657 return client->IsFileOccupied(path, inputList, outputList, isOccupy);
658 }
659 } // namespace StorageDaemon
660 } // namespace OHOS
661