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_IPC_INSTALLD_INTERFACE_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_INTERFACE_H 18 19 #include <string> 20 #include <vector> 21 22 #include "iremote_broker.h" 23 24 #include "aot/aot_args.h" 25 #include "appexecfwk_errors.h" 26 #include "ipc/create_dir_param.h" 27 #include "ipc/extract_param.h" 28 #include "ipc/file_stat.h" 29 #include "installd/installd_constants.h" 30 31 namespace OHOS { 32 namespace AppExecFwk { 33 class IInstalld : public IRemoteBroker { 34 public: 35 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.Installd"); 36 /** 37 * @brief Create a bundle code directory. 38 * @param bundleDir Indicates the bundle code directory path that to be created. 39 * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise. 40 */ CreateBundleDir(const std::string & bundleDir)41 virtual ErrCode CreateBundleDir(const std::string &bundleDir) 42 { 43 return ERR_OK; 44 } 45 /** 46 * @brief Extract the files of a HAP module to the code directory. 47 * @param srcModulePath Indicates the HAP file path. 48 * @param targetPath normal files decompression path. 49 * @param targetSoPath so files decompression path. 50 * @param cpuAbi cpuAbi. 51 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 52 */ ExtractModuleFiles(const std::string & srcModulePath,const std::string & targetPath,const std::string & targetSoPath,const std::string & cpuAbi)53 virtual ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath, 54 const std::string &targetSoPath, const std::string &cpuAbi) 55 { 56 return ERR_OK; 57 } 58 /** 59 * @brief Extract the files. 60 * @param extractParam Indicates the extractParam. 61 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 62 */ ExtractFiles(const ExtractParam & extractParam)63 virtual ErrCode ExtractFiles(const ExtractParam &extractParam) 64 { 65 return ERR_OK; 66 } 67 ExecuteAOT(const AOTArgs & aotArgs)68 virtual ErrCode ExecuteAOT(const AOTArgs &aotArgs) 69 { 70 return ERR_APPEXECFWK_INSTALLD_AOT_EXECUTE_FAILED; 71 } 72 /** 73 * @brief Rename the module directory from temporaily path to the real path. 74 * @param oldPath Indicates the old path name. 75 * @param newPath Indicates the new path name. 76 * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise. 77 */ RenameModuleDir(const std::string & oldDir,const std::string & newDir)78 virtual ErrCode RenameModuleDir(const std::string &oldDir, const std::string &newDir) 79 { 80 return ERR_OK; 81 } 82 /** 83 * @brief Create a bundle data directory. 84 * @param createDirParam Indicates param to be set to the directory. 85 * @return Returns ERR_OK if the bundle data directory created successfully; returns error code otherwise. 86 */ CreateBundleDataDir(const CreateDirParam & createDirParam)87 virtual ErrCode CreateBundleDataDir(const CreateDirParam &createDirParam) 88 { 89 return ERR_OK; 90 } 91 /** 92 * @brief Remove a bundle data directory. 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 */ RemoveBundleDataDir(const std::string & bundleDir,const int userid)97 virtual ErrCode RemoveBundleDataDir(const std::string &bundleDir, const int userid) 98 { 99 return ERR_OK; 100 } 101 /** 102 * @brief Remove a module and it's abilities data directory. 103 * @param ModuleDir Indicates the module data directory path that to be created. 104 * @param userid Indicates userid to be set to the directory. 105 * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise. 106 */ RemoveModuleDataDir(const std::string & ModuleDir,const int userid)107 virtual ErrCode RemoveModuleDataDir(const std::string &ModuleDir, const int userid) 108 { 109 return ERR_OK; 110 } 111 /** 112 * @brief Remove a directory. 113 * @param dir Indicates the directory path that to be removed. 114 * @return Returns ERR_OK if the directory removed successfully; returns error code otherwise. 115 */ RemoveDir(const std::string & dir)116 virtual ErrCode RemoveDir(const std::string &dir) 117 { 118 return ERR_OK; 119 } 120 /** 121 * @brief Clean all files in a bundle data directory. 122 * @param bundleDir Indicates the data directory path that to be cleaned. 123 * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise. 124 */ CleanBundleDataDir(const std::string & bundleDir)125 virtual ErrCode CleanBundleDataDir(const std::string &bundleDir) 126 { 127 return ERR_OK; 128 } 129 /** 130 * @brief Get bundle Stats. 131 * @param bundleName Indicates the bundle name. 132 * @param userId Indicates the user Id. 133 * @param bundleStats Indicates the bundle Stats. 134 * @return Returns ERR_OK if get stats successfully; returns error code otherwise. 135 */ GetBundleStats(const std::string & bundleName,const int32_t userId,std::vector<int64_t> & bundleStats)136 virtual ErrCode GetBundleStats( 137 const std::string &bundleName, const int32_t userId, std::vector<int64_t> &bundleStats) 138 { 139 return ERR_OK; 140 } 141 /** 142 * @brief Set dir apl. 143 * @param dir Indicates the data dir. 144 * @param bundleName Indicates the bundle name. 145 * @param apl Indicates the apl type. 146 * @param isPreInstallApp Indicates the bundle install type. 147 * @param debug Indicates the bundle debug mode. 148 * @return Returns ERR_OK if set apl successfully; returns error code otherwise. 149 */ SetDirApl(const std::string & dir,const std::string & bundleName,const std::string & apl,bool isPreInstallApp,bool debug)150 virtual ErrCode SetDirApl(const std::string &dir, const std::string &bundleName, const std::string &apl, 151 bool isPreInstallApp, bool debug) 152 { 153 return ERR_OK; 154 } 155 /** 156 * @brief Get all cache file path. 157 * @param dir Indicates the data dir. 158 * @param cachesPath Indicates the cache file path. 159 * @return Returns ERR_OK if get cache file path successfully; returns error code otherwise. 160 */ GetBundleCachePath(const std::string & dir,std::vector<std::string> & cachePath)161 virtual ErrCode GetBundleCachePath(const std::string &dir, std::vector<std::string> &cachePath) 162 { 163 return ERR_OK; 164 } 165 /** 166 * @brief Scan dir by scanMode and resultMode. this interface has higher permissions to scan. 167 * @param dir Indicates the directory to be scanned. 168 * @param scanMode Indicates the scan mode. 169 * Scan all subfiles and subfolders in the directory in SUB_FILE_ALL mode 170 * Scan all subfolders in the directory in SUB_FILE_DIR mode 171 * Scan all subfiles in the directory in SUB_FILE_FILE mode 172 * @param resultMode Indicates the result mode. 173 * Get absolute path in ABSOLUTE_PATH mode 174 * Get relative path in RELATIVE_PATH mode 175 * @return Returns ERR_OK if scan dir successfully; returns error code otherwise. 176 */ ScanDir(const std::string & dir,ScanMode scanMode,ResultMode resultMode,std::vector<std::string> & paths)177 virtual ErrCode ScanDir( 178 const std::string &dir, ScanMode scanMode, ResultMode resultMode, std::vector<std::string> &paths) 179 { 180 return ERR_OK; 181 } 182 183 /** 184 * @brief Move file from oldPath to newPath. 185 * @param oldPath Indicates oldPath. 186 * @param newPath Indicates newPath. 187 * @return Returns ERR_OK if move file successfully; returns error code otherwise. 188 */ MoveFile(const std::string & oldPath,const std::string & newPath)189 virtual ErrCode MoveFile(const std::string &oldPath, const std::string &newPath) 190 { 191 return ERR_OK; 192 } 193 194 /** 195 * @brief Copy file from oldPath to newPath. 196 * @param oldPath Indicates oldPath. 197 * @param newPath Indicates newPath. 198 * @return Returns ERR_OK if copy file successfully; returns error code otherwise. 199 */ CopyFile(const std::string & oldPath,const std::string & newPath,const std::string & signatureFilePath)200 virtual ErrCode CopyFile(const std::string &oldPath, const std::string &newPath, 201 const std::string &signatureFilePath) 202 { 203 return ERR_OK; 204 } 205 206 /** 207 * @brief Create directory recursively. 208 * @param dir Indicates dir which will be created. 209 * @param mode Indicates dir mode. 210 * @param uid Indicates dir uid. 211 * @param gid Indicates dir gid. 212 * @return Returns ERR_OK if create directory successfully; returns error code otherwise. 213 */ Mkdir(const std::string & dir,const int32_t mode,const int32_t uid,const int32_t gid)214 virtual ErrCode Mkdir( 215 const std::string &dir, const int32_t mode, const int32_t uid, const int32_t gid) 216 { 217 return ERR_OK; 218 } 219 220 /** 221 * @brief Get file stat. 222 * @param file Indicates file. 223 * @param fileStat Indicates fileStat. 224 * @return Returns ERR_OK if get file stat successfully; returns error code otherwise. 225 */ GetFileStat(const std::string & file,FileStat & fileStat)226 virtual ErrCode GetFileStat(const std::string &file, FileStat &fileStat) 227 { 228 return ERR_OK; 229 } 230 ExtractDiffFiles(const std::string & filePath,const std::string & targetPath,const std::string & cpuAbi)231 virtual ErrCode ExtractDiffFiles(const std::string &filePath, const std::string &targetPath, 232 const std::string &cpuAbi) 233 { 234 return ERR_OK; 235 } 236 ApplyDiffPatch(const std::string & oldSoPath,const std::string & diffFilePath,const std::string & newSoPath)237 virtual ErrCode ApplyDiffPatch(const std::string &oldSoPath, const std::string &diffFilePath, 238 const std::string &newSoPath) 239 { 240 return ERR_OK; 241 } 242 IsExistDir(const std::string & dir,bool & isExist)243 virtual ErrCode IsExistDir(const std::string &dir, bool &isExist) 244 { 245 return ERR_OK; 246 } 247 IsExistFile(const std::string & path,bool & isExist)248 virtual ErrCode IsExistFile(const std::string &path, bool &isExist) 249 { 250 return ERR_OK; 251 } 252 IsDirEmpty(const std::string & dir,bool & isDirEmpty)253 virtual ErrCode IsDirEmpty(const std::string &dir, bool &isDirEmpty) 254 { 255 return ERR_OK; 256 } 257 ObtainQuickFixFileDir(const std::string & dir,std::vector<std::string> & dirVec)258 virtual ErrCode ObtainQuickFixFileDir(const std::string &dir, std::vector<std::string> &dirVec) 259 { 260 return ERR_OK; 261 } 262 CopyFiles(const std::string & sourceDir,const std::string & destinationDir)263 virtual ErrCode CopyFiles(const std::string &sourceDir, const std::string &destinationDir) 264 { 265 return ERR_OK; 266 } 267 GetNativeLibraryFileNames(const std::string & filePath,const std::string & cpuAbi,std::vector<std::string> & fileNames)268 virtual ErrCode GetNativeLibraryFileNames(const std::string &filePath, const std::string &cpuAbi, 269 std::vector<std::string> &fileNames) 270 { 271 return ERR_OK; 272 } 273 VerifyCodeSignature(const std::string & modulePath,const std::string & cpuAbi,const std::string & targetSoPath,const std::string & signatureFileDir)274 virtual ErrCode VerifyCodeSignature(const std::string &modulePath, const std::string &cpuAbi, 275 const std::string &targetSoPath, const std::string &signatureFileDir) 276 { 277 return ERR_OK; 278 } 279 MoveFiles(const std::string & srcDir,const std::string & desDir)280 virtual ErrCode MoveFiles(const std::string &srcDir, const std::string &desDir) 281 { 282 return ERR_OK; 283 } 284 }; 285 286 #define INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(parcel, token) \ 287 do { \ 288 bool ret = parcel.WriteInterfaceToken((token)); \ 289 if (!ret) { \ 290 APP_LOGE("fail to write interface token into the parcel!"); \ 291 return ERR_APPEXECFWK_PARCEL_ERROR; \ 292 } \ 293 } while (0) 294 295 #define INSTALLD_PARCEL_WRITE(parcel, type, value) \ 296 do { \ 297 bool ret = parcel.Write##type((value)); \ 298 if (!ret) { \ 299 APP_LOGE("fail to write parameter into the parcel!"); \ 300 return ERR_APPEXECFWK_PARCEL_ERROR; \ 301 } \ 302 } while (0) 303 } // namespace AppExecFwk 304 } // namespace OHOS 305 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_INTERFACE_H