• 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_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H
17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H
18 
19 #include <vector>
20 
21 #include "bundle_stream_installer_interface.h"
22 #include "status_receiver_interface.h"
23 #include "install_param.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class IBundleInstaller : public IRemoteBroker {
28 public:
29     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.BundleInstaller");
30     /**
31      * @brief Installs an application, the final result will be notified from the statusReceiver object.
32      * @attention Notice that the bundleFilePath should be an absolute path.
33      * @param bundleFilePath Indicates the path for storing the ohos Ability Package (HAP) of the application
34      *                       to install or update.
35      * @param installParam Indicates the install parameters.
36      * @param statusReceiver Indicates the callback object that using for notifing the install result.
37      * @return Returns true if this function is successfully called; returns false otherwise.
38      */
39     virtual bool Install(const std::string &bundleFilePath, const InstallParam &installParam,
40         const sptr<IStatusReceiver> &statusReceiver) = 0;
41     /**
42      * @brief Installs an application by bundleName, the final result will be notified from the statusReceiver object.
43      * @param bundleName Indicates the bundleName of the application to install.
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 Recover(const std::string &bundleName, const InstallParam &installParam,
49         const sptr<IStatusReceiver> &statusReceiver) = 0;
50 
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) = 0;
62 
63     /**
64      * @brief Uninstalls an application, the result will be notified from the statusReceiver object.
65      * @param bundleName Indicates the bundle name of the application to uninstall.
66      * @param installParam Indicates the uninstall parameters.
67      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
68      * @return Returns true if this function is successfully called; returns false otherwise.
69      */
70     virtual bool Uninstall(const std::string &bundleName, const InstallParam &installParam,
71         const sptr<IStatusReceiver> &statusReceiver) = 0;
72 
73     virtual bool Uninstall(const UninstallParam &uninstallParam,
74         const sptr<IStatusReceiver> &statusReceiver) = 0;
75     /**
76      * @brief Uninstalls a module in an application, the result will be notified from the statusReceiver object.
77      * @param bundleName Indicates the bundle name of the module to uninstall.
78      * @param modulePackage Indicates the module package of the module to uninstall.
79      * @param installParam Indicates the uninstall parameters.
80      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
81      * @return Returns true if this function is successfully called; returns false otherwise.
82      */
83     virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage,
84         const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) = 0;
85     /**
86      * @brief Installs an app by bundleName, only used in preInstall app.
87      * @param bundleName Indicates the bundleName of the application to install.
88      * @param installParam Indicates the install parameters.
89      * @param statusReceiver Indicates the callback object that using for notifing the install result.
90      * @return Returns true if this function is successfully called; returns false otherwise.
91      */
InstallByBundleName(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)92     virtual bool InstallByBundleName(const std::string &bundleName, const InstallParam &installParam,
93         const sptr<IStatusReceiver> &statusReceiver)
94     {
95         return false;
96     }
97 
98     /**
99      * @brief Install sandbox application.
100      * @param bundleName Indicates the bundle name of the sandbox application to be install.
101      * @param dlpType Indicates type of the sandbox application.
102      * @param userId Indicates the sandbox application will be installed under which user id.
103      * @param appIndex Indicates the appIndex of the sandbox application installed under which user id.
104      * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise.
105      */
106     virtual ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId,
107         int32_t &appIndex) = 0;
108 
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) = 0;
117 
118     virtual sptr<IBundleStreamInstaller> CreateStreamInstaller(const InstallParam &installParam,
119         const sptr<IStatusReceiver> &statusReceiver) = 0;
120     virtual bool DestoryBundleStreamInstaller(uint32_t streamInstallerId) = 0;
121     virtual ErrCode StreamInstall(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
122         const sptr<IStatusReceiver> &statusReceiver) = 0;
123 
UpdateBundleForSelf(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)124     virtual bool UpdateBundleForSelf(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
125         const sptr<IStatusReceiver> &statusReceiver)
126     {
127         return true;
128     }
129 };
130 
131 #define PARCEL_WRITE_INTERFACE_TOKEN(parcel, token)                                 \
132     do {                                                                            \
133         bool ret = parcel.WriteInterfaceToken((token));                             \
134         if (!ret) {                                                                 \
135             APP_LOGE("fail to write interface token into the parcel!");             \
136             return false;                                                           \
137         }                                                                           \
138     } while (0)
139 
140 #define PARCEL_WRITE(parcel, type, value)                                           \
141     do {                                                                            \
142         bool ret = parcel.Write##type((value));                                     \
143         if (!ret) {                                                                 \
144             APP_LOGE("fail to write parameter into the parcel!");                   \
145             return false;                                                           \
146         }                                                                           \
147     } while (0)
148 }  // namespace AppExecFwk
149 }  // namespace OHOS
150 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H