• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_CLONE_INSTALLER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_CLONE_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 BundleCloneInstaller final {
27 public:
28     BundleCloneInstaller();
29     ~BundleCloneInstaller();
30 
31     /**
32      * @brief The main function for clone app installing.
33      * @param bundleName Indicates the bundleName of the clone application to install.
34      * @param userId Indicates the clone app will be installed under which user id.
35      * @param appIndex Indicates the appIndex generated by the clone application.
36      * @return Returns ERR_OK if the clone app install successfully; returns error code otherwise.
37      */
38     ErrCode InstallCloneApp(const std::string &bundleName, const int32_t userId, int32_t &appIndex);
39     /**
40      * @brief The main function for clone app uninstalling.
41      * @param bundleName Indicates the bundleName of the clone application to uninstall.
42      * @param appIndex Indicates the clone app index.
43      * @param userId Indicates the clone app will be uninstalled under which user id.
44      * @return Returns ERR_OK if the clone app uninstall successfully; returns error code otherwise.
45      */
46     ErrCode UninstallCloneApp(const std::string &bundleName, const int32_t userId, const int32_t appIndex);
47     /**
48      * @brief The main function for clone app uninstalling.
49      * @param bundleName Indicates the bundleName of the clone applications to uninstall.
50      * @return Returns ERR_OK if the clone apps uninstall successfully; returns error code otherwise.
51      */
52     ErrCode UninstallAllCloneApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID);
53 
54 private:
55     ErrCode CreateCloneDataDir(
56         InnerBundleInfo &info, const int32_t userId, const int32_t &uid, const int32_t &appIndex) const;
57     ErrCode RemoveCloneDataDir(const std::string bundleName, int32_t userId, int32_t appIndex);
58     ErrCode GetDataMgr();
59 
60     ErrCode ProcessCloneBundleInstall(const std::string &bundleName, const int32_t userId, int32_t &appIndex);
61     ErrCode ProcessCloneBundleUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex);
62     void ResetInstallProperties();
63 
64     std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr;
65     int32_t uid_ = 0;
66     uint32_t accessTokenId_ = 0;
67 };
68 } // AppExecFwk
69 } // OHOS
70 
71 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_INSTALLER_H