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_APP_HELPER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H 18 19 #include <map> 20 #include <string> 21 22 #include "appexecfwk_errors.h" 23 #include "bundle_data_storage_interface.h" 24 #include "bundle_constants.h" 25 #include "inner_bundle_info.h" 26 #include "singleton.h" 27 28 #ifdef BUNDLE_FRAMEWORK_SANDBOX_APP 29 #include "bundle_sandbox_data_mgr.h" 30 #endif 31 32 namespace OHOS { 33 namespace AppExecFwk { 34 class BundleSandboxAppHelper : public DelayedSingleton<BundleSandboxAppHelper> { 35 public: 36 // BundleSandboxDataMgr interface 37 void SaveSandboxAppInfo(const InnerBundleInfo &info, const int32_t &appIndex); 38 void DeleteSandboxAppInfo(const std::string &bundleName, const int32_t &appIndex); 39 ErrCode GetSandboxAppBundleInfo( 40 const std::string &bundleName, const int32_t &appIndex, const int32_t &userId, BundleInfo &info) const; 41 int32_t GenerateSandboxAppIndex(const std::string &bundleName); 42 bool DeleteSandboxAppIndex(const std::string &bundleName, int32_t appIndex); 43 std::unordered_map<std::string, InnerBundleInfo> GetSandboxAppInfoMap() const; 44 ErrCode GetSandboxAppInfo( 45 const std::string &bundleName, const int32_t &appIndex, int32_t &userId, InnerBundleInfo &info) const; 46 ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, 47 HapModuleInfo &hapModuleInfo) const; 48 ErrCode GetInnerBundleInfoByUid(const int32_t &uid, InnerBundleInfo &innerBundleInfo) const; 49 50 // BundleSandboxInstaller interface 51 ErrCode InstallSandboxApp(const std::string &bundleName, const int32_t &dlpType, const int32_t &userId, 52 int32_t &appIndex); 53 54 ErrCode UninstallSandboxApp(const std::string &bundleName, const int32_t &appIndex, const int32_t &userId); 55 56 ErrCode UninstallAllSandboxApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID); 57 58 void RestoreSandboxUidAndGid(std::map<int32_t, std::string> &bundleIdMap); 59 60 #ifdef BUNDLE_FRAMEWORK_SANDBOX_APP GetSandboxDataMgr()61 std::shared_ptr<BundleSandboxDataMgr> GetSandboxDataMgr() const 62 { 63 return sandboxDataMgr_; 64 } 65 #endif 66 67 #ifdef BUNDLE_FRAMEWORK_SANDBOX_APP 68 private: 69 std::shared_ptr<BundleSandboxDataMgr> sandboxDataMgr_ = std::make_shared<BundleSandboxDataMgr>(); 70 #endif 71 }; 72 } // AppExecFwk 73 } // OHOS 74 75 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_APP_HELPER_H