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 virtual bool Uninstall(const UninstallParam &uninstallParam, 92 const sptr<IStatusReceiver> &statusReceiver) override; 93 /** 94 * @brief Installs an app by bundleName, only used in preInstall app. 95 * @param bundleName Indicates the bundleName of the application to install. 96 * @param installParam Indicates the install parameters. 97 * @param statusReceiver Indicates the callback object that using for notifing the install result. 98 * @return Returns true if this function is successfully called; returns false otherwise. 99 */ 100 virtual bool InstallByBundleName(const std::string &bundleName, const InstallParam &installParam, 101 const sptr<IStatusReceiver> &statusReceiver) override; 102 /** 103 * @brief Install sandbox application. 104 * @param bundleName Indicates the bundle name of the sandbox application to be install. 105 * @param dlpType Indicates type of the sandbox application. 106 * @param userId Indicates the sandbox application will be installed under which user id. 107 * @param appIndex Indicates the appIndex of the sandbox application installed under which user id. 108 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 109 */ 110 virtual ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dplType, int32_t userId, 111 int32_t &appIndex) override; 112 /** 113 * @brief Uninstall sandbox application. 114 * @param bundleName Indicates the bundle name of the sandbox application to be install. 115 * @param appIndex Indicates application index of the sandbox application. 116 * @param userId Indicates the sandbox application will be uninstall under which user id. 117 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 118 */ 119 virtual ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId) override; 120 121 virtual sptr<IBundleStreamInstaller> CreateStreamInstaller(const InstallParam &installParam, 122 const sptr<IStatusReceiver> &statusReceiver) override; 123 virtual bool DestoryBundleStreamInstaller(uint32_t streamInstallerId) override; 124 virtual ErrCode StreamInstall(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 125 const sptr<IStatusReceiver> &statusReceiver) override; 126 bool UpdateBundleForSelf(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 127 const sptr<IStatusReceiver> &statusReceiver) override; 128 129 private: 130 /** 131 * @brief Handles the Install function called from a IBundleInstaller proxy object. 132 * @param data Indicates the data to be read. 133 * @param reply Indicates the reply to be sent; 134 * @return 135 */ 136 void HandleInstallMessage(Parcel &data); 137 /** 138 * @brief Handles the Install by bundleName function called from a IBundleInstaller proxy object. 139 * @param data Indicates the data to be read. 140 * @return 141 */ 142 void HandleRecoverMessage(Parcel &data); 143 /** 144 * @brief Handles the Install multiple haps function called from a IBundleInstaller proxy object. 145 * @param data Indicates the data to be read. 146 * @param reply Indicates the reply to be sent; 147 * @return 148 */ 149 void HandleInstallMultipleHapsMessage(Parcel &data); 150 /** 151 * @brief Handles the Uninstall bundle function called from a IBundleInstaller proxy object. 152 * @param data Indicates the data to be read. 153 * @param reply Indicates the reply to be sent; 154 * @return 155 */ 156 void HandleUninstallMessage(Parcel &data); 157 /** 158 * @brief Handles the Uninstall module function called from a IBundleInstaller proxy object. 159 * @param data Indicates the data to be read. 160 * @param reply Indicates the reply to be sent; 161 * @return 162 */ 163 void HandleUninstallModuleMessage(Parcel &data); 164 /** 165 * @brief Handles the uninstall by input uninstall param. 166 * @param data Indicates the data to be read. 167 * @return Returns true if the application is uninstall successfully; returns false otherwise. 168 */ 169 void HandleUninstallByUninstallParam(Parcel &data); 170 /** 171 * @brief Handles the InstallSandboxApp function called from a IBundleInstaller proxy object. 172 * @param data Indicates the data to be read. 173 * @param reply Indicates the reply to be sent. 174 * @return Returns true if the sandbox application is installed successfully; returns false otherwise. 175 */ 176 void HandleInstallSandboxApp(Parcel &data, Parcel &reply); 177 /** 178 * @brief Handles the UninstallSandboxApp function called from a IBundleInstaller proxy object. 179 * @param data Indicates the data to be read. 180 * @param reply Indicates the reply to be sent. 181 * @return Returns true if the sandbox application is installed successfully; returns false otherwise. 182 */ 183 void HandleUninstallSandboxApp(Parcel &data, Parcel &reply); 184 /** 185 * @brief Check whether the statusReceiver object is valid. 186 * @param statusReceiver Indicates the IStatusReceiver object. 187 * @return Returns true if the object is valid; returns false otherwise. 188 */ 189 bool CheckBundleInstallerManager(const sptr<IStatusReceiver> &statusReceiver) const; 190 191 void HandleCreateStreamInstaller(Parcel &data, Parcel &reply); 192 void HandleDestoryBundleStreamInstaller(Parcel &data, Parcel &reply); 193 private: 194 InstallParam CheckInstallParam(const InstallParam &installParam); 195 bool IsPermissionVaild(const InstallParam &installParam, InstallParam &installParam2); 196 std::shared_ptr<BundleInstallerManager> manager_; 197 std::vector<sptr<IBundleStreamInstaller>> streamInstallers_; 198 std::atomic<uint32_t> streamInstallerIds_ = 0; 199 std::mutex streamInstallMutex_; 200 201 DISALLOW_COPY_AND_MOVE(BundleInstallerHost); 202 }; 203 } // namespace AppExecFwk 204 } // namespace OHOS 205 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_HOST_H