• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 namespace OHOS {
29 namespace AppExecFwk {
30 class BundleSandboxDataMgr final {
31 public:
32     BundleSandboxDataMgr();
33     ~BundleSandboxDataMgr();
34 
35     void SaveSandboxAppInfo(const InnerBundleInfo &info, const int32_t &appIndex);
36     void DeleteSandboxAppInfo(const std::string &bundleName, const int32_t &appIndex);
37     ErrCode GetSandboxAppBundleInfo(
38         const std::string &bundleName, const int32_t &appIndex, const int32_t &userId, BundleInfo &info) const;
39     int32_t GenerateSandboxAppIndex(const std::string &bundleName);
40     bool DeleteSandboxAppIndex(const std::string &bundleName, int32_t appIndex);
41     std::unordered_map<std::string, InnerBundleInfo> GetSandboxAppInfoMap() const;
42     ErrCode GetSandboxAppInfo(
43         const std::string &bundleName, const int32_t &appIndex, int32_t &userId, InnerBundleInfo &info) const;
44     ErrCode GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId,
45         HapModuleInfo &hapModuleInfo) const;
46     ErrCode GetInnerBundleInfoByUid(const int32_t &uid, InnerBundleInfo &innerBundleInfo) const;
47 
48 private:
49     mutable std::shared_mutex sandboxAppMutex_;
50     mutable std::mutex sandboxAppIndexMapMutex_;
51     // key: bundleName_appindex
52     std::unordered_map<std::string, InnerBundleInfo> sandboxAppInfos_;
53     std::unordered_map<std::string, std::set<int32_t>> sandboxAppIndexMap_;
54 };
55 } // AppExecFwk
56 } // OHOS
57 
58 
59 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_SANDBOX_DATA_MGR_H