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 #include "event_report.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class BundleCloneInstaller final {
28 public:
29     BundleCloneInstaller();
30     ~BundleCloneInstaller();
31 
32     /**
33      * @brief The main function for clone app installing.
34      * @param bundleName Indicates the bundleName of the clone application to install.
35      * @param userId Indicates the clone app will be installed under which user id.
36      * @param appIndex Indicates the appIndex generated by the clone application.
37      * @return Returns ERR_OK if the clone app install successfully; returns error code otherwise.
38      */
39     ErrCode InstallCloneApp(const std::string &bundleName, const int32_t userId, int32_t &appIndex);
40     /**
41      * @brief The main function for clone app uninstalling.
42      * @param bundleName Indicates the bundleName of the clone application to uninstall.
43      * @param appIndex Indicates the clone app index.
44      * @param userId Indicates the clone app will be uninstalled under which user id.
45      * @return Returns ERR_OK if the clone app uninstall successfully; returns error code otherwise.
46      */
47     ErrCode UninstallCloneApp(const std::string &bundleName, const int32_t userId, const int32_t appIndex);
48     /**
49      * @brief The main function for clone app uninstalling.
50      * @param bundleName Indicates the bundleName of the clone applications to uninstall.
51      * @return Returns ERR_OK if the clone apps uninstall successfully; returns error code otherwise.
52      */
53     ErrCode UninstallAllCloneApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID);
54 
55 private:
56     ErrCode CreateCloneDataDir(
57         InnerBundleInfo &info, const int32_t userId, const int32_t &uid, const int32_t &appIndex) const;
58     ErrCode RemoveCloneDataDir(const std::string bundleName, int32_t userId, int32_t appIndex);
59     ErrCode GetDataMgr();
60 
61     ErrCode ProcessCloneBundleInstall(const std::string &bundleName, const int32_t userId, int32_t &appIndex);
62     ErrCode ProcessCloneBundleUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex);
63 
64     void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType,
65         int32_t userId, int32_t appIndex, bool isPreInstallApp, bool isFreeInstallMode,
66         InstallScene preBundleScene, ErrCode errCode);
67     void GetCallingEventInfo(EventInfo &eventInfo);
68 
69     void ResetInstallProperties();
70 
71     std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr;
72     int32_t uid_ = 0;
73     uint32_t accessTokenId_ = 0;
74     uint32_t versionCode_ = 0;
75 };
76 } // AppExecFwk
77 } // OHOS
78 
79 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_INSTALLER_H