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