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_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H 18 19 #include <vector> 20 21 #include "bundle_stream_installer_interface.h" 22 #include "clone_param.h" 23 #include "status_receiver_interface.h" 24 #include "install_param.h" 25 #include "plugin/install_plugin_param.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class IBundleInstaller : public IRemoteBroker { 30 public: 31 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.BundleInstaller"); 32 /** 33 * @brief Installs an application, the final result will be notified from the statusReceiver object. 34 * @attention Notice that the bundleFilePath should be an absolute path. 35 * @param bundleFilePath Indicates the path for storing the ohos Ability Package (HAP) of the application 36 * to install or update. 37 * @param installParam Indicates the install parameters. 38 * @param statusReceiver Indicates the callback object that using for notifing the install result. 39 * @return Returns true if this function is successfully called; returns false otherwise. 40 */ 41 virtual bool Install(const std::string &bundleFilePath, const InstallParam &installParam, 42 const sptr<IStatusReceiver> &statusReceiver) = 0; 43 /** 44 * @brief Installs an application by bundleName, the final result will be notified from the statusReceiver object. 45 * @param bundleName Indicates the bundleName of the application to install. 46 * @param installParam Indicates the install parameters. 47 * @param statusReceiver Indicates the callback object that using for notifing the install result. 48 * @return Returns true if this function is successfully called; returns false otherwise. 49 */ 50 virtual bool Recover(const std::string &bundleName, const InstallParam &installParam, 51 const sptr<IStatusReceiver> &statusReceiver) = 0; 52 53 /** 54 * @brief Installs multiple haps, the final result will be notified from the statusReceiver object. 55 * @attention Notice that the bundleFilePath should be an string vector of absolute paths. 56 * @param bundleFilePaths Indicates the paths for storing the ohos Ability Packages (HAP) of the application 57 * to install or update. 58 * @param installParam Indicates the install parameters. 59 * @param statusReceiver Indicates the callback object that using for notifing the install result. 60 * @return Returns true if this function is successfully called; returns false otherwise. 61 */ 62 virtual bool Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 63 const sptr<IStatusReceiver> &statusReceiver) = 0; 64 65 /** 66 * @brief Uninstalls an application, the result will be notified from the statusReceiver object. 67 * @param bundleName Indicates the bundle name of the application to uninstall. 68 * @param installParam Indicates the uninstall parameters. 69 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 70 * @return Returns true if this function is successfully called; returns false otherwise. 71 */ 72 virtual bool Uninstall(const std::string &bundleName, const InstallParam &installParam, 73 const sptr<IStatusReceiver> &statusReceiver) = 0; 74 75 virtual bool Uninstall(const UninstallParam &uninstallParam, 76 const sptr<IStatusReceiver> &statusReceiver) = 0; 77 /** 78 * @brief Uninstalls a module in an application, the result will be notified from the statusReceiver object. 79 * @param bundleName Indicates the bundle name of the module to uninstall. 80 * @param modulePackage Indicates the module package of the module to uninstall. 81 * @param installParam Indicates the uninstall parameters. 82 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 83 * @return Returns true if this function is successfully called; returns false otherwise. 84 */ 85 virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage, 86 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) = 0; 87 /** 88 * @brief Installs an app by bundleName, only used in preInstall app. 89 * @param bundleName Indicates the bundleName of the application to install. 90 * @param installParam Indicates the install parameters. 91 * @param statusReceiver Indicates the callback object that using for notifing the install result. 92 * @return Returns true if this function is successfully called; returns false otherwise. 93 */ InstallByBundleName(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)94 virtual bool InstallByBundleName(const std::string &bundleName, const InstallParam &installParam, 95 const sptr<IStatusReceiver> &statusReceiver) 96 { 97 return false; 98 } 99 100 /** 101 * @brief Install sandbox application. 102 * @param bundleName Indicates the bundle name of the sandbox application to be install. 103 * @param dlpType Indicates type of the sandbox application. 104 * @param userId Indicates the sandbox application will be installed under which user id. 105 * @param appIndex Indicates the appIndex of the sandbox application installed under which user id. 106 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 107 */ 108 virtual ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId, 109 int32_t &appIndex) = 0; 110 111 /** 112 * @brief Uninstall sandbox application. 113 * @param bundleName Indicates the bundle name of the sandbox application to be install. 114 * @param appIndex Indicates application index of the sandbox application. 115 * @param userId Indicates the sandbox application will be uninstall under which user id. 116 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 117 */ 118 virtual ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId) = 0; 119 120 /** 121 * @brief Install or update plugin application. 122 * @param hostBundleName Indicates the bundle name of the host application. 123 * @param pluginFilePath Indicates the paths for storing the HSP of the plugin to install or update. 124 * @param installPluginParam Indicates the install parameters. 125 * @return Returns ERR_OK if the plugin application is installed successfully; returns errcode otherwise. 126 */ InstallPlugin(const std::string & hostBundleName,const std::vector<std::string> & pluginFilePaths,const InstallPluginParam & installPluginParam)127 virtual ErrCode InstallPlugin(const std::string &hostBundleName, const std::vector<std::string> &pluginFilePaths, 128 const InstallPluginParam &installPluginParam) 129 { 130 return ERR_OK; 131 } 132 133 /** 134 * @brief uninstall plugin application. 135 * @param hostBundleName Indicates the bundle name of the host application. 136 * @param pluginBundleName Indicates the plugin bundle name to uninstall. 137 * @param installPluginParam Indicates the uninstall parameters. 138 * @return Returns ERR_OK if the plugin application is uninstalled successfully; returns errcode otherwise. 139 */ UninstallPlugin(const std::string & hostBundleName,const std::string & pluginBundleName,const InstallPluginParam & installPluginParam)140 virtual ErrCode UninstallPlugin(const std::string &hostBundleName, const std::string &pluginBundleName, 141 const InstallPluginParam &installPluginParam) 142 { 143 return ERR_OK; 144 } 145 146 virtual sptr<IBundleStreamInstaller> CreateStreamInstaller(const InstallParam &installParam, 147 const sptr<IStatusReceiver> &statusReceiver, const std::vector<std::string> &originHapPaths) = 0; 148 virtual bool DestoryBundleStreamInstaller(uint32_t streamInstallerId) = 0; 149 virtual ErrCode StreamInstall(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 150 const sptr<IStatusReceiver> &statusReceiver) = 0; 151 UpdateBundleForSelf(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)152 virtual bool UpdateBundleForSelf(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 153 const sptr<IStatusReceiver> &statusReceiver) 154 { 155 return true; 156 } 157 UninstallAndRecover(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)158 virtual bool UninstallAndRecover(const std::string &bundleName, const InstallParam &installParam, 159 const sptr<IStatusReceiver> &statusReceiver) 160 { 161 return true; 162 } 163 InstallCloneApp(const std::string & bundleName,int32_t userId,int32_t & appIndex)164 virtual ErrCode InstallCloneApp(const std::string &bundleName, int32_t userId, int32_t& appIndex) 165 { 166 return ERR_OK; 167 } 168 UninstallCloneApp(const std::string & bundleName,int32_t userId,int32_t appIndex,const DestroyAppCloneParam & destroyAppCloneParam)169 virtual ErrCode UninstallCloneApp(const std::string &bundleName, int32_t userId, int32_t appIndex, 170 const DestroyAppCloneParam &destroyAppCloneParam) 171 { 172 return ERR_OK; 173 } 174 InstallExisted(const std::string & bundleName,int32_t userId)175 virtual ErrCode InstallExisted(const std::string &bundleName, int32_t userId) 176 { 177 return ERR_OK; 178 } 179 }; 180 181 #define PARCEL_WRITE_INTERFACE_TOKEN(parcel, token) \ 182 do { \ 183 bool ret = parcel.WriteInterfaceToken((token)); \ 184 if (!ret) { \ 185 APP_LOGE("write interface token failed"); \ 186 return false; \ 187 } \ 188 } while (0) 189 190 #define PARCEL_WRITE(parcel, type, value) \ 191 do { \ 192 bool ret = parcel.Write##type((value)); \ 193 if (!ret) { \ 194 APP_LOGE("write parameter failed"); \ 195 return false; \ 196 } \ 197 } while (0) 198 } // namespace AppExecFwk 199 } // namespace OHOS 200 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H