• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 
31 class BundleInstallerHost : public IRemoteStub<IBundleInstaller> {
32 public:
33     BundleInstallerHost();
34     virtual ~BundleInstallerHost() override;
35 
36     bool Init();
37     virtual int OnRemoteRequest(
38         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
39     /**
40      * @brief Installs an application, the final result will be notified from the statusReceiver object.
41      * @attention Notice that the bundleFilePath should be an absolute path.
42      * @param bundleFilePath Indicates the path for storing the ohos Ability Package (HAP) of the application
43      *                       to install or update.
44      * @param installParam Indicates the install parameters.
45      * @param statusReceiver Indicates the callback object that using for notifing the install result.
46      * @return Returns true if this function is successfully called; returns false otherwise.
47      */
48     virtual bool Install(const std::string &bundleFilePath, const InstallParam &installParam,
49         const sptr<IStatusReceiver> &statusReceiver) override;
50     /**
51      * @brief Uninstalls an application, the result will be notified from the statusReceiver object.
52      * @param bundleName Indicates the bundle name of the application to uninstall.
53      * @param installParam Indicates the uninstall parameters.
54      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
55      * @return Returns true if this function is successfully called; returns false otherwise.
56      */
57     virtual bool Uninstall(const std::string &bundleName, const InstallParam &installParam,
58         const sptr<IStatusReceiver> &statusReceiver) override;
59     /**
60      * @brief Uninstalls a module in an application, the result will be notified from the statusReceiver object.
61      * @param bundleName Indicates the bundle name of the module to uninstall.
62      * @param modulePackage Indicates the module package of the module to uninstall.
63      * @param installParam Indicates the uninstall parameters.
64      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
65      * @return Returns true if this function is successfully called; returns false otherwise.
66      */
67     virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage,
68         const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) override;
69 
70 private:
71     /**
72      * @brief Handles the Install function called from a IBundleInstaller proxy object.
73      * @param data Indicates the data to be read.
74      * @param reply Indicates the reply to be sent;
75      * @return
76      */
77     void HandleInstallMessage(Parcel &data);
78     /**
79      * @brief Handles the Uninstall bundle function called from a IBundleInstaller proxy object.
80      * @param data Indicates the data to be read.
81      * @param reply Indicates the reply to be sent;
82      * @return
83      */
84     void HandleUninstallMessage(Parcel &data);
85     /**
86      * @brief Handles the Uninstall module function called from a IBundleInstaller proxy object.
87      * @param data Indicates the data to be read.
88      * @param reply Indicates the reply to be sent;
89      * @return
90      */
91     void HandleUninstallModuleMessage(Parcel &data);
92     /**
93      * @brief Check whether the statusReceiver object is valid.
94      * @param statusReceiver Indicates the IStatusReceiver object.
95      * @return Returns true if the object is valid; returns false otherwise.
96      */
97     bool CheckBundleInstallerManager(const sptr<IStatusReceiver> &statusReceiver) const;
98 
99 private:
100     std::shared_ptr<BundleInstallerManager> manager_;
101 
102     DISALLOW_COPY_AND_MOVE(BundleInstallerHost);
103 };
104 
105 }  // namespace AppExecFwk
106 }  // namespace OHOS
107 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALLER_HOST_H