1 /* 2 * Copyright (c) 2021-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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_PROXY_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_PROXY_H 18 19 #include <string> 20 21 #include "appexecfwk_errors.h" 22 #include "bundle_constants.h" 23 #include "bundle_framework_services_ipc_interface_code.h" 24 #include "iremote_proxy.h" 25 #include "ipc/installd_interface.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class InstalldProxy : public IRemoteProxy<IInstalld> { 30 public: 31 explicit InstalldProxy(const sptr<IRemoteObject> &object); 32 virtual ~InstalldProxy() override; 33 /** 34 * @brief Create a bundle code directory through a proxy object. 35 * @param bundleDir Indicates the bundle code directory path that to be created. 36 * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise. 37 */ 38 virtual ErrCode CreateBundleDir(const std::string &bundlePath) override; 39 /** 40 * @brief Extract the files of a HAP module to the code directory through a proxy object. 41 * @param srcModulePath Indicates the HAP file path. 42 * @param targetPath normal files decompression path. 43 * @param targetSoPath so files decompression path. 44 * @param cpuAbi cpuAbi. 45 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 46 */ 47 virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath, 48 const std::string &targetSoPath, const std::string &cpuAbi) override; 49 /** 50 * @brief Extract the files. 51 * @param extractParam Indicates the extractParam. 52 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 53 */ 54 virtual ErrCode ExtractFiles(const ExtractParam &extractParam) override; 55 56 /** 57 * @brief Extract the hnpFiles. 58 * @param hnpPackageInfo Indicates the hnpPackageInfo. 59 * @param extractParam Indicates the extractParam. 60 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 61 */ 62 virtual ErrCode ExtractHnpFiles(const std::string &hnpPackageInfo, const ExtractParam &extractParam) override; 63 64 virtual ErrCode ProcessBundleInstallNative(const std::string &userId, const std::string &hnpRootPath, 65 const std::string &hapPath, const std::string &cpuAbi, const std::string &packageName) override; 66 67 virtual ErrCode ProcessBundleUnInstallNative(const std::string &userId, const std::string &bundleName) override; 68 69 virtual ErrCode ExecuteAOT(const AOTArgs &aotArgs, std::vector<uint8_t> &pendSignData) override; 70 71 virtual ErrCode PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData) override; 72 73 virtual ErrCode StopAOT() override; 74 75 virtual ErrCode DeleteUninstallTmpDirs(const std::vector<std::string> &dirs) override; 76 /** 77 * @brief Rename the module directory from temporaily path to the real path through a proxy object. 78 * @param oldPath Indicates the old path name. 79 * @param newPath Indicates the new path name. 80 * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise. 81 */ 82 virtual ErrCode RenameModuleDir(const std::string &oldPath, const std::string &newPath) override; 83 /** 84 * @brief Create a bundle data directory through a proxy object. 85 * @param createDirParam Indicates param to be set to the directory. 86 * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise. 87 */ 88 virtual ErrCode CreateBundleDataDir(const CreateDirParam &createDirPara) override; 89 90 virtual ErrCode CreateBundleDataDirWithVector(const std::vector<CreateDirParam> &createDirParams) override; 91 /** 92 * @brief Remove a bundle data directory through a proxy object. 93 * @param bundleDir Indicates the bundle data directory path that to be created. 94 * @param userid Indicates userid to be set to the directory. 95 * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise. 96 */ 97 virtual ErrCode RemoveBundleDataDir(const std::string &bundleDir, const int32_t userId, 98 bool isAtomicService = false, const bool async = false) override; 99 /** 100 * @brief Remove a module data directory through a proxy object. 101 * @param ModuleDir Indicates the module data directory path that to be created. 102 * @param userid Indicates userid to be set to the directory. 103 * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise. 104 */ 105 virtual ErrCode RemoveModuleDataDir(const std::string &ModuleDir, const int userid) override; 106 /** 107 * @brief Remove a directory through a proxy object. 108 * @param dir Indicates the directory path that to be removed. 109 * @return Returns ERR_OK if the directory removed successfully; returns error code otherwise. 110 */ 111 virtual ErrCode RemoveDir(const std::string &dir) override; 112 /** 113 * @brief Get disk usage for dir. 114 * @param dir Indicates the directory. 115 * @param isRealPath Indicates isRealPath. 116 * @param statSize Indicates size of dir. 117 * @return Returns true if successfully; returns false otherwise. 118 */ 119 virtual ErrCode GetDiskUsage(const std::string &dir, int64_t &statSize, bool isRealPath = false) override; 120 /** 121 * @brief Get disk usage for dir. 122 * @param path Indicates the directory vector. 123 * @param statSize Indicates size of path. 124 * @return Returns true if successfully; returns false otherwise. 125 */ 126 virtual ErrCode GetDiskUsageFromPath(const std::vector<std::string> &path, int64_t &statSize) override; 127 /** 128 * @brief Clean all files in a bundle data directory through a proxy object. 129 * @param bundleDir Indicates the data directory path that to be cleaned. 130 * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise. 131 */ 132 virtual ErrCode CleanBundleDataDir(const std::string &bundlePath) override; 133 /** 134 * @brief Clean a bundle data directory through a proxy object. 135 * @param bundleName Indicates the bundleName data directory path that to be cleaned. 136 * @param userid Indicates userid to be set to the directory. 137 * @param appIndex Indicates app index to be set to the directory. 138 * @return Returns ERR_OK if the bundle data directory cleaned successfully; returns error code otherwise. 139 */ 140 virtual ErrCode CleanBundleDataDirByName(const std::string &bundleName, const int userid, 141 const int appIndex = 0) override; 142 /** 143 * @brief Get bundle Stats. 144 * @param bundleName Indicates the bundle name. 145 * @param userId Indicates the user Id. 146 * @param bundleStats Indicates the bundle Stats. 147 * @return Returns ERR_OK if get stats successfully; returns error code otherwise. 148 */ 149 virtual ErrCode GetBundleStats(const std::string &bundleName, const int32_t userId, 150 std::vector<int64_t> &bundleStats, const int32_t uid = Constants::INVALID_UID, 151 const int32_t appIndex = 0, const uint32_t statFlag = 0, 152 const std::vector<std::string> &moduleNameList = {}) override; 153 154 virtual ErrCode BatchGetBundleStats(const std::vector<std::string> &bundleNames, const int32_t userId, 155 const std::unordered_map<std::string, int32_t> &uidMap, 156 std::vector<BundleStorageStats> &bundleStats) override; 157 158 virtual ErrCode GetAllBundleStats(const int32_t userId, 159 std::vector<int64_t> &bundleStats, const std::vector<int32_t> &uids) override; 160 /** 161 * @brief Set dir apl. 162 * @param dir Indicates the data dir. 163 * @param bundleName Indicates the bundle name. 164 * @param apl Indicates the apl type. 165 * @param isPreInstallApp Indicates the bundle install type. 166 * @param debug Indicates the bundle debug mode. 167 * @param uid Indicates the uid. 168 * @return Returns ERR_OK if set apl successfully; returns error code otherwise. 169 */ 170 virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl, 171 bool isPreInstallApp, bool debug, int32_t uid) override; 172 173 /** 174 * @brief Set dir apl. 175 * @param dir Indicates the data dir. 176 * @return Returns ERR_OK if set apl successfully; returns error code otherwise. 177 */ 178 virtual ErrCode SetArkStartupCacheApl(const std::string &dir) override; 179 180 /** 181 * @brief Get all cache file path. 182 * @param dir Indicates the data dir. 183 * @param cachesPath Indicates the cache file path. 184 * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise. 185 */ 186 virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) override; 187 188 virtual ErrCode ScanDir( 189 const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths) override; 190 191 virtual ErrCode MoveFile(const std::string &oldPath, const std::string &newPath) override; 192 193 virtual ErrCode CopyFile(const std::string &oldPath, const std::string &newPath, 194 const std::string &signatureFilePath = "") override; 195 196 virtual ErrCode Mkdir( 197 const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid) override; 198 199 virtual ErrCode GetFileStat(const std::string &file, FileStat &fileStat) override; 200 201 virtual ErrCode ChangeFileStat(const std::string &file, FileStat &fileStat) override; 202 203 virtual ErrCode ExtractDiffFiles(const std::string &filePath, const std::string &targetPath, 204 const std::string &cpuAbi) override; 205 206 virtual ErrCode ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath, 207 const std::string &newSoPath, int32_t uid) override; 208 209 virtual ErrCode IsExistDir(const std::string &dir, bool &isExist) override; 210 211 virtual ErrCode IsExistFile(const std::string &path, bool &isExist) override; 212 213 virtual ErrCode IsExistApFile(const std::string &path, bool &isExist) override; 214 215 virtual ErrCode IsDirEmpty(const std::string &dir, bool &isDirEmpty) override; 216 217 virtual ErrCode ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec) override; 218 219 virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) override; 220 221 virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, 222 std::vector<std::string> &fileNames) override; 223 224 virtual ErrCode VerifyCodeSignature(const CodeSignatureParam &codeSignatureParam) override; 225 226 virtual ErrCode CheckEncryption(const CheckEncryptionParam &checkEncryptionParam, 227 bool &isEncryption) override; 228 229 virtual ErrCode MoveFiles(const std::string &srcDir, const std::string &desDir) override; 230 231 virtual ErrCode ExtractDriverSoFiles(const std::string &srcPath, 232 const std::unordered_multimap<std::string, std::string> &dirMap) override; 233 234 virtual ErrCode ExtractEncryptedSoFiles(const std::string &hapPath, const std::string &realSoFilesPath, 235 const std::string &cpuAbi, const std::string &tmpSoPath, int32_t uid) override; 236 237 virtual ErrCode VerifyCodeSignatureForHap(const CodeSignatureParam &codeSignatureParam) override; 238 239 virtual ErrCode DeliverySignProfile(const std::string &bundleName, int32_t profileBlockLength, 240 const unsigned char *profileBlock) override; 241 242 virtual ErrCode RemoveSignProfile(const std::string &bundleName) override; 243 244 virtual ErrCode SetEncryptionPolicy(const EncryptionParam &encryptionParam, std::string &keyId) override; 245 246 virtual ErrCode DeleteEncryptionKeyId(const EncryptionParam &encryptionParam) override; 247 248 virtual ErrCode RemoveExtensionDir(int32_t userId, const std::vector<std::string> &extensionBundleDirs) override; 249 250 virtual ErrCode IsExistExtensionDir(int32_t userId, const std::string &extensionBundleDir, bool &isExist) override; 251 252 virtual ErrCode CreateExtensionDataDir(const CreateDirParam &createDirParam) override; 253 254 virtual ErrCode GetExtensionSandboxTypeList(std::vector<std::string> &typeList) override; 255 256 virtual ErrCode MigrateData( 257 const std::vector<std::string> &sourcePaths, const std::string &destinationPath) override; 258 259 virtual ErrCode AddUserDirDeleteDfx(int32_t userId) override; 260 261 virtual ErrCode MoveHapToCodeDir(const std::string &originPath, const std::string &targetPath) override; 262 263 virtual ErrCode CreateDataGroupDirs(const std::vector<CreateDirParam> ¶ms) override; 264 265 virtual ErrCode DeleteDataGroupDirs(const std::vector<std::string> &uuidList, int32_t userId) override; 266 267 virtual ErrCode LoadInstalls() override; 268 269 virtual ErrCode ClearDir(const std::string &dir) override; 270 271 virtual ErrCode RestoreconPath(const std::string &path) override; 272 private: 273 ErrCode TransactInstalldCmd(InstalldInterfaceCode code, MessageParcel &data, MessageParcel &reply, 274 MessageOption &option); 275 static inline BrokerDelegator<InstalldProxy> delegator_; 276 }; 277 } // namespace AppExecFwk 278 } // namespace OHOS 279 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_PROXY_H