• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef STORAGE_DAEMON_CLIENT_H
17 #define STORAGE_DAEMON_CLIENT_H
18 
19 #include <iostream>
20 
21 #include "ipc/storage_daemon.h"
22 #include "istorage_daemon.h"
23 namespace OHOS {
24 namespace StorageDaemon {
25 class StorageDaemonClient {
26 public:
27     static int32_t PrepareUserDirs(int32_t userId, uint32_t flags);
28     static int32_t DestroyUserDirs(int32_t userId, uint32_t flags);
29     static int32_t StartUser(int32_t userId);
30     static int32_t StopUser(int32_t userId);
31     static int32_t PrepareUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags);
32     static int32_t DestroyUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags);
33     static int32_t InitGlobalKey(void);
34     static int32_t InitGlobalUserKeys(void);
35     static int32_t GenerateUserKeys(uint32_t userId, uint32_t flags);
36     static int32_t DeleteUserKeys(uint32_t userId);
37     static int32_t UpdateUserAuth(uint32_t userId, uint64_t secureUid,
38                                   const std::vector<uint8_t> &token,
39                                   const std::vector<uint8_t> &oldSecret,
40                                   const std::vector<uint8_t> &newSecret);
41     static int32_t UpdateUseAuthWithRecoveryKey(const std::vector<uint8_t> &authToken,
42                                                 const std::vector<uint8_t> &newSecret,
43                                                 uint64_t secureUid,
44                                                 uint32_t userId,
45                                                 std::vector<std::vector<uint8_t>> &plainText);
46     static int32_t ActiveUserKey(uint32_t userId,
47                                  const std::vector<uint8_t> &token,
48                                  const std::vector<uint8_t> &secret);
49     static int32_t InactiveUserKey(uint32_t userId);
50     static int32_t FscryptEnable(const std::string &fscryptOptions);
51     static int32_t UpdateKeyContext(uint32_t userId, bool needRemoveTmpKey = false);
52     static int32_t LockUserScreen(uint32_t userId);
53     static int32_t UnlockUserScreen(uint32_t userId,
54                                     const std::vector<uint8_t> &token,
55                                     const std::vector<uint8_t> &secret);
56     static int32_t GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus);
57     static int32_t GenerateAppkey(uint32_t userId, uint32_t hashId, std::string &keyId);
58     static int32_t DeleteAppkey(uint32_t userId, const std::string keyId);
59     static int32_t MountDfsDocs(int32_t userId, const std::string &relativePath,
60         const std::string &networkId, const std::string &deviceId);
61     static int32_t UMountDfsDocs(int32_t userId, const std::string &relativePath,
62         const std::string &networkId, const std::string &deviceId);
63     static int32_t GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount = false);
64     static int32_t GetUserNeedActiveStatus(uint32_t userId, bool &needActive);
65     static int32_t CreateRecoverKey(uint32_t userId,
66                                     uint32_t userType,
67                                     const std::vector<uint8_t> &token,
68                                     const std::vector<uint8_t> &secret);
69     static int32_t SetRecoverKey(const std::vector<uint8_t> &key);
70     // file mgr fuse
71     static int32_t MountFileMgrFuse(int32_t userId, const std::string &path, int32_t &fuseFd);
72     static int32_t UMountFileMgrFuse(int32_t userId, const std::string &path);
73     // file lock
74     static int32_t IsFileOccupied(const std::string &path, const std::vector<std::string> &inputList,
75         std::vector<std::string> &outputList, bool &isOccupy);
76 
77 private:
78     static sptr<IStorageDaemon> GetStorageDaemonProxy(void);
79     static int32_t CheckServiceStatus(uint32_t serviceFlags);
80 };
81 } // StorageDaemon
82 } // OHOS
83 
84 #endif
85