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_PROXY_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_PROXY_H 18 19 #include "iremote_proxy.h" 20 21 #include "bundle_framework_core_ipc_interface_code.h" 22 #include "bundle_installer_interface.h" 23 #include "status_receiver_interface.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 class BundleInstallerProxy : public IRemoteProxy<IBundleInstaller> { 28 public: 29 explicit BundleInstallerProxy(const sptr<IRemoteObject> &object); 30 virtual ~BundleInstallerProxy() override; 31 /** 32 * @brief Installs an application through the proxy 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) override; 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) override; 51 /** 52 * @brief Installs multiple haps, the final result will be notified from the statusReceiver object. 53 * @attention Notice that the bundleFilePath should be an string vector of absolute paths. 54 * @param bundleFilePaths Indicates the paths for storing the ohos Ability Packages (HAP) of the application 55 * to install or update. 56 * @param installParam Indicates the install parameters. 57 * @param statusReceiver Indicates the callback object that using for notifing the install result. 58 * @return Returns true if this function is successfully called; returns false otherwise. 59 */ 60 virtual bool Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 61 const sptr<IStatusReceiver> &statusReceiver) override; 62 /** 63 * @brief Uninstalls an application through the proxy object. 64 * @param bundleName Indicates the bundle name of the application to uninstall. 65 * @param installParam Indicates the uninstall parameters. 66 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 67 * @return Returns true if this function is successfully called; returns false otherwise. 68 */ 69 virtual bool Uninstall(const std::string &bundleName, const InstallParam &installParam, 70 const sptr<IStatusReceiver> &statusReceiver) override; 71 /** 72 * @brief Uninstalls a module in an application through the proxy object. 73 * @param bundleName Indicates the bundle name of the module to uninstall. 74 * @param modulePackage Indicates the module package of the module to uninstall. 75 * @param installParam Indicates the uninstall parameters. 76 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 77 * @return Returns true if this function is successfully called; returns false otherwise. 78 */ 79 virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage, 80 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) override; 81 /** 82 * @brief Uninstalls a module in an application through the proxy object. 83 * @param uninstallParam Indicates the input param to uninstall. 84 * @param statusReceiver Indicates the callback object that using for notifing the uninstall result. 85 * @return Returns true if this function is successfully called; returns false otherwise. 86 */ 87 virtual bool Uninstall(const UninstallParam &uninstallParam, const sptr<IStatusReceiver> &statusReceiver) override; 88 /** 89 * @brief Install sandbox application. 90 * @param bundleName Indicates the bundle name of the sandbox application to be install. 91 * @param dlpType Indicates type of the sandbox application. 92 * @param userId Indicates the sandbox application will be installed under which user id. 93 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 94 */ 95 virtual ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId, 96 int32_t &appIndex) override; 97 /** 98 * @brief Uninstall sandbox application. 99 * @param bundleName Indicates the bundle name of the sandbox application to be install. 100 * @param appIndex Indicates application index of the sandbox application. 101 * @param userId Indicates the sandbox application will be uninstall under which user id. 102 * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise. 103 */ 104 virtual ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId) override; 105 106 virtual sptr<IBundleStreamInstaller> CreateStreamInstaller(const InstallParam &installParam, 107 const sptr<IStatusReceiver> &statusReceiver, const std::vector<std::string> &originHapPaths) override; 108 virtual bool DestoryBundleStreamInstaller(uint32_t streamInstallerId) override; 109 110 virtual ErrCode StreamInstall(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam, 111 const sptr<IStatusReceiver> &statusReceiver) override; 112 113 virtual bool UninstallAndRecover(const std::string &bundleName, const InstallParam &installParam, 114 const sptr<IStatusReceiver> &statusReceiver) override; 115 116 virtual ErrCode InstallCloneApp(const std::string &bundleName, int32_t userId, int32_t& appIndex) override; 117 118 virtual ErrCode UninstallCloneApp(const std::string &bundleName, int32_t userId, int32_t appIndex) override; 119 120 virtual ErrCode InstallExisted(const std::string &bundleName, int32_t userId) override; 121 private: 122 bool SendInstallRequest(BundleInstallerInterfaceCode code, MessageParcel& data, MessageParcel& reply, 123 MessageOption& option); 124 125 ErrCode WriteFile(const std::string &path, int32_t outputFd); 126 127 ErrCode WriteHapFileToStream(sptr<IBundleStreamInstaller> &streamInstaller, const std::string &path); 128 129 ErrCode WriteSignatureFileToStream(sptr<IBundleStreamInstaller> &streamInstaller, const std::string &path, 130 const std::string &moduleName); 131 132 ErrCode WriteSharedFileToStream(sptr<IBundleStreamInstaller> &streamInstaller, 133 const std::string &path, uint32_t index); 134 135 ErrCode WritePgoFileToStream(sptr<IBundleStreamInstaller> &streamInstaller, const std::string &path, 136 const std::string &moduleName); 137 138 ErrCode CopySignatureFileToService(sptr<IBundleStreamInstaller> &streamInstaller, 139 const InstallParam &installParam); 140 141 ErrCode CopyPgoFileToService(sptr<IBundleStreamInstaller> &streamInstaller, 142 const InstallParam &installParam); 143 144 ErrCode GetFileNameByFilePath(const std::string &filePath, std::string &fileName); 145 146 static inline BrokerDelegator<BundleInstallerProxy> delegator_; 147 }; 148 } // namespace AppExecFwk 149 } // namespace OHOS 150 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_PROXY_H