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_USER_MANAGER_H 17 #define OHOS_STORAGE_DAEMON_USER_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 #include <mutex> 22 #include <sys/types.h> 23 #include <nocopyable.h> 24 #include "user/mount_manager.h" 25 #include "utils/file_utils.h" 26 27 namespace OHOS { 28 namespace StorageDaemon { 29 class UserManager final { 30 public: 31 UserManager(); 32 virtual ~UserManager() = default; 33 static std::shared_ptr<UserManager> GetInstance(); 34 int32_t CheckCrypto(int32_t userId, uint32_t flags); 35 int32_t PrepareUserDirs(int32_t userId, uint32_t flags); 36 int32_t DestroyUserDirs(int32_t userId, uint32_t flags); 37 int32_t StartUser(int32_t userId); 38 int32_t StopUser(int32_t userId); 39 void CreateBundleDataDir(uint32_t userId); 40 41 private: 42 int32_t PrepareDirsFromIdAndLevel(int32_t userId, const std::string &level); 43 int32_t DestroyDirsFromIdAndLevel(int32_t userId, const std::string &level); 44 int32_t PrepareEl1BundleDir(int32_t userId); 45 int32_t DestroyEl1BundleDir(int32_t userId); 46 int32_t PrepareEl2BackupDir(int32_t userId); 47 int32_t DestroyEl2BackupDir(int32_t userId); 48 int32_t PrepareEl1Dir(int32_t userId); 49 int32_t DestroyEl1Dir(int32_t userId); 50 int32_t SetElDirFscryptPolicy(int32_t userId, const std::string &level, 51 const std::vector<FileList> &list); 52 int32_t CheckUserIdRange(int32_t userId); 53 54 DISALLOW_COPY_AND_MOVE(UserManager); 55 56 static std::shared_ptr<UserManager> instance_; 57 const std::vector<DirInfo> rootDirVec_; 58 const std::vector<DirInfo> el3DirEl4DirEl5DirVec_; 59 const std::vector<DirInfo> subDirVec_; 60 const std::vector<DirInfo> el2DirVec_; 61 const std::vector<DirInfo> el1DirVec_; 62 const std::string bundle_ = "/data/app/el1/bundle/%d"; 63 std::mutex mutex_; 64 }; 65 } // STORAGE_DAEMON 66 } // OHOS 67 68 #endif // OHOS_STORAGE_DAEMON_USER_MANAGER_H