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_DATA_MGR_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_DATA_MGR_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <set> 23 #include <shared_mutex> 24 #include <string> 25 26 #include "inner_bundle_info.h" 27 #include "bundle_sandbox_manager_rdb.h" 28 29 namespace OHOS { 30 namespace AppExecFwk { 31 class BundleSandboxDataMgr final { 32 public: 33 BundleSandboxDataMgr(); 34 ~BundleSandboxDataMgr(); 35 36 void SaveSandboxAppInfo(const InnerBundleInfo &info, const int32_t &appIndex); 37 void DeleteSandboxAppInfo(const std::string &bundleName, const int32_t &appIndex); 38 ErrCode GetSandboxAppBundleInfo( 39 const std::string &bundleName, const int32_t &appIndex, const int32_t &userId, BundleInfo &info) const; 40 int32_t GenerateSandboxAppIndex(const std::string &bundleName); 41 bool DeleteSandboxAppIndex(const std::string &bundleName, int32_t appIndex); 42 std::unordered_map<std::string, InnerBundleInfo> GetSandboxAppInfoMap() const; 43 ErrCode GetSandboxAppInfo( 44 const std::string &bundleName, const int32_t &appIndex, int32_t &userId, InnerBundleInfo &info) const; 45 ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId, 46 HapModuleInfo &hapModuleInfo) const; 47 ErrCode GetInnerBundleInfoByUid(const int32_t &uid, InnerBundleInfo &innerBundleInfo) const; 48 bool SaveSandboxPersistentInfo(const std::string &bundleName, const InnerBundleInfo &innerBundleInfo); 49 bool RemoveSandboxPersistentInfo(const std::string &bundleName); 50 bool RestoreSandboxPersistentInnerBundleInfo(); 51 void RestoreSandboxUidAndGid(std::map<int32_t, std::string> &bundleIdMap); 52 53 private: 54 bool RestoreSandboxAppIndex(const std::string &bundleName, int32_t appIndex); 55 56 mutable std::shared_mutex sandboxAppMutex_; 57 mutable std::shared_mutex sandboxDbMutex_; 58 mutable std::mutex sandboxAppIndexMapMutex_; 59 // key: bundleName_appindex 60 std::unordered_map<std::string, InnerBundleInfo> sandboxAppInfos_; 61 std::unordered_map<std::string, std::set<int32_t>> sandboxAppIndexMap_; 62 std::shared_ptr<SandboxManagerRdb> sandboxManagerDb_ = nullptr; 63 }; 64 } // AppExecFwk 65 } // OHOS 66 67 68 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_DATA_MGR_H