• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
20 #include <string>
21 
22 #include "iremote_stub.h"
23 #include "nocopyable.h"
24 
25 #include "bundle_installer_interface.h"
26 #include "bundle_installer_manager.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 class BundleInstallerHost : public IRemoteStub<IBundleInstaller> {
31 public:
32     BundleInstallerHost();
33     virtual ~BundleInstallerHost() override;
34 
35     bool Init();
36     virtual int OnRemoteRequest(
37         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
38     /**
39      * @brief Installs an application, the final result will be notified from the statusReceiver object.
40      * @attention Notice that the bundleFilePath should be an absolute path.
41      * @param bundleFilePath Indicates the path for storing the ohos Ability Package (HAP) of the application
42      *                       to install or update.
43      * @param installParam Indicates the install parameters.
44      * @param statusReceiver Indicates the callback object that using for notifing the install result.
45      * @return Returns true if this function is successfully called; returns false otherwise.
46      */
47     virtual bool Install(const std::string &bundleFilePath, const InstallParam &installParam,
48         const sptr<IStatusReceiver> &statusReceiver) override;
49     /**
50      * @brief Installs an application by bundleName, the final result will be notified from the statusReceiver object.
51      * @param bundleName Indicates the bundleName of the application to install.
52      * @param installParam Indicates the install parameters.
53      * @param statusReceiver Indicates the callback object that using for notifing the install result.
54      * @return Returns true if this function is successfully called; returns false otherwise.
55      */
56     virtual bool Recover(const std::string &bundleName, const InstallParam &installParam,
57         const sptr<IStatusReceiver> &statusReceiver) override;
58     /**
59      * @brief Installs multiple haps, the final result will be notified from the statusReceiver object.
60      * @attention Notice that the bundleFilePath should be an string vector of absolute paths.
61      * @param bundleFilePaths Indicates the paths for storing the ohos Ability Packages (HAP) of the application
62      *                       to install or update.
63      * @param installParam Indicates the install parameters.
64      * @param statusReceiver Indicates the callback object that using for notifing the install result.
65      * @return Returns true if this function is successfully called; returns false otherwise.
66      */
67     virtual bool Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
68         const sptr<IStatusReceiver> &statusReceiver) override;
69     /**
70      * @brief Uninstalls an application, the result will be notified from the statusReceiver object.
71      * @param bundleName Indicates the bundle name of the application to uninstall.
72      * @param installParam Indicates the uninstall parameters.
73      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
74      * @return Returns true if this function is successfully called; returns false otherwise.
75      */
76     virtual bool Uninstall(const std::string &bundleName, const InstallParam &installParam,
77         const sptr<IStatusReceiver> &statusReceiver) override;
78     /**
79      * @brief Uninstalls a module in an application, the result will be notified from the statusReceiver object.
80      * @param bundleName Indicates the bundle name of the module to uninstall.
81      * @param modulePackage Indicates the module package of the module to uninstall.
82      * @param installParam Indicates the uninstall parameters.
83      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
84      * @return Returns true if this function is successfully called; returns false otherwise.
85      */
86     virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage,
87         const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) override;
88 
89 private:
90     /**
91      * @brief Handles the Install function called from a IBundleInstaller proxy object.
92      * @param data Indicates the data to be read.
93      * @param reply Indicates the reply to be sent;
94      * @return
95      */
96     void HandleInstallMessage(Parcel &data);
97     /**
98      * @brief Handles the Install by bundleName function called from a IBundleInstaller proxy object.
99      * @param data Indicates the data to be read.
100      * @return
101      */
102     void HandleRecoverMessage(Parcel &data);
103     /**
104      * @brief Handles the Install multiple haps function called from a IBundleInstaller proxy object.
105      * @param data Indicates the data to be read.
106      * @param reply Indicates the reply to be sent;
107      * @return
108      */
109     void HandleInstallMultipleHapsMessage(Parcel &data);
110     /**
111      * @brief Handles the Uninstall bundle function called from a IBundleInstaller proxy object.
112      * @param data Indicates the data to be read.
113      * @param reply Indicates the reply to be sent;
114      * @return
115      */
116     void HandleUninstallMessage(Parcel &data);
117     /**
118      * @brief Handles the Uninstall module function called from a IBundleInstaller proxy object.
119      * @param data Indicates the data to be read.
120      * @param reply Indicates the reply to be sent;
121      * @return
122      */
123     void HandleUninstallModuleMessage(Parcel &data);
124     /**
125      * @brief Check whether the statusReceiver object is valid.
126      * @param statusReceiver Indicates the IStatusReceiver object.
127      * @return Returns true if the object is valid; returns false otherwise.
128      */
129     bool CheckBundleInstallerManager(const sptr<IStatusReceiver> &statusReceiver) const;
130 
131 private:
132     InstallParam CheckInstallParam(const InstallParam &installParam);
133     std::shared_ptr<BundleInstallerManager> manager_;
134 
135     DISALLOW_COPY_AND_MOVE(BundleInstallerHost);
136 };
137 }  // namespace AppExecFwk
138 }  // namespace OHOS
139 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_HOST_H