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_MANAGER_STORAGE_DAEMON_COMMUNICATION_H 17 #define OHOS_STORAGE_MANAGER_STORAGE_DAEMON_COMMUNICATION_H 18 19 #include <singleton.h> 20 #include <nocopyable.h> 21 #include "ipc/istorage_daemon.h" 22 #include "iremote_object.h" 23 24 namespace OHOS { 25 namespace StorageManager { 26 class StorageDaemonCommunication : public NoCopyable { 27 DECLARE_DELAYED_SINGLETON(StorageDaemonCommunication); 28 29 public: 30 int32_t Connect(); 31 32 int32_t PrepareAddUser(int32_t userId, uint32_t flags); 33 int32_t RemoveUser(int32_t userId, uint32_t flags); 34 int32_t PrepareStartUser(int32_t userId); 35 int32_t StopUser(int32_t userId); 36 int32_t CompleteAddUser(int32_t userId); 37 38 int32_t Mount(std::string volumeId, int32_t flag); 39 int32_t Unmount(std::string volumeId); 40 int32_t Check(std::string volumeId); 41 int32_t Partition(std::string diskId, int32_t type); 42 int32_t Format(std::string volumeId, std::string type); 43 int32_t SetVolumeDescription(std::string volumeId, std::string description); 44 45 // fscrypt api 46 int32_t GenerateUserKeys(uint32_t userId, uint32_t flags); 47 int32_t DeleteUserKeys(uint32_t userId); 48 int32_t UpdateUserAuth(uint32_t userId, uint64_t secureUid, 49 const std::vector<uint8_t> &token, 50 const std::vector<uint8_t> &oldSecret, 51 const std::vector<uint8_t> &newSecret); 52 int32_t ActiveUserKey(uint32_t userId, 53 const std::vector<uint8_t> &token, 54 const std::vector<uint8_t> &secret); 55 int32_t InactiveUserKey(uint32_t userId); 56 int32_t UpdateKeyContext(uint32_t userId); 57 int32_t MountCryptoPathAgain(int32_t userId); 58 int32_t LockUserScreen(uint32_t userId); 59 int32_t UnlockUserScreen(uint32_t userId, 60 const std::vector<uint8_t> &token, 61 const std::vector<uint8_t> &secret); 62 int32_t GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount = false); 63 int32_t GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus); 64 int32_t GenerateAppkey(uint32_t userId, uint32_t hashId, std::string &keyId); 65 int32_t DeleteAppkey(uint32_t userId, const std::string keyId); 66 67 int32_t ResetSdProxy(); 68 void ForceLockUserScreen(); 69 70 // app file share api 71 std::vector<int32_t> CreateShareFile(const std::vector<std::string> &uriList, uint32_t tokenId, uint32_t flag); 72 int32_t DeleteShareFile(uint32_t tokenId, const std::vector<std::string> &uriList); 73 74 int32_t SetBundleQuota(const std::string &bundleName, int32_t uid, const std::string &bundleDataDirPath, 75 int32_t limitSizeMb); 76 int32_t GetOccupiedSpace(int32_t idType, int32_t id, int64_t &size); 77 int32_t UpdateMemoryPara(int32_t size, int32_t &oldSize); 78 79 int32_t GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames, 80 const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes, 81 std::vector<int64_t> &incPkgFileSizes); 82 83 // dfs service 84 int32_t MountDfsDocs(int32_t userId, const std::string &relativePath, 85 const std::string &networkId, const std::string &deviceId); 86 int32_t UMountDfsDocs(int32_t userId, const std::string &relativePath, 87 const std::string &networkId, const std::string &deviceId); 88 private: 89 sptr<OHOS::StorageDaemon::IStorageDaemon> storageDaemon_; 90 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 91 std::mutex mutex_; 92 }; 93 94 class SdDeathRecipient : public IRemoteObject::DeathRecipient { 95 public: 96 SdDeathRecipient() = default; 97 virtual ~SdDeathRecipient() = default; 98 99 virtual void OnRemoteDied(const wptr<IRemoteObject> &object); 100 }; 101 } // StorageManager 102 } // OHOS 103 104 #endif