1 /* 2 * Copyright (c) 2021-2022 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_HOST_IMPL_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_HOST_IMPL_H 18 19 #include "ipc/installd_host.h" 20 #include "installd/installd_operator.h" 21 22 namespace OHOS { 23 namespace AppExecFwk { 24 class InstalldHostImpl : public InstalldHost { 25 public: 26 InstalldHostImpl(); 27 virtual ~InstalldHostImpl(); 28 /** 29 * @brief Create a bundle code directory. 30 * @param bundleDir Indicates the bundle code directory path that to be created. 31 * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise. 32 */ 33 virtual ErrCode CreateBundleDir(const std::string &bundleDir) override; 34 /** 35 * @brief Extract the files of a HAP module to the code directory. 36 * @param srcModulePath Indicates the HAP file path. 37 * @param targetPath normal files decompression path. 38 * @param targetSoPath so files decompression path. 39 * @param cpuAbi cpuAbi. 40 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 41 */ 42 virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath, 43 const std::string &targetSoPath, const std::string &cpuAbi) override; 44 /** 45 * @brief Rename the module directory from temporaily path to the real path. 46 * @param oldPath Indicates the old path name. 47 * @param newPath Indicates the new path name. 48 * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise. 49 */ 50 virtual ErrCode RenameModuleDir(const std::string &oldPath, const std::string &newPath) override; 51 /** 52 * @brief Create a bundle data directory. 53 * @param bundleDataDir Indicates the bundle data directory path that to be created. 54 * @param userid Indicates userid to be set to the directory. 55 * @param uid Indicates uid to be set to the directory. 56 * @param gid Indicates gid to be set to the directory. 57 * @param apl Indicates apl to be set to the directory. 58 * @param onlyOneUser Indicates is only one user or not. 59 * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise. 60 */ 61 virtual ErrCode CreateBundleDataDir(const std::string &bundleDataDir, const int userid, 62 const int uid, const int gid, const std::string &apl, bool onlyOneUser = true) override; 63 /** 64 * @brief Remove a bundle data directory. 65 * @param bundleName Indicates the bundleName data directory path that to be created. 66 * @param userid Indicates userid to be set to the directory. 67 * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise. 68 */ 69 virtual ErrCode RemoveBundleDataDir( 70 const std::string &bundleName, const int userid) override; 71 /** 72 * @brief Create a module and it's abilities data directory. 73 * @param bundleDir Indicates the module data directory path that to be created. 74 * @param abilityDirs Indicates the abilities data directory name that to be created. 75 * @param uid Indicates uid to be set to the directory. 76 * @param gid Indicates gid to be set to the directory. 77 * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise. 78 */ 79 virtual ErrCode CreateModuleDataDir(const std::string &ModuleDir, const std::vector<std::string> &abilityDirs, 80 const int uid, const int gid) override; 81 /** 82 * @brief Remove a module data directory. 83 * @param ModuleDir Indicates the module data directory path that to be created. 84 * @param userid Indicates userid to be set to the directory. 85 * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise. 86 */ 87 virtual ErrCode RemoveModuleDataDir(const std::string &ModuleDir, const int userid) override; 88 /** 89 * @brief Remove a directory. 90 * @param dir Indicates the directory path that to be removed. 91 * @return Returns ERR_OK if the directory removed successfully; returns error code otherwise. 92 */ 93 virtual ErrCode RemoveDir(const std::string &dir) override; 94 /** 95 * @brief Clean all files in a bundle data directory. 96 * @param bundleDir Indicates the data directory path that to be cleaned. 97 * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise. 98 */ 99 virtual ErrCode CleanBundleDataDir(const std::string &bundleDir) override; 100 /** 101 * @brief Get bundle Stats. 102 * @param bundleName Indicates the bundle name. 103 * @param userId Indicates the user Id. 104 * @param bundleStats Indicates the bundle Stats. 105 * @return Returns ERR_OK if get stats successfully; returns error code otherwise. 106 */ 107 virtual ErrCode GetBundleStats( 108 const std::string &bundleName, const int32_t userId, std::vector<int64_t> &bundleStats) override; 109 /** 110 * @brief Set dir apl. 111 * @param dir Indicates the data dir. 112 * @param bundleName Indicates the bundle name. 113 * @param apl Indicates the apl type. 114 * @return Returns ERR_OK if set apl successfully; returns error code otherwise. 115 */ 116 virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl) override; 117 /** 118 * @brief Get all cache file path. 119 * @param dir Indicates the data dir. 120 * @param cachesPath Indicates the cache file path. 121 * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise. 122 */ 123 virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) override; 124 125 private: 126 std::string GetBundleDataDir(const std::string &el, const int userid) const; 127 ErrCode CreateNewBundleDataDir(const std::string &bundleName, const int userid, const int uid, const int gid, 128 const std::string &apl); 129 }; 130 } // namespace AppExecFwk 131 } // namespace OHOS 132 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_HOST_IMPL_H