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, const int32_t userId, const int32_t appIndex); 49 /** 50 * @brief The main function for clone app uninstalling. 51 * @param bundleName Indicates the bundleName of the clone applications to uninstall. 52 * @return Returns ERR_OK if the clone apps uninstall successfully; returns error code otherwise. 53 */ 54 ErrCode UninstallAllCloneApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID); 55 56 private: 57 ErrCode CreateCloneDataDir( 58 InnerBundleInfo &info, const int32_t userId, const int32_t &uid, const int32_t &appIndex) const; 59 ErrCode RemoveCloneDataDir(const std::string bundleName, int32_t userId, int32_t appIndex); 60 ErrCode GetDataMgr(); 61 void UninstallDebugAppSandbox(const std::string &bundleName, const int32_t uid, int32_t appIndex, 62 const InnerBundleInfo& innerBundleInfo); 63 64 ErrCode ProcessCloneBundleInstall(const std::string &bundleName, const int32_t userId, int32_t &appIndex); 65 ErrCode ProcessCloneBundleUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); 66 67 void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType, 68 int32_t userId, int32_t appIndex, bool isPreInstallApp, bool isFreeInstallMode, 69 InstallScene preBundleScene, ErrCode errCode); 70 void GetCallingEventInfo(EventInfo &eventInfo); 71 72 void ResetInstallProperties(); 73 74 std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; 75 int32_t uid_ = 0; 76 uint32_t accessTokenId_ = 0; 77 uint32_t versionCode_ = 0; 78 std::string appId_; 79 std::string appIdentifier_; 80 }; 81 } // AppExecFwk 82 } // OHOS 83 84 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_INSTALLER_H