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 #ifndef OHOS_STORAGE_DAEMON_ISTORAGE_DAEMON_H
17 #define OHOS_STORAGE_DAEMON_ISTORAGE_DAEMON_H
18 
19 #include <string>
20 #include "iremote_broker.h"
21 
22 namespace OHOS {
23 namespace StorageDaemon {
24 class IStorageDaemon : public IRemoteBroker {
25 public:
26     enum {
27         CRYPTO_FLAG_EL1 = 1,
28         CRYPTO_FLAG_EL2 = 2,
29         CRYPTO_FLAG_EL3 = 4,
30         CRYPTO_FLAG_EL4 = 8,
31         CRYPTO_FLAG_EL5 = 16,
32     };
33 
34     virtual int32_t Shutdown() = 0;
35 
36     virtual int32_t Mount(const std::string &volId, uint32_t flags) = 0;
37     virtual int32_t UMount(const std::string &volId) = 0;
38     virtual int32_t Check(const std::string &volId) = 0;
39     virtual int32_t Format(const std::string &volId, const std::string &fsType) = 0;
40     virtual int32_t Partition(const std::string &diskId, int32_t type) = 0;
41     virtual int32_t SetVolumeDescription(const std::string &volId, const std::string &description) = 0;
42 
43     virtual int32_t StartUser(int32_t userId) = 0;
44     virtual int32_t StopUser(int32_t userId) = 0;
45     virtual int32_t PrepareUserDirs(int32_t userId, uint32_t flags) = 0;
46     virtual int32_t DestroyUserDirs(int32_t userId, uint32_t flags) = 0;
47     virtual int32_t CompleteAddUser(int32_t userId) = 0;
48 
49     // fscrypt api
50     virtual int32_t InitGlobalKey(void) = 0;
51     virtual int32_t InitGlobalUserKeys(void) = 0;
52     virtual int32_t GenerateUserKeys(uint32_t userId, uint32_t flags) = 0;
53     virtual int32_t DeleteUserKeys(uint32_t userId) = 0;
54     virtual int32_t UpdateUserAuth(uint32_t userId, uint64_t secureUid,
55                                    const std::vector<uint8_t> &token,
56                                    const std::vector<uint8_t> &oldSecret,
57                                    const std::vector<uint8_t> &newSecret) = 0;
58     virtual int32_t ActiveUserKey(uint32_t userId,
59                                   const std::vector<uint8_t> &token,
60                                   const std::vector<uint8_t> &secret) = 0;
61     virtual int32_t InactiveUserKey(uint32_t userId) = 0;
62     virtual int32_t UpdateKeyContext(uint32_t userId) = 0;
63     virtual int32_t MountCryptoPathAgain(uint32_t userId) = 0;
64     virtual int32_t LockUserScreen(uint32_t userId) = 0;
65     virtual int32_t UnlockUserScreen(uint32_t user,
66                                      const std::vector<uint8_t> &token,
67                                      const std::vector<uint8_t> &secret) = 0;
68     virtual int32_t GetLockScreenStatus(uint32_t user, bool &lockScreenStatus) = 0;
69     virtual int32_t GenerateAppkey(uint32_t userId, uint32_t hashId, std::string &keyId) = 0;
70     virtual int32_t DeleteAppkey(uint32_t userId, const std::string &keyId) = 0;
71 
72     // app file share api
73     virtual std::vector<int32_t> CreateShareFile(const std::vector<std::string> &uriList,
74                                                 uint32_t tokenId, uint32_t flag) = 0;
75     virtual int32_t DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &uriList) = 0;
76 
SetBundleQuota(const std::string & bundleName,int32_t uid,const std::string & bundleDataDirPath,int32_t limitSizeMb)77     virtual int32_t SetBundleQuota(const std::string &bundleName, int32_t uid,
78         const std::string &bundleDataDirPath, int32_t limitSizeMb)
79     {
80         return 0;
81     }
82 
83     virtual int32_t GetOccupiedSpace(int32_t idType, int32_t id, int64_t &size) = 0;
84 
85     virtual int32_t UpdateMemoryPara(int32_t size, int32_t &oldSize) = 0;
86     virtual int32_t GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames,
87         const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes,
88         std::vector<int64_t> &incPkgFileSizes) = 0;
89     virtual int32_t MountDfsDocs(int32_t userId, const std::string &relativePath,
90         const std::string &networkId, const std::string &deviceId) = 0;
91     virtual int32_t UMountDfsDocs(int32_t userId, const std::string &relativePath,
92         const std::string &networkId, const std::string &deviceId) = 0;
93     virtual int32_t GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount = false) = 0;
94 
95     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.StorageDaemon");
96 };
97 } // STORAGE_DAEMON
98 } // OHOS
99 
100 #endif // OHOS_STORAGE_DAEMON_ISTORAGE_DAEMON_H
101