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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_CLIENT_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_CLIENT_H 18 19 #include <memory> 20 #include <mutex> 21 #include <string> 22 23 #include "nocopyable.h" 24 #include "singleton.h" 25 26 #include "appexecfwk_errors.h" 27 #include "ipc/installd_interface.h" 28 29 namespace OHOS { 30 namespace AppExecFwk { 31 32 class InstalldClient : public DelayedSingleton<InstalldClient> { 33 public: 34 /** 35 * @brief Create a bundle code directory through an installd proxy object. 36 * @param bundleDir Indicates the bundle code directory path that to be created. 37 * @return Returns ERR_OK if the bundle directory created successfully; returns error code otherwise. 38 */ 39 ErrCode CreateBundleDir(const std::string &bundleDir); 40 /** 41 * @brief Remove a bundle code directory. 42 * @param bundleDir Indicates the bundle code directory path that to be removed. 43 * @return Returns ERR_OK if the bundle directory removed successfully; returns error code otherwise. 44 */ 45 ErrCode RemoveBundleDir(const std::string &bundleDir); 46 /** 47 * @brief Remove a bundle data directory. 48 * @param bundleDir Indicates the bundle data directory path that to be removed. 49 * @return Returns ERR_OK if the bundle data directory removed successfully; returns error code otherwise. 50 */ 51 ErrCode RemoveBundleDataDir(const std::string &bundleDataDir); 52 /** 53 * @brief Extract the files of a HAP module to the code directory. 54 * @param srcModulePath Indicates the HAP file path. 55 * @param targetPath Indicates the code directory path that the HAP to be extracted to. 56 * @return Returns ERR_OK if the HAP file extracted successfully; returns error code otherwise. 57 */ 58 ErrCode ExtractModuleFiles(const std::string &srcModulePath, const std::string &targetPath); 59 /** 60 * @brief Remove a module directory. 61 * @param moduleDir Indicates the module directory to be removed. 62 * @return Returns ERR_OK if the module directory removed successfully; returns error code otherwise. 63 */ 64 ErrCode RemoveModuleDir(const std::string &moduleDir); 65 /** 66 * @brief Rename the module directory from temporaily path to the real path. 67 * @param oldPath Indicates the old path name. 68 * @param newPath Indicates the new path name. 69 * @return Returns ERR_OK if the module directory renamed successfully; returns error code otherwise. 70 */ 71 ErrCode RenameModuleDir(const std::string &oldPath, const std::string &newPath); 72 /** 73 * @brief Create a bundle data directory. 74 * @param bundleDir Indicates the bundle data directory path 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 bundle data directory created successfully; returns error code otherwise. 78 */ 79 ErrCode CreateBundleDataDir(const std::string &bundleDir, const int uid, const int gid); 80 /** 81 * @brief Create a module and it's abilities data directory. 82 * @param bundleDir Indicates the module data directory path that to be created. 83 * @param abilityDirs Indicates the abilities data directory name that to be created. 84 * @param uid Indicates uid to be set to the directory. 85 * @param gid Indicates gid to be set to the directory. 86 * @return Returns ERR_OK if the data directories created successfully; returns error code otherwise. 87 */ 88 ErrCode CreateModuleDataDir( 89 const std::string &ModuleDir, const std::vector<std::string> &abilityDirs, const int uid, const int gid); 90 /** 91 * @brief Remove a module data directory. 92 * @param bundleDir Indicates the module data directory path that to be removed. 93 * @return Returns ERR_OK if the module data directory removed successfully; returns error code otherwise. 94 */ 95 ErrCode RemoveModuleDataDir(const std::string &moduleDataDir); 96 /** 97 * @brief Clean all files in a bundle data directory. 98 * @param bundleDir Indicates the data directory path that to be cleaned. 99 * @return Returns ERR_OK if the data directory cleaned successfully; returns error code otherwise. 100 */ 101 ErrCode CleanBundleDataDir(const std::string &bundleDir); 102 /** 103 * @brief Reset the installd proxy object when installd service died. 104 * @return 105 */ 106 void ResetInstalldProxy(); 107 108 private: 109 /** 110 * @brief Get the installd proxy object. 111 * @return Returns true if the installd proxy object got successfully; returns false otherwise. 112 */ 113 bool GetInstalldProxy(); 114 115 private: 116 std::mutex mutex_; 117 sptr<IInstalld> installdProxy_; 118 sptr<IRemoteObject::DeathRecipient> recipient_; 119 }; 120 121 } // namespace AppExecFwk 122 } // namespace OHOS 123 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALLD_CLIENT_H