• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_SANDBOX_INSTALLER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_INSTALLER_H
18 
19 #include <string>
20 
21 #include "bundle_data_mgr.h"
22 #include "inner_bundle_info.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class BundleSandboxInstaller final {
27 public:
28     BundleSandboxInstaller();
29     ~BundleSandboxInstaller();
30 
31     /**
32      * @brief The main function for sandbox app installing.
33      * @param bundleName Indicates the bundleName of the sandbox application to install.
34      * @param dlpType Indicates type of the sandbox application.
35      * @param userId Indicates the sandbox app will be installed under which user id.
36      * @param appIndex Indicates the appIndex generated by the sandbox application.
37      * @return Returns ERR_OK if the sandbox app install successfully; returns error code otherwise.
38      */
39     ErrCode InstallSandboxApp(const std::string &bundleName, const int32_t &dlpType, const int32_t &userId,
40         int32_t &appIndex);
41     /**
42      * @brief The main function for sandbox app uninstalling.
43      * @param bundleName Indicates the bundleName of the sandbox application to uninstall.
44      * @param appIndex Indicates the sandbox app index.
45      * @param userId Indicates the sandbox app will be uninstalled under which user id.
46      * @return Returns ERR_OK if the sandbox app uninstall successfully; returns error code otherwise.
47      */
48     ErrCode UninstallSandboxApp(const std::string &bundleName, const int32_t &appIndex, const int32_t &userId);
49     /**
50      * @brief The main function for sandbox app uninstalling.
51      * @param bundleName Indicates the bundleName of the sandbox applications to uninstall.
52      * @return Returns ERR_OK if the sandbox apps uninstall successfully; returns error code otherwise.
53      */
54     ErrCode UninstallAllSandboxApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID);
55 
56 private:
57     ErrCode CreateSandboxDataDir(InnerBundleInfo &info, const int32_t &uid, const int32_t &appIndex) const;
58     void SandboxAppRollBack(InnerBundleInfo &info, const int32_t &userId);
59     bool GetInnerBundleInfo(InnerBundleInfo &info, bool &isAppExist);
60     ErrCode GetDataMgr();
61     ErrCode GetSandboxDataMgr();
62 
63     std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr;
64     std::shared_ptr<BundleSandboxDataMgr> sandboxDataMgr_ = nullptr;
65     std::string bundleName_;
66     int32_t userId_ = Constants::INVALID_USERID;
67 };
68 } // AppExecFwk
69 } // OHOS
70 
71 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_INSTALLER_H