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