1 /* 2 * Copyright (c) 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 OHOS_STORAGE_MANAGER_STORAGE_MANAGER_PROVIDER_H 17 #define OHOS_STORAGE_MANAGER_STORAGE_MANAGER_PROVIDER_H 18 19 #include "istorage_manager.h" 20 #include "storage_manager.h" 21 #include "storage_manager_stub.h" 22 #include "system_ability.h" 23 #include "storage_file_raw_data.h" 24 25 namespace OHOS { 26 namespace StorageManager { 27 class StorageManagerProvider : public SystemAbility, public StorageManagerStub { 28 DECLARE_SYSTEM_ABILITY(StorageManagerProvider) 29 public: 30 const std::string PATH_INVALID_FLAG1 = "../"; 31 const std::string PATH_INVALID_FLAG2 = "/.."; 32 const uint32_t PATH_INVALID_FLAG_LEN = 3; 33 const char FILE_SEPARATOR_CHAR = '/'; 34 StorageManagerProvider(int32_t saID, bool runOnCreate = true) SystemAbility(saID,runOnCreate)35 : SystemAbility(saID, runOnCreate), manager_(StorageManager::GetInstance()) {}; 36 ~StorageManagerProvider() = default; 37 38 void OnStart() override; 39 void OnStop() override; 40 41 int32_t PrepareAddUser(int32_t userId, uint32_t flags) override; 42 int32_t RemoveUser(int32_t userId, uint32_t flags) override; 43 int32_t PrepareStartUser(int32_t userId) override; 44 int32_t StopUser(int32_t userId) override; 45 int32_t CompleteAddUser(int32_t userId) override; 46 47 int32_t GetFreeSizeOfVolume(const std::string &volumeUuid, int64_t &freeSize) override; 48 int32_t GetTotalSizeOfVolume(const std::string &volumeUuid, int64_t &totalSize) override; 49 int32_t GetBundleStats(const std::string &pkgName, 50 BundleStats &bundleStats, 51 int32_t appIndex, 52 uint32_t statFlag) override; 53 int32_t GetSystemSize(int64_t &systemSize) override; 54 int32_t GetTotalSize(int64_t &totalSize) override; 55 int32_t GetFreeSize(int64_t &freeSize) override; 56 int32_t GetUserStorageStats(StorageStats &storageStats) override; 57 int32_t GetUserStorageStats(int32_t userId, StorageStats &storageStats) override; 58 int32_t GetCurrentBundleStats(BundleStats &bundleStats, uint32_t statFlag) override; 59 int32_t GetUserStorageStatsByType(int32_t userId, StorageStats &storageStats, const std::string &type) override; 60 61 int32_t NotifyVolumeCreated(const VolumeCore &vc) override; 62 int32_t NotifyVolumeMounted(const std::string &volumeId, 63 const std::string &fsTypeStr, 64 const std::string &fsUuid, 65 const std::string &path, 66 const std::string &description) override; 67 int32_t NotifyVolumeDamaged(const std::string &volumeId, 68 const std::string &fsTypeStr, 69 const std::string &fsUuid, 70 const std::string &path, 71 const std::string &description) override; 72 int32_t NotifyVolumeStateChanged(const std::string &volumeId, uint32_t state) override; 73 74 int32_t Mount(const std::string &volumeId) override; 75 int32_t Unmount(const std::string &volumeId) override; 76 int32_t TryToFix(const std::string &volumeId) override; 77 78 int32_t GetAllVolumes(std::vector<VolumeExternal> &vecOfVol) override; 79 80 int32_t NotifyDiskCreated(const Disk &disk) override; 81 int32_t NotifyDiskDestroyed(const std::string &diskId) override; 82 int32_t Partition(const std::string &diskId, int32_t type) override; 83 int32_t GetAllDisks(std::vector<Disk> &vecOfDisk) override; 84 85 int32_t GetVolumeByUuid(const std::string &fsUuid, VolumeExternal &vc) override; 86 int32_t GetVolumeById(const std::string &volumeId, VolumeExternal &vc) override; 87 int32_t SetVolumeDescription(const std::string &fsUuid, const std::string &description) override; 88 int32_t Format(const std::string &volumeId, const std::string &fsType) override; 89 int32_t GetDiskById(const std::string &diskId, Disk &disk) override; 90 int32_t QueryUsbIsInUse(const std::string &diskPath, bool &isInUse) override; 91 92 int32_t NotifyMtpMounted(const std::string &id, 93 const std::string &path, 94 const std::string &desc, 95 const std::string &uuid) override; 96 int32_t NotifyMtpUnmounted(const std::string &id, const std::string &path, bool isBadRemove) override; 97 98 // fscrypt api 99 int32_t GenerateUserKeys(uint32_t userId, uint32_t flags) override; 100 int32_t DeleteUserKeys(uint32_t userId) override; 101 int32_t UpdateUserAuth(uint32_t userId, 102 uint64_t secureUid, 103 const std::vector<uint8_t> &token, 104 const std::vector<uint8_t> &oldSecret, 105 const std::vector<uint8_t> &newSecret) override; 106 int32_t UpdateUseAuthWithRecoveryKey(const std::vector<uint8_t> &authToken, 107 const std::vector<uint8_t> &newSecret, 108 uint64_t secureUid, 109 uint32_t userId, 110 const std::vector<std::vector<uint8_t>> &plainText) override; 111 int32_t ActiveUserKey(uint32_t userId, 112 const std::vector<uint8_t> &token, 113 const std::vector<uint8_t> &secret) override; 114 int32_t InactiveUserKey(uint32_t userId) override; 115 int32_t UpdateKeyContext(uint32_t userId, bool needRemoveTmpKey = false) override; 116 int32_t LockUserScreen(uint32_t userId) override; 117 int32_t UnlockUserScreen(uint32_t userId, 118 const std::vector<uint8_t> &token, 119 const std::vector<uint8_t> &secret) override; 120 int32_t GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus) override; 121 int32_t GenerateAppkey(uint32_t hashId, uint32_t userId, std::string &keyId, bool needReSet = false) override; 122 int32_t DeleteAppkey(const std::string &keyId) override; 123 int32_t GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount = false) override; 124 int32_t GetUserNeedActiveStatus(uint32_t userId, bool &needActive) override; 125 int32_t CreateRecoverKey(uint32_t userId, 126 uint32_t userType, 127 const std::vector<uint8_t> &token, 128 const std::vector<uint8_t> &secret) override; 129 int32_t SetRecoverKey(const std::vector<uint8_t> &key) override; 130 int32_t ResetSecretWithRecoveryKey(uint32_t userId, uint32_t rkType, const std::vector<uint8_t> &key) override; 131 132 // app file share api 133 int32_t CreateShareFile(const StorageFileRawData &rawData, 134 uint32_t tokenId, 135 uint32_t flag, 136 std::vector<int32_t> &funcResult) override; 137 int32_t DeleteShareFile(uint32_t tokenId, const StorageFileRawData &rawData) override; 138 139 int32_t SetBundleQuota(const std::string &bundleName, 140 int32_t uid, 141 const std::string &bundleDataDirPath, 142 int32_t limitSizeMb) override; 143 int32_t UpdateMemoryPara(int32_t size, int32_t &oldSize) override; 144 145 // dfs service 146 int32_t MountDfsDocs(int32_t userId, 147 const std::string &relativePath, 148 const std::string &networkId, 149 const std::string &deviceId) override; 150 int32_t UMountDfsDocs(int32_t userId, 151 const std::string &relativePath, 152 const std::string &networkId, 153 const std::string &deviceId) override; 154 155 // media fuse 156 int32_t MountMediaFuse(int32_t userId, int32_t &devFd) override; 157 int32_t UMountMediaFuse(int32_t userId) override; 158 // file mgr fuse 159 int32_t MountFileMgrFuse(int32_t userId, const std::string &path, int32_t &fuseFd) override; 160 int32_t UMountFileMgrFuse(int32_t userId, const std::string &path) override; 161 int32_t IsFileOccupied(const std::string &path, 162 const std::vector<std::string> &inputList, 163 std::vector<std::string> &outputList, 164 bool &isOccupy) override; 165 // reset user event record api 166 void ResetUserEventRecord(int32_t userId); 167 int32_t MountDisShareFile(int32_t userId, const std::map<std::string, std::string> &shareFiles) override; 168 int32_t UMountDisShareFile(int32_t userId, const std::string &networkId) override; 169 int32_t InactiveUserPublicDirKey(uint32_t userId) override; 170 int32_t RegisterUeceActivationCallback(const sptr<IUeceActivationCallback> &ueceCallback) override; 171 int32_t UnregisterUeceActivationCallback() override; 172 private: 173 StorageManagerProvider(); 174 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 175 void SetPriority(); 176 bool IsFilePathInvalid(const std::string &filePath); 177 static sptr<StorageManagerProvider> instance_; 178 std::reference_wrapper<StorageManager> manager_; 179 static std::mutex instanceLock_; 180 std::mutex mutex_; 181 }; 182 } // namespace StorageManager 183 } // namespace OHOS 184 185 #endif // OHOS_STORAGE_MANAGER_STORAGE_MANAGER_H 186