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_BUNDLE_INSTALLER_HOST_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_HOST_H 18 19 #include <atomic> 20 #include <memory> 21 #include <string> 22 23 #include "iremote_stub.h" 24 #include "nocopyable.h" 25 26 #include "bundle_installer_interface.h" 27 #include "bundle_installer_manager.h" 28 #include "bundle_stream_installer_host_impl.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class BundleInstallerHost : public IRemoteStub<IBundleInstaller> { 33 public: 34 BundleInstallerHost(); 35 virtual ~BundleInstallerHost() override; 36 37 bool Init(); 38 virtual int OnRemoteRequest( 39 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 40 /** 41 * @brief Installs an application, the final result will be notified from the statusReceiver object. 42 * @attention Notice that the bundleFilePath should be an absolute path. 43 * @param bundleFilePath Indicates the path for storing the ohos Ability Package (HAP) of the application 44 * to install or update. 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 Install(const std::string &bundleFilePath, const InstallParam &installParam, 50 const sptr<IStatusReceiver> &statusReceiver) override; 51 /** 52 * @brief Installs an application by bundleName, the final result will be notified from the statusReceiver object. 53 * @param bundleName Indicates the bundleName of the application to install. 54 * @param installParam Indicates the install parameters. 55 * @param statusReceiver Indicates the callback object that using for notifing the install result. 56 * @return Returns true if this function is successfully called; returns false otherwise. 57 */ 58 virtual bool Recover(const std::string &bundleName, const InstallParam &installParam, 59 const sptr<IStatusReceiver> &statusReceiver) override; 60 /** 61 * @brief Installs multiple haps, the final result will be notified from the statusReceiver object. 62 * @attention Notice that the bundleFilePath should be an string vector of absolute paths. 63 * @param bundleFilePaths Indicates the paths for storing the ohos Ability Packages (HAP) of the application 64 * to install or update. 65 * @param installParam Indicates the install parameters. 66 * @param statusReceiver Indicates the callback object that using for notifing the install result. 67 * @return Returns true if this function is successfully called; returns false otherwise. 68 */ 69 virtual bool Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 70 const sptr<IStatusReceiver> &statusReceiver) override; 71 /** 72 * @brief Uninstalls an application, the result will be notified from the statusReceiver object. 73 * @param bundleName Indicates the bundle name of the application to uninstall. 74 * @param installParam Indicates the uninstall parameters. 75 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 76 * @return Returns true if this function is successfully called; returns false otherwise. 77 */ 78 virtual bool Uninstall(const std::string &bundleName, const InstallParam &installParam, 79 const sptr<IStatusReceiver> &statusReceiver) override; 80 /** 81 * @brief Uninstalls a module in an application, the result will be notified from the statusReceiver object. 82 * @param bundleName Indicates the bundle name of the module to uninstall. 83 * @param modulePackage Indicates the module package of the module to uninstall. 84 * @param installParam Indicates the uninstall parameters. 85 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 86 * @return Returns true if this function is successfully called; returns false otherwise. 87 */ 88 virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage, 89 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) override; 90 /** 91 * @brief Installs an app by bundleName, only used in preInstall app. 92 * @param bundleName Indicates the bundleName of the application to install. 93 * @param installParam Indicates the install parameters. 94 * @param statusReceiver Indicates the callback object that using for notifing the install result. 95 * @return Returns true if this function is successfully called; returns false otherwise. 96 */ 97 virtual bool InstallByBundleName(const std::string &bundleName, const InstallParam &installParam, 98 const sptr<IStatusReceiver> &statusReceiver) override; 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 dplType, int32_t userId, 108 int32_t &appIndex) override; 109 /** 110 * @brief Uninstall sandbox application. 111 * @param bundleName Indicates the bundle name of the sandbox application to be install. 112 * @param appIndex Indicates application index of the sandbox application. 113 * @param userId Indicates the sandbox application will be uninstall under which user id. 114 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 115 */ 116 virtual ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId) override; 117 118 virtual sptr<IBundleStreamInstaller> CreateStreamInstaller(const InstallParam &installParam, 119 const sptr<IStatusReceiver> &statusReceiver) override; 120 virtual bool DestoryBundleStreamInstaller(uint32_t streamInstallerId) override; 121 virtual ErrCode StreamInstall(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 122 const sptr<IStatusReceiver> &statusReceiver) override; 123 124 private: 125 /** 126 * @brief Handles the Install function called from a IBundleInstaller proxy object. 127 * @param data Indicates the data to be read. 128 * @param reply Indicates the reply to be sent; 129 * @return 130 */ 131 void HandleInstallMessage(Parcel &data); 132 /** 133 * @brief Handles the Install by bundleName function called from a IBundleInstaller proxy object. 134 * @param data Indicates the data to be read. 135 * @return 136 */ 137 void HandleRecoverMessage(Parcel &data); 138 /** 139 * @brief Handles the Install multiple haps function called from a IBundleInstaller proxy object. 140 * @param data Indicates the data to be read. 141 * @param reply Indicates the reply to be sent; 142 * @return 143 */ 144 void HandleInstallMultipleHapsMessage(Parcel &data); 145 /** 146 * @brief Handles the Uninstall bundle function called from a IBundleInstaller proxy object. 147 * @param data Indicates the data to be read. 148 * @param reply Indicates the reply to be sent; 149 * @return 150 */ 151 void HandleUninstallMessage(Parcel &data); 152 /** 153 * @brief Handles the Uninstall module function called from a IBundleInstaller proxy object. 154 * @param data Indicates the data to be read. 155 * @param reply Indicates the reply to be sent; 156 * @return 157 */ 158 void HandleUninstallModuleMessage(Parcel &data); 159 /** 160 * @brief Handles the InstallSandboxApp function called from a IBundleInstaller proxy object. 161 * @param data Indicates the data to be read. 162 * @param reply Indicates the reply to be sent. 163 * @return Returns true if the sandbox application is installed successfully; returns false otherwise. 164 */ 165 void HandleInstallSandboxApp(Parcel &data, Parcel &reply); 166 /** 167 * @brief Handles the UninstallSandboxApp function called from a IBundleInstaller proxy object. 168 * @param data Indicates the data to be read. 169 * @param reply Indicates the reply to be sent. 170 * @return Returns true if the sandbox application is installed successfully; returns false otherwise. 171 */ 172 void HandleUninstallSandboxApp(Parcel &data, Parcel &reply); 173 /** 174 * @brief Check whether the statusReceiver object is valid. 175 * @param statusReceiver Indicates the IStatusReceiver object. 176 * @return Returns true if the object is valid; returns false otherwise. 177 */ 178 bool CheckBundleInstallerManager(const sptr<IStatusReceiver> &statusReceiver) const; 179 180 void HandleCreateStreamInstaller(Parcel &data, Parcel &reply); 181 void HandleDestoryBundleStreamInstaller(Parcel &data, Parcel &reply); 182 183 private: 184 InstallParam CheckInstallParam(const InstallParam &installParam); 185 std::shared_ptr<BundleInstallerManager> manager_; 186 std::vector<sptr<IBundleStreamInstaller>> streamInstallers_; 187 std::atomic<uint32_t> streamInstallerIds_ = 0; 188 std::mutex streamInstallMutex_; 189 190 DISALLOW_COPY_AND_MOVE(BundleInstallerHost); 191 }; 192 } // namespace AppExecFwk 193 } // namespace OHOS 194 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_HOST_H