• 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     /**
74      * @brief Uninstalls a module in an application, the result will be notified from the statusReceiver object.
75      * @param bundleName Indicates the bundle name of the module to uninstall.
76      * @param modulePackage Indicates the module package of the module to uninstall.
77      * @param installParam Indicates the uninstall parameters.
78      * @param statusReceiver Indicates the callback object that using for notifing the uninstall result.
79      * @return Returns true if this function is successfully called; returns false otherwise.
80      */
81     virtual bool Uninstall(const std::string &bundleName, const std::string &modulePackage,
82         const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver) = 0;
83     /**
84      * @brief Installs an app by bundleName, only used in preInstall app.
85      * @param bundleName Indicates the bundleName of the application to install.
86      * @param installParam Indicates the install parameters.
87      * @param statusReceiver Indicates the callback object that using for notifing the install result.
88      * @return Returns true if this function is successfully called; returns false otherwise.
89      */
InstallByBundleName(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)90     virtual bool InstallByBundleName(const std::string &bundleName, const InstallParam &installParam,
91         const sptr<IStatusReceiver> &statusReceiver)
92     {
93         return false;
94     }
95 
96     /**
97      * @brief Install sandbox application.
98      * @param bundleName Indicates the bundle name of the sandbox application to be install.
99      * @param dlpType Indicates type of the sandbox application.
100      * @param userId Indicates the sandbox application will be installed under which user id.
101      * @param appIndex Indicates the appIndex of the sandbox application installed under which user id.
102      * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise.
103      */
104     virtual ErrCode InstallSandboxApp(const std::string &bundleName, int32_t dlpType, int32_t userId,
105         int32_t &appIndex) = 0;
106 
107     /**
108      * @brief Uninstall sandbox application.
109      * @param bundleName Indicates the bundle name of the sandbox application to be install.
110      * @param appIndex Indicates application index of the sandbox application.
111      * @param userId Indicates the sandbox application will be uninstall under which user id.
112      * @return Returns ERR_OK if the sandbox application is installed successfully; returns errcode otherwise.
113      */
114     virtual ErrCode UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId) = 0;
115 
116     virtual sptr<IBundleStreamInstaller> CreateStreamInstaller(const InstallParam &installParam,
117         const sptr<IStatusReceiver> &statusReceiver) = 0;
118     virtual bool DestoryBundleStreamInstaller(uint32_t streamInstallerId) = 0;
119     virtual ErrCode StreamInstall(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
120         const sptr<IStatusReceiver> &statusReceiver) = 0;
121 
122     enum Message : uint32_t {
123         INSTALL = 0,
124         INSTALL_MULTIPLE_HAPS,
125         UNINSTALL,
126         UNINSTALL_MODULE,
127         RECOVER,
128         INSTALL_SANDBOX_APP,
129         UNINSTALL_SANDBOX_APP,
130         CREATE_STREAM_INSTALLER,
131         DESTORY_STREAM_INSTALLER,
132     };
133 };
134 
135 #define PARCEL_WRITE_INTERFACE_TOKEN(parcel, token)                                 \
136     do {                                                                            \
137         bool ret = parcel.WriteInterfaceToken((token));                             \
138         if (!ret) {                                                                 \
139             APP_LOGE("fail to write interface token into the parcel!");             \
140             return false;                                                           \
141         }                                                                           \
142     } while (0)
143 
144 #define PARCEL_WRITE(parcel, type, value)                                           \
145     do {                                                                            \
146         bool ret = parcel.Write##type((value));                                     \
147         if (!ret) {                                                                 \
148             APP_LOGE("fail to write parameter into the parcel!");                   \
149             return false;                                                           \
150         }                                                                           \
151     } while (0)
152 }  // namespace AppExecFwk
153 }  // namespace OHOS
154 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_INSTALLER_INTERFACE_H